简体   繁体   中英

ffmpeg: concat video and audio files

Is it possible to concatenate multiple files, if some of the files are videos with audio and some are audio only. The end result should look like this:

--------------------------------------------------------
|###(v/a)### | ### (a) ### | ### (a) ### | ###(v/a)### |
--------------------------------------------------------

v/a: video + audio
a  : audio only (blank screen)

I tried to do it with the following command:

ffmpeg 
-i chunk1.mp4 
-i chunk2.m4a 
-i chunk3.mp4
-filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] concat=n=3:v=1:a=1 [v] [a]"
-map "[v]" -map "[a]" -strict -2 result.mp4

So I tried to only use the audio track from input 1 ( [1:a:0] ) but unfortunately, I'm getting this error message:

Stream specifier ':v:0' in filtergraph description [0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] concat=n=3:v=1:a=1 [v] [a] matches no streams.

I thought that this must be possible somehow, since I can also combine a large audio file and a small video with ffmpeg. The result would then be a video file where the last frame just freezes but the audio still plays along. I would like to achieve the same result with either a frozen last frame or simply a black frames. Is this possible?

For the command given in the Q, use

ffmpeg -i chunk1.mp4 -i chunk2.m4a -i chunk3.mp4 -filter_complex \
       "color=black:s=WxH:r=N:d=T[1v]; \
       [0:v:0] [0:a:0] [1v] [1:a:0] [2:v:0] [2:a:0] concat=n=3:v=1:a=1 [v] [a]"
-map "[v]" -map "[a]" -strict -2 result.mp4

where WxH is the resolution of the videos, N the framerate, and T the duration of the audio file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM