[LAU] FFMPEG audio/video editing question

Joel Roth joelz at pobox.com
Thu Jan 25 22:21:39 UTC 2018


Jeanette C. wrote:
> Hey hey,
> I'm just trying to concatenate two mpeg4 videos that I have created with
> ffmpeg. One has a series of images (a true video), the other just has a
> still. Here's how they were created:
> ffmpeg -loop 1 -y -i image.jpg -i sound.wav -acodec aac -vcodec mpeg4 -s
> 1280x720 -shortest result.mp4
> (the options from -vcodec to -s were later exchanged for the ones in the
> commandline below, almost same result)
> ffmpeg -r 24 -start_number 1 -i image%03d.jpg -c:v libx264 -r 24 -pix_fmt
> yuv420p -i sound.wav -acodec aac out.mp4
> (swapped the first commandline for everything from -c:v to -pix_fmt)
> 
> For concatenation I tried:
> ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
> (where mylist.txt contained lines:
> file file1.mp4
> ...
> I also tried converting the mpeg4s to intermediate .ts files:
> ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts
> intermediate1.ts
> ...
> And then used:
> ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a
> aac_adtstoasc output.mp4
> 
> With the original options for the first and second video, the direct
> concatenation failed, because they apparently had different video/image
> formats.
> 
> After rerendering the still, they'd concatenate, but only play the first
> (moving) video correctly and then just skip through the rest. The same for
> the second concatenation method with intermediate .ts files.
> 
> Can anyone point out where I went wrong. Or even better give me a few
> correct commandlines. :)

The best would be to match precisely the attributes of
two videos, so they can be combined without re-encoding.
You can use ffprobe to get the attributes of a video.

Even if the codecs are different, a number of attributes
must match. Quote:

All segments must have the same number of streams of each
type, and that will also be the number of streams at output. 

Also, inputs have to be of the same frame dimensions (e.g.,
1920x1080 pixels) and should have the same framerate.
Therefore, you may at least have to add a 'scale' or
'scale2ref' filter before concatenating videos. A
handful of other attributes have to match as well, like the
stream aspect ratio. Refer to the documentation of the
filter for more info. 

https://trac.ffmpeg.org/wiki/Concatenate#differentcodec

hope that helps

-- 
Joel Roth
  



More information about the Linux-audio-user mailing list