Script to change mkv container to mp4

Come up with a useful post-processing script? Share it here!
Post Reply
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Script to change mkv container to mp4

Post by Mattoligy »

Hi, I am using iSabnzbd to download nzbs directly on to my iPad, mainly mkv movies!

I would like an add on script that quickly changes an mkv contained movie in to an mp4 ready to be played directly on the iPad! The script could use ffmpeg video converter from Cydia! Not sure about the audio side of things probably best to just leave it as is! Pyphon would be ok or unix I guess!?

I use SabMobileHD as a front end (Client) using localhost and it has the option to enable a script per download so would love to just tick convert mkv2mp4 and then as soon as its finished downloading the container is changed to mp4 and of I go with the native video player :-)

Any help appreciated, thanks.

Matt
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: Script to change mkv container to mp4

Post by sander »

How about

Code: Select all

ffmpeg -i blabla.mkv blabla.mp4
Disclaimer: not used by me.
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

Can't be as simple as that surely lol... Anyway if im going to use said script as a sabnzbd ad on, to use on every download on the fly I can't input file names manually! This script will auto run after sabnzbd has finished all it's other business so it needs to recognise mkvs with any file name!?

New to all this so if I'm a bit off please forgive me lol
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

Anyone? I know you super nerds are here somewhere with your magical powers :-) lol
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Script to change mkv container to mp4

Post by exussum »

Mattoligy wrote: I can't input file names manually!
You cant have manual and automatic ?
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

I want it to use ffmpeg from cydia (As this is the only conversion library on ios) to just remux/change the container from MKV to MP4 without touching the audio, i assume the audio doesn't need touching!? Most movies are in h/x.264 so i would like to keep it like that and just change the container!

Along these lines...

1) change *.mkv to input.mkv
2) move input.mkv to where ever ffpmeg needs it (If it needs to be in a specific location)
3) change container from mkv to mp4 leaving audio alone (Passthrough)
4) change input.mkv back to original movie filename (Either from .nzb file or ideally from containing folder name)
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: Script to change mkv container to mp4

Post by sander »

Mattoligy wrote:Can't be as simple as that surely lol...
Well, it is: see below the conversion of a .mkv into a .mp4 on a Ubuntu system:

Code: Select all

sander@ubuntu1004:~/downloads$ time ffmpeg -i some-clip.mkv  some-clip.mp4

FFmpeg version SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.9-0ubuntu0.10.04.1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Jun 12 2012 16:27:34, gcc: 4.4.3

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (48000/1001) -> 23.98 (24000/1001)
Input #0, matroska, from 'some-clip.mkv':
  Duration: 00:01:01.31, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, yuv420p, 1920x800, PAR 1:1 DAR 12:5, 23.98 tbr, 1k tbn, 47.95 tbc
    Stream #0.1(ger): Audio: dca, 48000 Hz, 5.1, s16
    Stream #0.2(eng): Audio: dca, 48000 Hz, 5.1, s16
    Stream #0.3(ger): Subtitle: 0x0000
Output #0, mp4, to 'some-clip.mp4':
    Stream #0.0(eng): Video: mpeg4, yuv420p, 1920x800 [PAR 1:1 DAR 12:5], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
    Stream #0.1(ger): Audio: libfaac, 48000 Hz, 5.1, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 1366 fps= 17 q=31.0 Lsize=    6921kB time=61.18 bitrate= 926.7kbits/s
video:5825kB audio:1061kB global headers:0kB muxing overhead 0.505222%

real    1m21.494s
user    1m2.628s
sys     0m0.820s
sander@ubuntu1004:~/downloads$

Some remarks:
- the resulting .mp4 is a few times smaller than the source .mkv. So it's not just a matter of changing the container
- this is on Ubuntu. I had to install a medibuntu repository to get it working with the codec.
- within my virtual machine (which is not too fast), the conversion is about 'real time', which sounds good, but means the conversion of a 1 minute clip takes about 1 minute. So I guess it won't be fast either on an ARM based iPad.
- I haven't got a iPad, so I can't help you with iPad scripting.
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

Everywhere I have researched online so far people say it is extremely quick to just re mux!?
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: Script to change mkv container to mp4

Post by sander »

Mattoligy wrote:Everywhere I have researched online so far people say it is extremely quick to just re mux!?
Well, ask those people then!
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

Didn't mean that to sound like it sounded

Uv been really helpful and i am grateful for any help at all, so thanks :-)
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Script to change mkv container to mp4

Post by exussum »

try
ffmpeg -i input.mkv -vcodec copy -acodec aac -sameq output.mp4

That should be faster
Stark5
Newbie
Newbie
Posts: 1
Joined: July 15th, 2012, 4:01 pm

Re: Script to change mkv container to mp4

Post by Stark5 »

sander wrote:Well, ask those people then!
*snicker* Gotta love the appreciation sometimes eh? Just a Note, your Advice helped me, so know it was not a waste, Thank you Sander!
Mattoligy
Newbie
Newbie
Posts: 21
Joined: July 11th, 2012, 2:58 pm

Re: Script to change mkv container to mp4

Post by Mattoligy »

Hey Sander, your suggestion works perfectly but it re encodes the whole film, which takes hours! The option including -vcodec copy however doesn't work for just changing container, it errors out and only produces an output file of a few kb...

http://cl.ly/image/0D2O0i0P161T
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Script to change mkv container to mp4

Post by exussum »

try

Code: Select all

ffmpeg -i input.mkv -vcodec copy -acodec libfaac -aq 200 output.mp4
if that doesnt work try adding -an and -vn separately and then together
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Script to change mkv container to mp4

Post by exussum »

apparently its a known bug if they dont fix it

Work around is making a full copy (copy both audio and video codecs keeping the container) and then run my command on the output from the first. Not great with space though ..

or update to the svn release - which may be hard
Post Reply