英文:
FFMPEG - Batch convert multiple audio formats in nested folders to AIFF & keep filename and meta data
问题
我正在尝试将各个文件夹中的整个音乐库(mp3 / wav / m4a)转换为aif格式。我还需要:
1. 转换所有嵌套子目录中的文件
2. 转换为44khz 16位的aif格式
3. 复制元数据到新文件
4. 复制嵌入的艺术品
5. 将所有新文件放入同一输出目录
我花了一些时间在这里找答案,但到目前为止只能转换为aif:
find ./ -type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) -exec ffmpeg -i '{}' '{}.aif' \;
有人能帮忙更新脚本以做我需要的所有事情吗?
非常感谢任何帮助 :)
(我已经看了多篇解释如何做到这些事情的帖子,但我无法将其应用于批处理!)
英文:
I'm trying to convert all of my music library in various folders (mp3 / wav / m4a) to aif. I also need to:
- Convert files in all nested subdirectories
- Convert to 44khz 16 bit aif
- Copy meta data to new file
- Copy embedded artwork
- Put all new files in the same output directory
I have spent some time going through answers on here but can only convert to aif so far;
find ./ -type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) -exec ffmpeg -i '{}' '{}.aif' \;
Can someone help me update the script to do all of the things I need?
Any help mucho appreciated
(I've been through multiple posts explaining how to do each of these things but I can't get this to work on batch processing!)
答案1
得分: 3
我无法让[标签:ffmpeg]为[aif]文件添加封面艺术。另外,只有标题和注释字段被映射/保留(在我的版本上)。其他所有字段都丢失或未映射。
问题出现在**[标签:aif]**格式上,作为目标输出。
功能/错误已经报告。
确认添加封面艺术没有问题,mp3 -> mp3,并保留所有标签(除了注释!!!)。
我的命令:
ffmpeg \
-i "${fullpathfile}" \
-i "${startDIR}/${fileroot}.png" \
-map 0:a \
-map 1:0 \
-c:0 copy \
-c:1 copy \
-id3v2_version 4 \
"${libraryDIR}/${fileroot}.${sufOut}";
我的环境:
Ubuntu MATE 20.04
Linux 5.4.0-135-generic
#152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022
ffmpeg version 4.2.7-0ubuntu0.1
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
我的测试脚本:
#!/bin/bash
doTransform()
{
cd "${libraryDIR}" ;
skip_start=0
time_end=unknown
while read line
do
sufIn=`echo "${line}" | awk '{ n=split( $0, val, "." ) ; print val[n] ; }' `
fileroot=`basename "${line}" ".${sufIn}" `
rm -f "${libraryDIR}/${fileroot}.${sufOut}";
ffprobe -hide_banner "${line}";
echo -e "\n sufIn = ${sufIn} ..."
echo "按回车继续..." >&2
read k <&2
case "${sufOut}" in
"${sufIn}" )
codec="-c:0 copy -c:1 copy" ;;
* )
case "${SufIn}" in
mp3 )
codec="-c:0 copy -c:1 copy" ;;
* )
# AIC/AIF格式和编解码器规范存在问题
codec="-c:0 copy -c:1 copy" ;;
esac
esac
ffmpeg \
-i "${line}" \
-i "${startDIR}/${fileroot}.png" \
-map 0:a \
-map 1:0 \
${codec} \
-ss ${skip_start} \
-id3v2_version 4 \
"${libraryDIR}/${fileroot}.${sufOut}";
### MP3 -> MP3:元数据被保留(除了注释)
### MP3 -> MP3:仅保留标题和注释,其他都丢失
### 升级到 22.04 后再尝试这些
# -metadata title="Album cover" \
# -metadata comment="Cover (front)" \
# -metadata:s:a:0 title="Album cover" \
# -metadata:s:a:0 comment="Cover (front)" \
done
}
startDIR=`pwd`
sourceDIR=${startDIR}/FFMPEG_Test
libraryDIR=${startDIR}/Output
sufOut=mp3
sufOut=aif
find "${sourceDIR}" \
-type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) \
-print |
grep -v '/Output' |
doTransform
英文:
I am unable to get [tag:ffmpeg] to add artwork to [tag:aif] file. Also, only Title and Comment fields are mapped/preserved (on my version). All others lost or not mapped.
Issue is with the [tag:aif] format as target output.
Feature/Bug reported.
Confirmed no problem adding artwork, mp3 -> mp3, and preserving all tags (except comment !!!).
My command:
ffmpeg \
-i "${fullpathfile}" \
-i "${startDIR}/${fileroot}.png" \
-map 0:a \
-map 1:0 \
-c:0 copy \
-c:1 copy \
-id3v2_version 4 \
"${libraryDIR}/${fileroot}.${sufOut}"
My environment:
Ubuntu MATE 20.04
Linux 5.4.0-135-generic
#152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022
ffmpeg version 4.2.7-0ubuntu0.1
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
My test script:
#!/bin/bash
doTransform()
{
cd "${libraryDIR}" ;
skip_start=0
time_end=unknown
while read line
do
#sufIn=mp3
sufIn=`echo "${line}" | awk '{ n=split( $0, val, "." ) ; print val[n] ; }' `
fileroot=`basename "${line}" ".${sufIn}" `
rm -f "${libraryDIR}/${fileroot}.${sufOut}"
ffprobe -hide_banner "${line}"
echo -e "\n sufIn = ${sufIn} ..."
echo " Hit return to continue ..." >&2
read k <&2
case "${sufOut}" in
"${sufIn}" )
#codec="-codec copy" ;;
codec="-c:0 copy -c:1 copy" ;;
* )
case "${SufIn}" in
mp3 )
#codec="-codec copy" ;;
codec="-c:0 copy -c:1 copy" ;;
* )
# Issues with AIC/AIF format and codec specificaiton
codec="-c:0 copy -c:1 copy" ;;
esac
::
esac
#-to ${time_end} \
#-b:a 192k \
#-i "${fullpathfile}" \
ffmpeg \
-i "${line}" \
-i "${startDIR}/${fileroot}.png" \
-map 0:a \
-map 1:0 \
${codec} \
-ss ${skip_start} \
-id3v2_version 4 \
"${libraryDIR}/${fileroot}.${sufOut}"
### MP3 -> MP3 : metadata is preseved (except comment) for
### MP3 -> MP3 : only Title and Comment preserved, all others lost
### Try these again after upgrade to 22.04
# -metadata title="Album cover" \
# -metadata comment="Cover (front)" \
# -metadata:s:a:0 title="Album cover" \
# -metadata:s:a:0 comment="Cover (front)" \
done
}
startDIR=`pwd`
sourceDIR=${startDIR}/FFMPEG_Test
libraryDIR=${startDIR}/Output
sufOut=mp3
sufOut=aif
#-ipath "${libraryDIR}" \
#\( -ipath "${libraryDIR}" \) \
find "${sourceDIR}" \
-type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) \
-print |
grep -v '/Output' |
doTransform
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论