Your files won't join properly because something doesn't match up.
Like many others I had problems with sound syncing up properly in merged videos. and while MP4Box works fine if the clips have identical specifications, in some cases I would get whacked by the “No suitable destination track found - creating new one" in which case Totem (a.k.a Videos) Wouldn't play that segment in the joined file. After some trial and error and further research I've developed the following method for dealing with joining videos which thus far has worked every time with acceptable (to me) quality.
If frame sizes don't match (joining errors pertaining to video tracks):
Normalize video without disrupting audio (-c:a copy) by setting constraints (divisible by 8 for maximum codec compatibility) for unmatched segments
Example commands
width=856
height=480
avconv -i input.mp4 -filter:v "scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2" -c:a copy output.mp4
If Audio Doesn't match (joining errors pertaining to audio tracks):
Normalize Audio
Process audio without disrupting video (c:v copy) so that all clips match the desired codec, frequency and bitrate with c:a codec -ar frequency like -ar 48000 and and bit-rate with b:a 128k for stereo (64K per channel seems a good target) or whatever matches.
Example: avconv -i input.mp4 -c:v copy -c:a libmp3lame -ar 48000 b:a 128k output.mp4
(note that libmp3lame is a codec for mp3 audio) You can get a list of avconv supported encoders by issuing the command avconv -codecs
or to narrow things down to a specific coded avconv -codecs|grep *codecname*
for example avconv -codecs|grep mp3
Now that we've normalized the files, we can join them. In this example I'll join the files with MP4Box. If you don't have it you can get it by issuing the command sudo apt-get install gpac
Join the files with the command MP4Box file1.mp4 -cat file2.mp4 -cat file3.mp4 -cat file4.mp4 -out joinedfile.mp4
(note that there is no cat before the first file and each additional file is preceded by -cat and the target file is preceded by -out)
If using MP4Box (recommended for MP4) for joining you may find that you have to process all clips with avconv whether specs appear to match or not to avoid the error “No suitable destination track found - creating new one (type vide)
”
Note: I've found Avidemux to have problems with videos encoded using H.264/AVC (per totem) files due to the B-frames as a reference. This seems to result in audio out of sync when joining even when choosing to copy both audio and video without remux. Crashes when not choosing safe mode and out of sync when using safe mode
Sources:
https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player
https://stackoverflow.com/questions/20703160/problems-with-setting-constant-bitrate-by-using-avconv
https://trac.ffmpeg.org/wiki/Encode/AAC#fdk_cbr
Note: As far as I know other formats (containers) have similar constraints for matching frame size and audio rates, so this may work for avi as well if you attempt the joining via cat or mencoder after normalizing video and audio.
Optional: Use Handbrake to re-encode the joined file for smaller size if desired with a variable framerate and a constant quality setting of 25 (suggested settings – adjust as needed for your material and quality expectations)
mencoder
with -ovc option and -oac option. See: http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-selecting-codec.html – vine_user Jul 08 '12 at 17:53