FFMPEG – 批量转换嵌套文件夹中的多种音频格式为AIFF,并保留文件名和元数据

huangapple go评论52阅读模式
英文:

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:

  1. Convert files in all nested subdirectories
  2. Convert to 44khz 16 bit aif
  3. Copy meta data to new file
  4. Copy embedded artwork
  5. 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 FFMPEG – 批量转换嵌套文件夹中的多种音频格式为AIFF,并保留文件名和元数据

(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 &quot;${fullpathfile}&quot; \
-i &quot;${startDIR}/${fileroot}.png&quot; \
-map 0:a \
-map 1:0 \
-c:0 copy \
-c:1 copy \
-id3v2_version 4 \
&quot;${libraryDIR}/${fileroot}.${sufOut}&quot;

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 &quot;${libraryDIR}&quot; ;
skip_start=0
time_end=unknown
while read line
do
#sufIn=mp3
sufIn=`echo &quot;${line}&quot; | awk &#39;{ n=split( $0, val, &quot;.&quot; ) ; print val[n] ; }&#39; `
fileroot=`basename &quot;${line}&quot; &quot;.${sufIn}&quot; `
rm -f &quot;${libraryDIR}/${fileroot}.${sufOut}&quot;
ffprobe -hide_banner &quot;${line}&quot;
echo -e &quot;\n sufIn = ${sufIn} ...&quot;
echo &quot; Hit return to continue ...&quot; &gt;&amp;2
read k &lt;&amp;2 
case &quot;${sufOut}&quot; in
&quot;${sufIn}&quot; )
#codec=&quot;-codec copy&quot; ;;
codec=&quot;-c:0 copy -c:1 copy&quot; ;;
* )
case &quot;${SufIn}&quot; in
mp3 )	
#codec=&quot;-codec copy&quot; ;;
codec=&quot;-c:0 copy -c:1 copy&quot; ;;
* ) 	
# Issues with AIC/AIF format and codec specificaiton
codec=&quot;-c:0 copy -c:1 copy&quot; ;;
esac
::
esac
#-to ${time_end} \
#-b:a 192k \
#-i &quot;${fullpathfile}&quot; \
ffmpeg \
-i &quot;${line}&quot; \
-i &quot;${startDIR}/${fileroot}.png&quot; \
-map 0:a \
-map 1:0 \
${codec} \
-ss ${skip_start} \
-id3v2_version 4 \
&quot;${libraryDIR}/${fileroot}.${sufOut}&quot;
###	MP3 -&gt; MP3 :	metadata is preseved (except comment) for  
###	MP3 -&gt; MP3 :	only Title and Comment preserved, all others lost
###  Try these again after upgrade to 22.04
#			-metadata title=&quot;Album cover&quot; \
#			-metadata comment=&quot;Cover (front)&quot; \
#			-metadata:s:a:0 title=&quot;Album cover&quot; \
#			-metadata:s:a:0 comment=&quot;Cover (front)&quot; \
done
}
startDIR=`pwd`
sourceDIR=${startDIR}/FFMPEG_Test
libraryDIR=${startDIR}/Output
sufOut=mp3
sufOut=aif
#-ipath &quot;${libraryDIR}&quot; \
#\( -ipath &quot;${libraryDIR}&quot; \) \
find &quot;${sourceDIR}&quot; \
-type f \( -name &quot;*.wav&quot; -o -name &quot;*.aac&quot; -o -name &quot;*.m4a&quot; -o -name &quot;*.mp3&quot; \) \
-print		|
grep -v &#39;/Output&#39; |
doTransform

huangapple
  • 本文由 发表于 2023年2月18日 22:29:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定