Concatenating videos with ffmpeg produces silent video when the first video has no audio track
I have 3 mp4 files:
- 1.mp4 - Has video, no audio
- 2.mp4 - Has video and audio
- 3.mp4 - Has video and audio
I have created a clips file (clips.txt) for concatenation:
file '1.mp4'
file '2.mp4'
file '3.mp4'
I run the following command line:
ffmpeg -f concat -i "clips.txt" -c:a aac -b:a 160k -y "out.mp4"
The file that is produced has video but no audio, presumably because 1.mp4 has no audio track.
If I rearrange clips.txt so 1.mp4 is not first, out.mp4 has an audio track.
Is there a way of forcing ffmpeg to use audio? I guess it would have to produce a silent audio track for any silent videos.
Thanks!
For anyone that stumbles onto this and wants to achieve the same thing as I do, I solved it as follows:
ffmpeg -i "1.mp4" -f lavfi -i aevalsrc=0 -shortest -y "new_1.mp4"
What this says is:
- Take 1.mp4 (which is the video clip without audio) (-i "1.mp4")
- Generate the minimum silence required (-f lavfi -i aevalsrc=0 -shortest)
- Output the result (-y "new_1.mp4")
From here I concatenate as I did before, but replacing "1.mp4" in clips.txt with "new_1.mp4"