开发者

Using FFMPEG to join two MTS files together

I have two MTS video files, each one 2 minutes long. I need to be able to join the files together and convert the format to MPEG4. I have a suitable command line for converting MTS to MP4 but don't know how to join the files together in the first place.

Some articles on the web suggest using the CAT command, like:

cat video1.mts video2.mts > whole_video.mts

However this doesn't work and according t开发者_运维问答o FFMPEG, "whole_video.mts" is only 2 minutes long, not 4 minutes.

Does anyone know how to join the files together? Is FFMPEG the best program to use to do this? Thanks in advance.


The following worked perfectly for me (i.e. resulting in seamless joins):

ffmpeg -i "concat:00019.MTS|00020.MTS|00021.MTS|00022.MTS" output.mp4


Using cat works. Its just that video players will be kind of fooled about the video length while reading the resulting whole_video.mts. There will be typically a sudden timestamp jump where the file were previously cut. But this is okay. You can encode it and then you'll get a right timestamped file.

Encoding with ffmpeg and then joining with MP4Box is a bad idea. You'll get ugly images with missing blocks at the crossing position if the second file doesn't start with a keyframe (which happens when it has been cut by a camcorder because of the 2GB file limitation). Do join and then encode, not the opposite.


It's OK, I've sorted it. Using the latest SVN versions of FFMPEG, x264 and MP4Box (GPAC), here's what I did...

Use FFMPEG to convert the MTS files to MP4 as normal:

ffmpeg -i video1.mts -vcodec libx264 -deinterlace -crf 25 -vpre hq -f mp4 -s hd480 -ab 128k -threads 0 -y 1.mp4
ffmpeg -i video2.mts -vcodec libx264 -deinterlace -crf 25 -vpre hq -f mp4 -s hd480 -ab 128k -threads 0 -y 2.mp4

Use MP4Box to join the MP4 files together:

MP4Box -cat 1.mp4 -cat 2.mp4 output.mp4

This joins the files together into "output.mp4", however when I use "ffmpeg -i output.mp4" it says the duration is longer that it should be. To fix this, I had to use FFMPEG again:

ffmpeg -i output.mp4 -vcodec copy -y final.mp4

And voila! Querying the "final.mp4" file using FFMPEG shows the correct duration and the video plays fine.

Hope this helps anyone else experiencing the same problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜