1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Converting camcorder .mts files to .mp4 with FFmpeg

Discussion in 'Editing Software' started by cyanide, Aug 7, 2012.

  1. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    Recently I purchased a Panasonic HD-V100 (see my RCSparks review here). I found it saves to a file type called .mts (http://www.fileinfo.com/extension/mts) which is used with AVCHD developed by Sony & Panasonic.

    This file type is not really usable with a great many players or editors (although Win7 now has native support of it), so we are faced with converting the .mts to another more common/user friendly file type. In my case I wanted to convert to H264 .mp4 files.

    The .mts footage will load in my video editor as .mts (on WinXP using VideoPad), but it is pretty much unusable, AV sync issues, image noise & pixelation etc.
    Because I want to edit on my PC and splice with .mp4 footage from my GoPro I set about finding a way to convert the .mts file from the camcorder.

    I downloaded and tried about 5, maybe 6 different video converter softwares claiming to convert .mts to .mp4. Of those, only one actualy did a decent job of it, however, it was watermarked and payment is required. The software that came on CD with the camcorder was so terrible to use I uninstalled it.

    I then remembered the developers at work are using a free conversion tool called FFmpeg (it is many other things, but for this, I only needed it for converting video). So I decided to give it a go.

    I downloaded and installed it, read a few examples I found on Google and I had sucessfully converted .mts to .mp4 within about 30mins, and without reading the user manual. I was stoked!

    A few notes about FFmpeg:
    FFmpeg is a command line application. There is a great amount FFmpeg can do, it's codec and file container support is very impressive, however, for those not comfortable with commandline interface it may be a little daunting, the good news is that there are many, many examples on the web of different conversions, so as long as you can copy someone elses examples you can use it.

    For example you may want to convert .3gp (mobile phone) to another format, it can do it. Little side note: Facebook uses ffmpeg for video encoding, and some believe YouTube are also using it as part of their video encoding backend, as do many other softwares including VideoPad Editor, Pazera MOV to AVI etc (it is legal to do so). Although not necessarily user friendly to the average Joe, it is indeed powerfull.

    Anyway, back to the nuts and bolts.

    I'm going to explain what I did in really basic terms, not because I am assuming people are thick or nothing, but because it is easy for it not to work if you ain't familar with the commandline interface and also, because I think in small steps when trying out things like this.

    Because I am converting 1080i to 720p I will mention stuff about deinterlacing, scale and frames per second. For some people this may be a non issue and they may just want to go from .mts to .mp4 without any other changes to the video (you will have to convert the AC3 audio to ACC or MP3 because apparently .mp4 don't like AC3 audio).

    Let's begin:

    1. Download FFmpeg (http://ffmpeg.org/).
      This is the downloads for the Windows versions: http://ffmpeg.zeranoe.com/builds/

    2. Extract FFmpeg using 7zip or simular compatible extractor software like WinRAR.
      http://www.7-zip.org/

    3. FFmpeg don't need to be in the Programmes folder, it will run from any location (heck, I just left it in the Downloads folder while testing it). Put the exe file(s) into a folder of your choosing. However, I'd suggest (unless you are familar with commandline CD useage) putting it into your My Videos folder (inside the My Documents folder).

      Example (Win 7):
      C:\Users\cyanide\My Documents\My Videos
      or
      Example (Win XP):
      C:\Documents and Settings\cyanide\My Documents\My Videos

      NOTE: In all examples, replace cyanide with your computer user name.

      For simplicities sake I am going to assume the videos you wish to convert are in this same folder as FFmpeg.exe, this will save you having to type in file locations in command line, but it is up to you. I will add a sample of converting videos in another folder later in this post.

    4. To run the commandline prompt built into windows click on the Windows Start icon (lower left) then:
      WinXP: click Run, then type cmd into the Run dialogue box and click OK.
      or
      Win 7: type cmd into the search text field and hit enter key.

    5. Now we have cmd.exe open we will change directories to the folder we have the FFmpeg.exe and the video files. By default cmd.exe will start in the logged in users folder.

      [​IMG]

      To navigate to our video folder we use the CD command as follows:
      Code:
      CD My Documents\My Videos
      Then hit the enter key to CD (Change Directory, not Compact Disc in this case).

      NOTE: If you don't want to muck about with cmd.exe CD then put the ffmpeg.exe and .mts file directly into your username folder, not ideal file organisation, but it will still do the job.

      TIP: if you mis spell anything, and you get a message saying a path don't exsist etc, use the arrow up key to display the last command, then arrow left to the place of typo and correct it, better than rewriting it all out again.

    6. OK, assuming you have the FFmpeg.exe and .mts file in your My Videos folder and we have navigated to the same folder using cmd CD we will now run the ffmpeg commands to convert the .mts video file.

    I am in no way an expert on this, and do not claim to be, I will show a few commands I have tried, but first a very simple break down.

    The generic syntax is (from ffmpeg documentation):
    Code:
    ffmpeg [global options] [[infile options][‘-i’ infile]]... {[outfile options] outfile}...
    As I understand it, ffmpeg gets the input file, decodes it to uncompressed frames then re encodes it to the output file. It can do heaps more with filters like effects, overlay, merging videos etc, but that is beyond this post, read the manual or Google it if interested.

    Here are some things I tried when experimenting with FFmpeg to convert .mts to .mp4

    All of these examples I found on other websites, or are a combination of various examples I merged until I got the result I wanted.
    In these cases input video was 1920x1080i / 50fps.

    For these examples replace "filename" on the input and output file names with the names of your video files.

    .mts to .mp4
    Code:
    ffmpeg -i filename.mts -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k filename.mp4
    results: convert audio to mp3, convert video to mp4.


    reduced to 1280x720
    Code:
    ffmpeg -i filename.mts -s 1280x720 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k filename.mp4
    result: scaled down from 1080 to 720, 50fps, no deinterlacing


    reduce to 1280x720 & 30fps
    Code:
    ffmpeg -i filename.mts -s 1280x720 -r 30 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k filename.mp4
    result: scaled, 30fps, no deinterlacing


    deinterlace, reduce to 1280x720 & 60fps,include audio
    Code:
    ffmpeg -i filename.mts -vf yadif=1 -s 1280x720 -r 60 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k filename.mp4
    result: 720p, 60fps, audio


    deinterlace, reduce to 1280x720,include audio
    Code:
    ffmpeg -i filename.mts -vf yadif -s 1280x720 -vcodec mpeg4 -b:v 15M -acodec libmp3lame -b:a 192k filename.mp4
    result: 720p, original fps, audio


    Once you write out the conversion parameters hit the enter key and the cmd window will start spitting out a whole bunch of text, don't worry about it, it is just loading up it's depenacies, then it will start the conversion, or display an error (usually in red text). If everything is typed up correctly it will show it's prgress, when done the cmd window will go back to the command prompt state ready for more input from the user.

    [​IMG]

    That's it, clear as mud!

    Here is a video that started of as a 1920x1080i / 50fps .mts converted to 1080x720p 60fps .mp4 with FFmpeg
    [video=youtube_share;QZrehwjurmQ]http://youtu.be/QZrehwjurmQ?hd=1[/video]
    *Select the HD setting of the player, it don't appear to be embeding the HD version.

    Because I have a background in programming and am kinda lazy and can't be bothered to use command line everytime I want to convert videos from my camcorder before I edit it, I am going to write a small application with a GUI that will allow me to select an input folder, an output folder and some basic settings I want to access (scale, fps, etc) that will then batch covert my video files using FFmpeg.
    I will post it here for RCSparks members when it is done. If any other members have camcorder that use .mts as the file type it may be usefull.

    If anyone else here is using FFmpeg to convert different file types, please share your command line parameters in this thread.
     
    #1 cyanide, Aug 7, 2012
    Last edited: Aug 12, 2012
  2. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    Apon talking with one of our tech heads at work, he suggested I try to convert to as close to raw frame data .avi as I can to edit on PC, then save out the final video from the video editor as H264 .mp4

    We hope this will cure the A/V out of sync issue we get with HD @ high frame rate .mp4 in VideoPad also. If that don't work I will try mpeg2. Once I have done some experiments I will post up my findings here. Might take awhile, I got a lot going on with work and home life right now which I must focus on first.
     
  3. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    I've had a bit of time to try a few things out. I found that if I converted to Mpeg2 it made no difference to the A/V sync issue in VideoPad when using higher than 30fps so I went back to mpeg4 codec.


    I also found a bit of time to whip up a very basic application that will run ffmpeg so you can run it on a folder of videos and it will send ffmpeg commands untill they are all done. (written in AutoIt3)

    It was build for my own usage, I am sharing it with the RCSparks community, however, use at your own risk, it comes "as is" with NO warranties, guarantees, support or anything else of that nature. Tested on Windows XP and Windows 7.


    [​IMG]
    *** DOWNLOAD LINK ***

    NOTES:
    • You will still need to download ffmpeg, as it is the application doing the actual convertions, download links are in the first post.
    • It can only do one directory at a time, it will not do recursive directories.
    • The defaults are set up to convert .mts files to .mp4, if you want to change the input, output and commandline options you can, however, you may need to read the documentation at the ffmpeg website.
    • If you want to change the input file type, do this before opening the input browse button.
    • The software will steal focus to communicate with the commandline interface, It is best to set up a convertion job and leave the computer alone untill it is done (hence the option to shutdown after converting files). If you try to use the computer while it is running chances are it will fail to convert one or more videos. Video processing can be PCU intensive, this application was designed to be set and forget.
    • If you don't want to scale down to 720p remove " -s 1280x720 " from commandline, remove " -r 30 " if you don't want the frame rate set to 30fps, if you do not require deinterlacing remove " - vf yadif=1 " from the commandline options.
    • You can choose to delete the original video files after they are converted to save disc space, but it pays to test one file first to make sure they convert correctly before batch deleting the original files (they are sent to the recyle bin, so you can restore them until you empty the recycle bin).
     
    #3 cyanide, Sep 9, 2012
    Last edited: Sep 9, 2012
  4. motoX

    motoX New Member

    Joined:
    Dec 3, 2012
    Messages:
    64
    Likes Received:
    0
    i just rename the extension to .mp4

    thats just me though....
     
  5. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    With .mts to .mp4 on Windows PC? I tried that first before going to all the other trouble, no dice for me.
     
  6. Andthocom

    Andthocom Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Aug 13, 2012
    Messages:
    192
    Likes Received:
    4
    This is just like writing another address on your mailbox, the house is still in the same place.

    The codec recognizes the file format and plays it regardless of what extension you name it. The extension is only to tell the operating system which program it should use to display it. In this case its a mediaplayer in both cases and you wouldnt notice the difference. Try rename a .txt file to .mp4 for instance and the operating system gets confused. :)
     
  7. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    ahhh, on Win 7 .mts is natively supported by WMP, I am on WinXP at home still. This makes more sence based on what Andthocom has said.
     
  8. RCSparks

    RCSparks Administrator
    Staff Member ADMiNiSTRAToR SUPER MODERATOR

    Joined:
    Jan 19, 2011
    Messages:
    2,564
    Media:
    243
    Likes Received:
    759
    I use a program called iSkysoft Video converter when I have to convert my .mts files. It allows me to do everything I need to import them into my editor. Most of my editing is done in the new Final Cut Pro X on my Mac. FCPX will actually import my mts files right from the camera. Very nice...
     
  9. johnshevi

    johnshevi New Member

    Joined:
    Dec 19, 2012
    Messages:
    1
    Likes Received:
    0
    Handbrake (HandBrake) is what I use and it's free
    So simple and it even creates queues if you have multiple mts videos to convert.
     
  10. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    oh, I forgot about Handbrake, I did not know it converted .mts files, that's good to know.
     
  11. Halon

    Halon New Member

    Joined:
    Jan 18, 2013
    Messages:
    38
    Likes Received:
    1
  12. bobspez

    bobspez New Member

    Joined:
    Aug 1, 2013
    Messages:
    1
    Likes Received:
    0
    Converting mts at 59fps to mp4 at 59fps ...thanks so much!

    Cyanide,

    Thanks so much for posting this. I shoot 720x1280 MTS files at 59fps with a Panasonic LUMIX LX5 and have been unable to import these files to Adobe CS6 64 bit Win7 for editing, or convert them to anything higher than 30fps mp4 files with a variety of free converters. The ffmpeg download for Win 7 64 bit and the example command line you gave worked perfectly. You solved a puzzle I have been researching for days. Thanks again.




     
  13. cyanide

    cyanide Studio Forums Elite
    ELiTE MEMBER

    Joined:
    Jun 27, 2011
    Messages:
    1,005
    Media:
    2
    Likes Received:
    111
    No Problems mate, I am glad it helped you out.
     
  14. stronggerfate

    stronggerfate New Member

    Joined:
    May 24, 2015
    Messages:
    1
    Likes Received:
    0
    I highly recommend iDealshare VideoGo.

    It can convert .mts to .mp4 keeping the original video quality.

    It also can convert MTS to MOV, ProRes, AVI, WMV, 3GP, MKV, MPG, DV, etc.

    [​IMG]

    I prefer its editing function like trim, crop, rotate, watermark, subtitle, split, merge, adjust audio volume, video bitrates, aspect ratio, sample rate, etc.
     
  15. mtsfiles

    mtsfiles New Member

    Joined:
    Sep 11, 2017
    Messages:
    1
    Likes Received:
    0
    MTS Converter not only lets you convert MTS to various formats but also convert M2TS to multiple formats, e.g. AVI, MP4, WMV, MOV, MPG, FLV, and RMVB, to meet high-end demands, this MTS File Converter supports to convert MTS to 3D video format for playback with life like 3D effect.
     

Share This Page