[FFmpeg-user] Optimal workflow for concatenating (reliably)

hdn8 hdlmnate at gmail.com
Thu Apr 10 13:54:41 CEST 2014

I have a web application that for a user-given video file concatenates a
short intro and outro, trims based on user-selected in and out points and
overlays a watermark.  In order to make this work I have the following flow
(not included code for generating the intro/outro videos):

1. Separate audio and video 
--  I found that during concatenation the audio tracks sometimes became
unsynchronized, also this separation allows for normalizing the levels to
match the intro and outro music levels.  

2. Overlay watermark and/or subtitles, apply trimming. 
-- Note: This is output to .mp4 (and not .mpg directly) so we can keep a
copy of this file for later use, and discard the original saving disk space.    
-- command:  ffmpeg -i input_video.mp4 -r 25 -acodec libfaac -ac 2 -ar 48000
-ab 128k -vcodec libx264 -q:v 0 -vf
-metadata:s:v:0 rotate=0 -ss 2 -t 23 -y main.mp4

3. Create mpg containers for videos to be concatenated
-- I did not have any reliable success with other formats for concatenation
except with mpg containers, important that the settings and sizes are the
same for all three videos.  
-- command:  
ffmpeg -i main.mp4 -r 25 -an -s 854x480 -q:v 0 -y main_prepconcat.mpg

4. Concatenate videos
-- command:  ffmpeg -i concat:intro.mpg|main_prepconcat.mpg|outro.mpg -q:v 0
-y concat_tmp.mpg

5. Concatenate audios (and normalize)
-- This I do in python, not ffmpeg, normalize and concatenate the audio to
give a file: audio_concat.wav

6. Final encode,  encode output video with given concatenated video and
audio tracks  
-- command: ffmpeg -i concat_tmp.mpg -i audio_concat.wav -vcodec libx264
-q:v 0 -g 50 -y join_process.mp4

7. Faststart (put moov atom at front for faster web instantiation)
qtfaststart join_process.mp4

Im now revisiting this code and looking to see if there are any options for
improvement, better efficiency.  I found the concatenation process difficult
originally, trying many different formats and options before settling on
this workflow, in the next iteration we will add some more editing
functionality which will put more demand on the concatenation and trimming
processes, so if anyone can share their best practices thanks in advance!

View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Optimal-workflow-for-concatenating-reliably-tp4664731.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.

More information about the ffmpeg-user mailing list