I have a Sony HandyCam that produces MTS digital videos. I am also a Linux user, Ubuntu flavor, and ran through hours and hours of trying a variety of programs to get these videos converted to a format acceptable to YouTube.
Some popular programs would not work at all after install, even after several attempts to get them to function, and other programs would fail to do what I needed. I ended up reinstalling the program “ffmpeg” from source and enabling just about every feature during the compile. Then I used two simple command-line methods to successfully process an MTS video into a YouTube-ready MP4 video. But there is also the problem that the camera itself splits files internally at 2GB. Since this can happen in the middle of a song, I had to be able to join the files together prior to extracting a clip.
To join files, I have to use an older free program called TsMuxer: http://www.videohelp.com/tools/tsMuxeR (In this program, click Add to put the first file in the list, then click Join to add more files to append.) I tried using “cat” to join them, but frequently had errors appear.
When trying to cut out a clip from two files (as shown in picture below), I find it is best to first join the large files, then cut out the clip, rather than clipping each and then trying to join them.
The first command to convert the file tells ffmpeg to take a specific clip of the video (which you figure out by watching the video), and excise it from the original. You need to note the beginning time, then the end time, and figure out how long the clip is that you want.
NOTE: If you want to convert the whole video, you can skip step 1.
1. ffmpeg -ss 00:01:33 -i 00001.MTS -vcodec copy -acodec -t 00:13:04 copy file.mts
This copies a clip of the specified portion of the file “00001.MTS” without re-encoding [starting at 1 minute 33 seconds and lasting for a duration of 13 minutes 4 seconds] NOTE: Duration (the “-t” option) is how long the clip lasts, not the time when it ends. This step is fast and results in a shorter MTS clip called “file.mts”. (NOTE: There seems to be some issue with the way that ffmpeg creates clips. Often, other programs have trouble with the clips, implying that there is something not quite right about how ffmpeg is creating the new file. Even ffmpeg has trouble combining such clips into a new file, compaining about PES packet size mismatch.)
2. ffmpeg -i file.mts -itsoffset 0.150 -i file.mts -map 1:0 -map 0:1 -c:v libx264 -c:a libfaac file2.mp4
There is sometimes a slight sync problem between the video and audio when converting to MP4, but there is a way to correct for it highlighted in blue above. This command takes the clip from above, and corrects the video delay that happens when encoding to mp4, splits the audio and video streams and remuxes them with the video delayed .15 seconds (the “-itsoffset 0.150” part). You may have to tweak the delay plus or minus some to get things synced the way you like. The input file has to be specified twice (“-i file.mts”) once for the video delay, once for splitting out the video and audio and re-combining them. The last bit (“-c:v libx264 -c:a libfaac”) tells it to use the video codec “libx264” for h264, and the audio codec “libfaac” for AAC, which is what YouTube likes for HD videos. If your video doesn’t need the sync correction, leave out the part in blue.
If your installation of ffmpeg says it doesn’t know about libx264, you may need to do a reinstall using the source code to get that option enabled. Or just try following the commands on this page: http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide
The only issue I’ve found with this method is a bit of visual noise when people are moving around in the video. I’m open to suggestions on preventing that noise. It happens during the conversion to MP4, and is not part of the original video (MTS).
Also, to convert MTS files for burning to standard NTSC (American) DVD, this command works well:
ffmpeg -i 00000.MTS -target ntsc-dvd foo.mpg
(converts in about real time, automatically sets the bitrate, sets to AC3 audio and converts from h264 to mpeg2, which is what is required for making a dvd)
From FFMPEG docs: “Specify target file type (vcd, svcd, dvd, dv, dv50). Type may be prefixed with pal-, ntsc- or film- to use the corresponding standard. All the format options (bitrate, codecs, buffer sizes) are then set automatically.”
Lastly, convert the MP4 file to have quick loading on Youtube:
qt-faststart input.mp4 output.mp4
In this example, output.mp4 will be the one you post to Youtube.