我正在尝试合并两个视频文件(大小为 320x240)并创建一个水平扩展的输出视频文件(大小为 640x240)但是对于音频合并,当其中一个输入文件不包含音频时命令失败流。
这是我正在使用的命令:
C:\ffmpeg\bin\ffmpeg.exe -y -i "input1.flv"-i "input2.flv"-filter_complex "nullsrc=size=640x240[base];[0:v]scale =320x240[左上];[1:v]scale=320x240[右上];[base][upperleft]overlay=shortest=1[tmp1];[tmp1][upperright]overlay=shortest=1:x=320:y =0;[0:a][1:a]amerge=inputs=2[aout]"-map [aout] -ac 2 "output.mp4"
当 input1.flv 和 input2.flv 都包含音轨时,此命令工作正常。当任何一个缺少音轨时,该命令会给出以下错误:
[flv @ 0000000004300660] Stream discovered after head already parsed [flv @ 0000000004300660] Could not find codec parameters for stream 1 (Audio: none, 0 channels): unspecified sample format Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #1, flv, from 'input2.flv': Metadata: creationdate : Tue Jan 26 16:50:12 Duration: 00:25:59.10, start: 0.000000, bitrate: 212 kb/s Stream #1:0: Video: flv1, yuv420p, 320x240, 1k tbr, 1k tbn, 1k tbc Stream #1:1: Audio: none, 0 channels Stream #1:2: Data: none [abuffer @ 0000000004335620] Value inf for parameter 'time_base' out of range [0 - 2.14748e+009] [abuffer @ 0000000004335620] Unable to parse option value "(null)" as sample format [abuffer @ 0000000004335620] Value inf for parameter 'time_base' out of range [0 - 2.14748e+009] [abuffer @ 0000000004335620] Error setting option time_base to value 1/0. [graph 0 input from stream 1:1 @ 00000000042e4d60] Error applying options to the filter. Error configuring filters.
即使一个音频流缺少音轨或两个音频流都缺少音轨,是否有办法使此命令起作用?
最佳答案
有一个准备命令只需要执行一次,生成一个文件
ffmpeg -f lavfi -t 1 -i anullsrc:r=48000 silence.mkv
对于每个flv,
ffmpeg -i input1.flv -analyzeduration 10M -i silence.mkv -c copy -map 0 -map 1 input1a.mkv
ffmpeg -i input2.flv -analyzeduration 10M -i silence.mkv -c copy -map 0 -map 1 input2a.mkv
然后,
ffmpeg -i input1a.mkv -i input2a.mkv -filter_complex "[0:v][1:v]hstack=shortest=1[v];[0:a][1:a]amerge[a]" -map [v] -map [a] -ac 2 "output.mp4"
关于缺少一个音频流时 FFMPEG 合并失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35177801/