Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: MKV to MP4 Conversion

  1. #1
    Join Date
    Jun 2009
    Beans
    18

    MKV to MP4 Conversion

    I'm working on converting some anime from MKV to MP4. I can get the videos converted, but I would like to keep the stylized subs as presented in the original video. I don't want to run it through handbrake as I would like to find a way to automate the whole process via scripting. Can anyone provide a way perhaps using FFMPEG to do this?

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,020
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: MKV to MP4 Conversion

    Hi gachnar.

    Here are a few pointers to get you started:
    • Main idea: do not convert. Most of the time you can get away by extracting the MKV tracks, and repackaging in a MP4 container.
    • Install ffmpeg with the extra codecs as described here.
    • Install mkvtoolnix:
      Code:
      sudo apt-get-install mkvtoolnix
    • Use mkvinfo to know the tracks numbers and type.
    • Extracts the actual tracks using mkvextract.
    • You can repack the tracks using ffmpeg itself, but I would recommend installing gpac:
      Code:
      sudo apt-get install gpac
      and do the packing using MP4Box.


    Hope it helps. Let us know how it goes.
    Regards.
    Last edited by papibe; February 19th, 2013 at 05:49 AM. Reason: link to ffmpeg info fixed.

  3. #3
    Join Date
    Oct 2010
    Location
    London
    Beans
    481
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: MKV to MP4 Conversion

    Subtitle support in MP4 is limited, you either have to use bitmap-based VOBSUB (not really an option here), or 3gpp times text (supported in ffmpeg as -c:s mov_text). For soft subtitles, you would have to use (assuming the video is h.264 & the audio is AAC, which most MKVs are; if the video or audio isn't compatible with MP4, ffmpeg will throw out an error & stop):

    Code:
    ffmpeg -i input.mkv -c copy -c:s mov_text output.mp4
    ...however, that will not preserve any fancy formatting. If you want that in an MP4, I think you'll have to hardcode the subtitles iwth the 'subtitles' video filter, and before that you'll have to extract the subtitles into a separate file. Note that I haven't actually tested if this preserves any fancy text, I've only used it with plain SRT subtitles:

    Code:
    ffmpeg -i input.mkv -map 0:s:0 subtitle.ass
    ffmpeg -i input.mkv -filter:v 'subtitles=subtitle.ass' \
    -c:v libx264 -preset veryfast -crf 22 -c:a copy -sn output.mkv
    The version of ffmpeg in the repositories doesn't have access to the subtitles filter, you can see options for getting an up-to-date version from here.

    See also: x264 and AAC encoding guides.

  4. #4
    Join Date
    Sep 2006
    Beans
    3,578

    Re: MKV to MP4 Conversion

    Quote Originally Posted by papibe View Post
    [*]Install ffmpeg with the extra codecs as described here.
    I asked for that thread to be deleted, but instead it was moved to The Jail and it appears that it is still visible to some users. It is unmaintained due to the neutering of the Tutorials & Tips section, and it was designed for FFmpeg, not libav which is what Ubuntu unfortunately switched to. Therefore, it should not be used. I don't know who has permission to view it (just the forum staff and me?), but I would have preferred it to have been actually deleted.
    Last edited by FakeOutdoorsman; February 19th, 2013 at 12:23 AM.

  5. #5
    Join Date
    Jun 2009
    Beans
    18

    Re: MKV to MP4 Conversion

    I was able to get things working in a slightly different way, but I am having an issue when trying to do the actual conversion as I keep getting errors with the fonts not being there... Now they (The fonts from the source file) are added to the initial MKV as attachments, but do not actually work when I extract and move to my system font location and then restart the encoding process. Ideas?

  6. #6
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,020
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: MKV to MP4 Conversion

    What is the original subtitles format?

    It would be possible that using 'Gnome Subtitles' (GUI tool) may help you to convert the subtitles to a mp4 compatible format.

    Just a thought.
    Regards.

  7. #7
    Join Date
    Jun 2009
    Beans
    18

    Re: MKV to MP4 Conversion

    All of the files have subs in the A-S-S format. It seems like I read that some people have had luck converting to the "TTXT" format, but I'm not sure about it. I want to keep all the fancy formatting if possible.

  8. #8
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,020
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: MKV to MP4 Conversion

    Install 'Gnome Subtitles'. Open the .ass file with it, and save the file to SubRip (.srt).

    Then on the terminal:
    Code:
    MP4Box -ttxt subtitles.srt
    That should get you a .ttxt file compatible with mp4.

    Let us know how it goes.
    Regards.

  9. #9
    Join Date
    Apr 2009
    Location
    USA
    Beans
    23
    Distro
    Xubuntu

    Re: MKV to MP4 Conversion

    I have been working on a project like this for a while and even have a nearly completed script for doing the encoding.

    here is the link to my forum post -> http://ubuntuforums.org/showthread.php?t=2113242

    I still need to polish the script as it has issues with filenames that have special charecters and spaces in them.

    The script dose hard subbing btw so that all the nice work the sub groups do is persevered even on hardware decoders that would normally ruin the subs.
    Last edited by Wolfpup; February 21st, 2013 at 10:34 PM.

  10. #10
    Join Date
    Jun 2009
    Beans
    18

    Re: MKV to MP4 Conversion

    I've got a script very similar to yours wolf... I will paste it below... I managed to get around all the fancy commandline-fu with a extremely simple, yet in my opinion elegant solution in regards to escaping all the special characters.

    granted, it's a MAJOR workaround, but it works quite well.

    Code:
    #!/bin/bash
    
    for TEST in *.mkv
    do
        
        mv "$TEST" "TEMP.mkv"
        subno=`mkvmerge -i "TEMP.mkv" | grep subtitles | awk -F " " '{print $3}' | sed 's/://g'`
        mkvextract tracks "TEMP.mkv" "$subno":"TEMP.ass"
        ffmpeg -i "TEMP.mkv" -c:v libx264 -crf 22 -preset veryfast -c:a copy -vf "ass=TEMP.ass" "`basename "$TEST" .mkv`.mp4"
        mv "TEMP.mkv" "$TEST"
        rm "TEMP.ass"
    
    done
    
    exit 0
    sorry... I had to edit out the comments on the script

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •