Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Newbies

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th February 2010, 18:14   #1  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
mkv to mp4 (h.264+aac+ac3) with video pass-through program?

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!
Mike_111 is offline   Reply With Quote
Old 19th February 2010, 18:59   #2  |  Link
txporter
Registered User
 
Join Date: Nov 2009
Posts: 110
You might want to look at this batch file 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).
txporter is offline   Reply With Quote
Old 19th February 2010, 19:04   #3  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
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.ph...03#post1375003

Last edited by stax76; 19th February 2010 at 19:10.
stax76 is offline   Reply With Quote
Old 27th February 2010, 11:22   #4  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
Quote:
Originally Posted by stax76 View Post
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.ph...03#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.
Mike_111 is offline   Reply With Quote
Old 27th February 2010, 12:02   #5  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
You may take a look at this.
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:
Code:
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:
Code:
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.
roozhou is offline   Reply With Quote
Old 28th February 2010, 02:10   #6  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
Quote:
Originally Posted by roozhou View Post
You may take a look at this.
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:
Code:
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:
Code:
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?
Mike_111 is offline   Reply With Quote
Old 28th February 2010, 08:25   #7  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
Quote:
Originally Posted by Mike_111 View Post
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.
Quote:
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
Quote:
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.
roozhou is offline   Reply With Quote
Old 1st March 2010, 09:15   #8  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
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...

Quote:
Originally Posted by roozhou View Post
My bad, CTAACEncoder is missing in that package, please download an earlier package.
Thanks! So I tried it and it works in principle! But I have a few questions. Sorry, should be the last time

1) Speed.
Code:
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.

Code:
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!

Last edited by Mike_111; 1st March 2010 at 09:17.
Mike_111 is offline   Reply With Quote
Old 1st March 2010, 18:09   #9  |  Link
b66pak
Registered User
 
b66pak's Avatar
 
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
changing refs is a very bad idea...

http://forum.doom9.org/showthread.ph...02#post1377002
_
b66pak is offline   Reply With Quote
Old 1st March 2010, 18:13   #10  |  Link
Rippa
Registered User
 
Join Date: Feb 2010
Posts: 3
I solved this using Handbrake. Please see my thread in the encoder GUI forum.
Rippa is offline   Reply With Quote
Old 1st March 2010, 19:04   #11  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
Quote:
Originally Posted by b66pak View Post
changing refs is a very bad idea...

http://forum.doom9.org/showthread.ph...02#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...

Quote:
Originally Posted by Rippa View Post
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.

Last edited by Mike_111; 1st March 2010 at 19:14.
Mike_111 is offline   Reply With Quote
Old 1st March 2010, 19:28   #12  |  Link
b66pak
Registered User
 
b66pak's Avatar
 
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
@Mike_111 oops...i get it wrong...
_
b66pak is offline   Reply With Quote
Old 2nd March 2010, 02:54   #13  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
Quote:
Originally Posted by Mike_111 View Post
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"
Quote:
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.
roozhou is offline   Reply With Quote
Old 2nd March 2010, 18:36   #14  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
Quote:
Originally Posted by roozhou View Post
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!

Quote:
Originally Posted by roozhou View Post
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!

Code:
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%
Mike_111 is offline   Reply With Quote
Old 2nd March 2010, 18:45   #15  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
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.
roozhou is offline   Reply With Quote
Old 2nd March 2010, 20:42   #16  |  Link
Mike_111
Registered User
 
Join Date: Jun 2007
Posts: 31
Quote:
Originally Posted by roozhou View Post
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?

Quote:
Originally Posted by roozhou View Post
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.
Code:
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
Mike_111 is offline   Reply With Quote
Old 3rd March 2010, 03:02   #17  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
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).
roozhou is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:18.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.