View Full Version : mkv to mp4 (h.264+aac+ac3) with video pass-through program?
Mike_111
19th February 2010, 18:14
I'm looking for a program that can convert mkv (h.264+ac3) into mp4 (h.264+aac+ac3). With video pass-through(!) and two audio streams (I need the same audio stream as aac and ac3).
All I have found so far are guides where you have to manually demux the mkv, then use another tool to manually convert the ac3 to aac and then yet another tool to remux the three streams. Or tools that can't convert ac3 into aac or can't add a second audio stream (directly from the mkv source).
If anybody knows a program that can do it all (preferably in one step) I would be grateful, since I need to convert quite a few files (DVDs that I converted into mkvs but now my new player doesn't support the container, the streams itself are fine). Thanks!
txporter
19th February 2010, 18:59
You might want to look at this batch file (http://www.tivocommunity.com/tivo-vb/showthread.php?p=7711412#post7711412) that some of the Tivo users are using for MKV to MP4 conversion. It will batch remux a bunch of MKV files to MP4 files, but it won't do the AC3 --> AAC conversion (although you could probably just add it later or update the batch file to do it).
stax76
19th February 2010, 19:04
You can also try StaxRip, there is a 'Just Mux' video profile to pass-through video and there is a 'Just Mux' audio profile to pass-through audio.
http://forum.doom9.org/showthread.php?p=1375003#post1375003
Mike_111
27th February 2010, 11:22
You can also try StaxRip, there is a 'Just Mux' video profile to pass-through video and there is a 'Just Mux' audio profile to pass-through audio.
http://forum.doom9.org/showthread.php?p=1375003#post1375003
Thanks for your response. But how can I add the same audio stream twice (AAC + AC3)? StaxRip always says "Invalid Audio Settings" because "the first and second audio source files are identical" and won't let me proceed. Is there a way to deactivate this warning? I looked through the options but couldn't find anything.
roozhou
27th February 2010, 12:02
You may take a look at this (http://forum.doom9.org/showthread.php?t=141441).
Download the direct264 package as well as ffmpeg(here do not use official ffmpeg builds).
Make sure you have mkv splitter and ac3 decoder installed on your system. (e.g. Haali + ffdshow)
Use the following command line to do it in one pass:
CTAACEncoder -d -b 128000 -o - input.mkv | ffmpeg -i input.mkv -vcodec copy -acodec copy -sn output.mp4 -i - -acodec copy -newaudio
Note that CTAACEncoder will automatically downmix your 5.1 AC3 to stereo.
Well official ffmpeg should also do it in one pass:
ffmpeg -i input.mkv -vcodec copy -acodec aac -ab 128 -sn output.mp4 -acodec copy -newaudio
However there are two problems:
1) The quality of ffmpeg's built-in aac encoder is bad.
2) If your H264 stream contains b-frames, stream copy will fail due to ffmpeg's lack of dts generation for mkv. It is only fixed in my build.
Mike_111
28th February 2010, 02:10
You may take a look at this (http://forum.doom9.org/showthread.php?t=141441).
Download the direct264 package as well as ffmpeg(here do not use official ffmpeg builds).
Make sure you have mkv splitter and ac3 decoder installed on your system. (e.g. Haali + ffdshow)
Use the following command line to do it in one pass:
CTAACEncoder -d -b 128000 -o - input.mkv | ffmpeg -i input.mkv -vcodec copy -acodec copy -sn output.mp4 -i - -acodec copy -newaudio
Note that CTAACEncoder will automatically downmix your 5.1 AC3 to stereo.
Well official ffmpeg should also do it in one pass:
ffmpeg -i input.mkv -vcodec copy -acodec aac -ab 128 -sn output.mp4 -acodec copy -newaudio
However there are two problems:
1) The quality of ffmpeg's built-in aac encoder is bad.
2) If your H264 stream contains b-frames, stream copy will fail due to ffmpeg's lack of dts generation for mkv. It is only fixed in my build.
Thanks, that looks promising. Couple questions:
1) Where do I get the CTAACEncoder? I downloaded direct264_20100225.7z but there's no CTAACEncoder, although your link implies that it's included in the package?
2) Can I change the audio stream order since I need the AAC first and AC3 second?
3) official ffmpeg doesn't work for me since my H.264 stream contains b-frames and your ffmpeg can't do aac encoding ("demuxer_muxer only"), did I understand that correct?
roozhou
28th February 2010, 08:25
Thanks, that looks promising. Couple questions:
1) Where do I get the CTAACEncoder? I downloaded direct264_20100225.7z but there's no CTAACEncoder, although your link implies that it's included in the package?
My bad, CTAACEncoder is missing in that package, please download an earlier package (http://sourceforge.net/projects/direct264/files/Direct264%20SVN%20Release/2010-02-08/direct264_20100208.7z/download).
2) Can I change the audio stream order since I need the AAC first and AC3 second?
Try adding the following parameters to ffmpeg cmdline:
-map 0:0 -map 1:0 -map 0:1
3) official ffmpeg doesn't work for me since my H.264 stream contains b-frames and your ffmpeg can't do aac encoding ("demuxer_muxer only"), did I understand that correct?
Correct. My build does not contain aac encoder.
Mike_111
1st March 2010, 09:15
FYI, I have these strange requirements because I want to be able to play the mkv-to-mp4 video at least on my Computer (AC3), my AppleTV (AAC+AC3) and my iPhone 3GS (AAC), without having to transcode, give up AC3 or the need for multiple versions of the video. And I know the h.264 stream itself is already compatible with all these devices, so...
My bad, CTAACEncoder is missing in that package, please download an earlier package (http://sourceforge.net/projects/direct264/files/Direct264%20SVN%20Release/2010-02-08/direct264_20100208.7z/download).
Thanks! So I tried it and it works in principle! But I have a few questions. Sorry, should be the last time :)
1) Speed.
CTAACEncoder -d -b 128000 -o - h:\input.mkv | ffmpeg -i h:\input.mkv -vcodec copy -acodec copy -s
n h:\out3.mp4 -i - -acodec copy -newaudio -map 0:0 -map 1:0 -map 0:1
FFmpeg version SVN-r21997, Copyright (c) 2000-2010 the FFmpeg developers
built on Feb 23 2010 22:31:38 with gcc 4.4.1
configuration:
libavutil 50. 9. 0 / 50. 9. 0
libavcodec 52.55. 0 / 52.55. 0
libavformat 52.53. 0 / 52.53. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.10. 0 / 0.10. 0
[matroska @ 0xbfefe0]Unknown entry 0x80
[matroska @ 0xbfefe0]max_analyze_duration reached
[matroska @ 0xbfefe0]Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 500.00 (500/1)
Input #0, matroska, from 'h:\input.mkv':
Duration: 00:10:03.36, start: 0.000000, bitrate: 448 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 704x416 [PAR 64:45 DAR 1408:585], PAR 91:64 DAR 77:32, 25 fps, 500 tbr, 1k tbn, 50 tbc
Stream #0.1(deu): Audio: 0x0000, 48000 Hz, 5.1, 448 kb/s
Decoding audio stream #0 via DirectShow
[aac @ 0x10cde60]max_analyze_duration reached
[aac @ 0x10cde60]Estimating duration from bitrate, this may be inaccurate
Input #1, aac, from 'pipe:':
Duration: N/A, bitrate: 125 kb/s
Stream #1.0: Audio: aac, 24000 Hz, 2 channels, s16, 125 kb/s
Output #0, mp4, to 'h:\out3.mp4':
Metadata:
encoder : Lavf52.53.0
Stream #0.0(eng): Video: 0x0021, yuv420p, 704x416 [PAR 91:64 DAR 77:32], q=2-31, 50 tbn, 25 tbc
Stream #0.1: Audio: 0x0040, 24000 Hz, 2 channels, 125 kb/s
Stream #0.2(deu): Audio: 0x00a5, 48000 Hz, 5.1, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Stream #0.1 -> #0.2
[mp4 @ 0x1478250]st:0 error, non monotone timestamps 1 >= 1
[mp4 @ 0x1478250]st:0 error, non monotone timestamps 2 >= 2
frame=15084 fps= 27 q=-1.0 Lsize= 133547kB time=603.23 bitrate=1813.6kbps
video:90807kB audio:42417kB global headers:0kB muxing overhead 0.242225%
The result works great, but I only get around 25fps with 5% CPU usage on a Core 2 Quad. With only ffmpeg demux/mux I get around 6000fps, so it has to be the audio encoder. Any idea what I'm doing wrong here?
2) Since I also want to be able to transfer the video on my iPhone 3GS the file info has to say h.264 level 3.0 or lower or iTunes won't transfer the file, even though the iPhone 3GS itself can play level 3.1 without problems. Luckily I found your post about changing the h.264 bitstream with your modified ffmpeg
http://forum.doom9.org/showthread.php?t=152419
So I tried to change the level to 3.0 but somehow it didn't work, mediainfo and iTunes still identify the h.264 stream as level 3.1.
CTAACEncoder -d -b 128000 -o - h:\input.mkv | ffmpeg -i h:\input.mkv -vcodec copy -acodec copy -s
n h:\out4.mp4 -i - -acodec copy -newaudio -map 0:0 -map 1:0 -map 0:1 -vbsf h264_changesps=level=30
FFmpeg version SVN-r21997, Copyright (c) 2000-2010 the FFmpeg developers
built on Feb 23 2010 22:31:38 with gcc 4.4.1
configuration:
libavutil 50. 9. 0 / 50. 9. 0
libavcodec 52.55. 0 / 52.55. 0
libavformat 52.53. 0 / 52.53. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.10. 0 / 0.10. 0
[matroska @ 0xa4efe0]Unknown entry 0x80
[matroska @ 0xa4efe0]max_analyze_duration reached
[matroska @ 0xa4efe0]Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 500.00 (500/1)
Input #0, matroska, from 'h:\input.mkv':
Duration: 00:10:03.36, start: 0.000000, bitrate: 448 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 704x416 [PAR 64:45 DAR 1408:585], PAR 91:64 DAR 77:32, 25 fps, 500 tbr, 1k tbn, 50 tbc
Stream #0.1(deu): Audio: 0x0000, 48000 Hz, 5.1, 448 kb/s
Decoding audio stream #0 via DirectShow
[aac @ 0xf234a0]max_analyze_duration reached
[aac @ 0xf234a0]Estimating duration from bitrate, this may be inaccurate
Input #1, aac, from 'pipe:':
Duration: N/A, bitrate: 125 kb/s
Stream #1.0: Audio: aac, 24000 Hz, 2 channels, s16, 125 kb/s
Output #0, mp4, to 'h:\out4.mp4':
Metadata:
encoder : Lavf52.53.0
Stream #0.0(eng): Video: 0x0021, yuv420p, 704x416 [PAR 91:64 DAR 77:32], q=2-31, 50 tbn, 25 tbc
Stream #0.1: Audio: 0x0040, 24000 Hz, 2 channels, 125 kb/s
Stream #0.2(deu): Audio: 0x00a5, 48000 Hz, 5.1, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Stream #0.1 -> #0.2
[mp4 @ 0xc50050]st:0 error, non monotone timestamps 1 >= 1
[mp4 @ 0xc50050]st:0 error, non monotone timestamps 2 >= 2
frame=15084 fps= 27 q=-1.0 Lsize= 133547kB time=603.23 bitrate=1813.6kbps
video:90807kB audio:42417kB global headers:0kB muxing overhead 0.242225%
Any idea what I'm doing wrong?
I really appreciate your help and your fantastic work!
PS: If someone knows what additional ffmpeg parameters I need (if possible at all) or what conditions have to be met so that iTunes recognizes both audio streams and shows the audio dialog (where I can chose between the AAC and AC3 audio stream) I would be grateful!
b66pak
1st March 2010, 18:09
changing refs is a very bad idea...
http://forum.doom9.org/showthread.php?p=1377002#post1377002
_
Rippa
1st March 2010, 18:13
I solved this using Handbrake. Please see my thread in the encoder GUI forum.
Mike_111
1st March 2010, 19:04
changing refs is a very bad idea...
http://forum.doom9.org/showthread.php?p=1377002#post1377002
_
I'm sorry, I don't understand. Why change refs? I just want to change the h.264 level (identifier?) to 3.0 from 3.1. The video just has to tell iTunes that it's level 3.0, in my case it doesn't matter what it really is since I know that the iPhone 3GS can play my video without problems. As far as I understand it roozhou's modified ffmpeg should be able to do this and I'm just doing something wrong...
I solved this using Handbrake. Please see my thread in the encoder GUI forum.
Thanks for you response, I assume you mean this thread:
http://forum.doom9.org/showthread.php?t=153105
But that's not exactly my problem since I don't want to reencode my videos. I know and use Handbrake but sadly it doesn't support video passthrough. Which would have been the easiest solution but that's not gonna happen. Requests for the video passthrough feature get shut down for years now, Handbrake just doesn't want to be a demuxer/muxer.
b66pak
1st March 2010, 19:28
@Mike_111 oops...i get it wrong...
_
roozhou
2nd March 2010, 02:54
1) Speed.
The result works great, but I only get around 25fps with 5% CPU usage on a Core 2 Quad. With only ffmpeg demux/mux I get around 6000fps, so it has to be the audio encoder. Any idea what I'm doing wrong here?
Try adding "-mt" after "-d"
So I tried to change the level to 3.0 but somehow it didn't work, mediainfo and iTunes still identify the h.264 stream as level 3.1.
Try placing "-vbsf h264_changesps=level=30" before the second "-i" because it should apply to the first input file.
Mike_111
2nd March 2010, 18:36
Try placing "-vbsf h264_changesps=level=30" before the second "-i" because it should apply to the first input file.
Fantastic! Now the level gets changed like it's supposed to!
Try adding "-mt" after "-d"
Sadly this didn't change anything. CPU usage is still just around 5% with 27fps. Anything else I can do or test to get to the bottom of this? Really appreciate your help!
CTAACEncoder -d -mt -b 128000 -o - h:\input.mkv | ffmpeg -i h:\input.mkv -vcodec copy -acodec cop
y -vbsf h264_changesps=level=30 -sn h:\out5.mp4 -i - -acodec copy -newaudio -map 0:0 -map 1:0 -map 0:1
FFmpeg version SVN-r21997, Copyright (c) 2000-2010 the FFmpeg developers
built on Feb 23 2010 22:31:38 with gcc 4.4.1
configuration:
libavutil 50. 9. 0 / 50. 9. 0
libavcodec 52.55. 0 / 52.55. 0
libavformat 52.53. 0 / 52.53. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.10. 0 / 0.10. 0
[matroska @ 0xcdefe0]Unknown entry 0x80
[matroska @ 0xcdefe0]max_analyze_duration reached
[matroska @ 0xcdefe0]Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 500.00 (500/1)
Input #0, matroska, from 'h:\input.mkv':
Duration: 00:10:03.36, start: 0.000000, bitrate: 448 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 704x416 [PAR 64:45 DAR 1408:585], PAR 91:64 DAR 77:32, 25 fps, 500 tbr, 1k tbn, 50 tbc
Stream #0.1(deu): Audio: 0x0000, 48000 Hz, 5.1, 448 kb/s
Decoding audio stream #0 via DirectShow
[aac @ 0xfb34a0]max_analyze_duration reached
[aac @ 0xfb34a0]Estimating duration from bitrate, this may be inaccurate
Input #1, aac, from 'pipe:':
Duration: N/A, bitrate: 125 kb/s
Stream #1.0: Audio: aac, 24000 Hz, 2 channels, s16, 125 kb/s
Output #0, mp4, to 'h:\out5.mp4':
Metadata:
encoder : Lavf52.53.0
Stream #0.0(eng): Video: 0x0021, yuv420p, 704x416 [PAR 91:64 DAR 77:32], q=2-31, 50 tbn, 25 tbc
Stream #0.1: Audio: 0x0040, 24000 Hz, 2 channels, 125 kb/s
Stream #0.2(deu): Audio: 0x00a5, 48000 Hz, 5.1, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Stream #0.1 -> #0.2
[mp4 @ 0xce0050]st:0 error, non monotone timestamps 1 >= 1
[mp4 @ 0xce0050]st:0 error, non monotone timestamps 2 >= 2
frame=15084 fps= 27 q=-1.0 Lsize= 133547kB time=603.23 bitrate=1813.6kbps
video:90807kB audio:42417kB global headers:0kB muxing overhead 0.242225%
roozhou
2nd March 2010, 18:45
OK I did a test on a similar file and it gave me ~300fps and ~70% CPU load on my 1.8G Turion X2.
What demuxer and decoder are you using? Try running "CTAACEncoder -d -mt -b 128000 -o NUL h:\input.mkv" and tell me your encoding speed and CPU usage.
Mike_111
2nd March 2010, 20:42
OK I did a test on a similar file and it gave me ~300fps and ~70% CPU load on my 1.8G Turion X2.
What demuxer and decoder are you using?
I'm using ffdshow tryouts revision 3233 and haali 1.9.355.21 both with default settings. Should I try something else or change the default settings?
Try running "CTAACEncoder -d -mt -b 128000 -o NUL h:\input.mkv" and tell me your encoding speed and CPU usage.
CTAACEncoder's CPU usage is 3%-7% on my 2.66 GHz Core 2 Quad.
CTAACEncoder -d -mt -b 128000 -o NUL h:\input.mkv
Decoding audio stream #0 via DirectShow
h:\input.mkv --> NUL
603 seconds processed
Encoding finished
roozhou
3rd March 2010, 03:02
Strange. I was also using Haali + ffdshow. Is the encoding speed same as playback speed?
I guess it could be one of the following reasons:
1) HDD read becomes bottleneck.(Your source bitrate is too high)
2) Demuxer or decoder has limited maximum decoding speed to playback speed.
Try switching to MPC Matroska Splitter(MatroskaSplitter.ax in MPC-HC's standalone filters).
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.