DTS Passthrough (sort of)

Archive of historical development discussions
Discussions / Development has moved to GitHub
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

DTS Passthrough (sort of)

Post by JohnAStebbins » Wed Dec 10, 2008 11:55 pm

So I got this Blu-ray title (Wanted) that has nothing but DTS-HD and DTS audio. And I really wanted to grab the original audio. So I hacked something up that works to a certain extent. Several caveats. We don't have a DTS encoder handy to generate the silence sample that is used in sync.c, so if the source requires silence insertion, bad things will probably happen. For some reason I haven't figured out yet, audio sync in AVI files slips. And I didn't do anything for MP4. There is no equivalent MP4AddDTSAudioTrack in libmp4v2, so I didn't know where to begin. But it worked great for MKV.

http://handbrake.fr/pastebin/pastebin.php?show=345

EDIT: hmm, that pastebin patch fails for me on hunk 7, but the only difference between it and on that succeeds is white space.
Figured it out. Using the download link seems to be adding <CR> to every line. If you copy/paste from the text in the edit box at the bottom, it works as expected.

jzietman
Regular User
Posts: 146
Joined: Mon Feb 04, 2008 3:29 pm

Re: DTS Passthrough (sort of)

Post by jzietman » Sat Dec 13, 2008 8:09 am

Hey John,

I wanted to test this patch, but clicking on that link sends me to a blank pastebin space. I see no patch code there... Did you remove it for some reason?

Thanks,
Jack

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Sat Dec 13, 2008 5:57 pm

The pastebin seems to have expired. There were some bugs anyway. I've made a new patch against head.
I've added something to handle audio gaps in the dts stream. Since we can't insert silence, I force a skip in all other streams to resync. I still haven't figured out what's up with avi files. For some reason the video is playing long. But if I play the same file with the audio disabled (mplayer -nosound option) it plays the correct length. I've verified that the video is exactly the same as when using a different audio codec. I'm beginning to think it's a player problem, even though both vlc and mplayer show the problem. I was going to add code to test.c to allow specifying dts for output, but it seems someone already did that :? .

http://handbrake.fr/pastebin/pastebin.php?show=350

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Sat Jan 10, 2009 8:42 pm

From my searching, it appears there is no standard (or even non-standard) way of putting dts in mp4. However, I found an interesting site that is run by Apple. It is the registration authority for code-points in mp4. It lists all registered codec code-points and provides links to a lot of documentation.
http://www.mp4ra.org/codecs.html

cvk_b
Veteran User
Posts: 527
Joined: Sun Mar 18, 2007 2:11 am

Re: DTS Passthrough (sort of)

Post by cvk_b » Sat Jan 10, 2009 8:56 pm

Nice find.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Fri Jan 16, 2009 5:33 pm

Pastebin expired again. Here's an updated patch against svn 2088.

http://handbrake.fr/pastebin/pastebin.php?show=405

burns1111
Posts: 6
Joined: Tue Nov 11, 2008 5:16 pm

Re: DTS Passthrough (sort of)

Post by burns1111 » Wed Jan 21, 2009 1:09 am

I copied in the pastebin diff and was able to patch the files (mostly). There was a problem patching hb-backend.c at line 2746, but I entered the lines manually and compiled and everything worked great. I have the option to do DTS-passthru now and an currently giving an encode a go. I suppose the error could have occured due to me being a revision 2090.

This is something I've been looking forward to! Thanks for your work! I'll let you all know if anything odd comes up or if I notice anything code-wise.


Cheers.

golias
Regular User
Posts: 105
Joined: Wed Jan 03, 2007 7:29 pm

Re: DTS Passthrough (sort of)

Post by golias » Fri Jan 23, 2009 2:55 am

This is EPIC. I'm not too familiar with the procedure for applying patches like this, so I guess I've got some Wiki readin' to do (unless it gets rolled into a beta build in the near future.)

Kudos!

geneg1
Posts: 1
Joined: Fri Jan 23, 2009 5:12 am

Re: DTS Passthrough (sort of)

Post by geneg1 » Fri Jan 23, 2009 5:27 am

Awesome! I can confirm that John's patch can successfully encode the DTS HD 5.1 audio stream in I, Robot (Blu-Ray) into an MKV container. VLC can pass it through to a receiver but (sadly) QuickTime via Perian does not (it downmixes it to Stereo during playback).

Like others, from John's pastebin I had to apply one of the hunks manually against svn2088. No biggie.

I also took the liberty of adding to the patch and the following pastebin combines the DTS support patch with the GUI changes I needed before I could get DTS passthrough to appear as an option in the Mac OS X UI. This is also against svn2088 and incorporates John's patch.

I'm new to Handbrake so apologies in advance if this isn't the correct way to contribute, but anyway...

http://handbrake.fr/pastebin/pastebin.php?show=419

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Fri Jan 23, 2009 11:02 pm

Well, I finally figured out why I can't get a/v sync with dts in avi files. The players I've looked at use the audio bitrate specified in the audio header to maintain sync. The bitrate that the dts audio stream signals is 768000 bps. But if you look at the audio frame duration (960 ticks) and the frame size (1006 bytes), the actual bitrate is 754500. In comparison, an ac3 stream that signals 448000 bps has frame frame duration (2880 ticks) and frame size (1792) that match the bitrate.

So I had to ask myself, why do sources with dts encoded with mencoder play correctly. They also put the incorrect bitrate in the audio header. A close look at the file created reveals that they've fudged the video stream somehow to compensate for the incorrect estimation of audio timestamps. The video when played without the audio actually plays shorter than it should. When played with the audio enabled, the a/v sync code stretches the video to the correct duration.

The avi audio bitrate is actually specified in bytes per sec, which would be 94312.5. Since this isn't a round number, there would be some amount of drift, even if I specified this value in the avi. Give how ugly this seems to be, I think I'll just chalk this up to yet another thing not supported in avi.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Sat Jan 24, 2009 7:56 pm

I've committed the linux gui changes needed for dts passthru. They are currently disabled. To enable, just uncomment the DTS entry in this array in gtk/src/hb-backend.c

Code: Select all

static options_map_t d_acodec_opts[] =
{
    {"AAC (faac)",      "faac",   HB_ACODEC_FAAC, "faac"},
    {"MP3 (lame)",      "lame",   HB_ACODEC_LAME, "lame"},
    {"Vorbis",          "vorbis", HB_ACODEC_VORBIS, "vorbis"},
    {"AC3 (pass-thru)", "ac3",    HB_ACODEC_AC3, "ac3"},
//  {"DTS (pass-thru)", "dts",    HB_ACODEC_DCA, "dts"},
};
I've updated the patch on the pastebin. It now only has the libhb changes.
http://handbrake.fr/pastebin/pastebin.php?show=421

geure
Posts: 3
Joined: Tue Apr 07, 2009 4:24 am

Re: DTS Passthrough (sort of)

Post by geure » Tue Apr 07, 2009 4:50 am

Hello. I have been trying persistently to get DTS pass-thru to work using this patch without success. I've successfully compiled the patch using current SVN (at the time) on Ubuntu and Windows Vista. I've even compiled with SVN version 2093. But my results are always the same either way - the encode hangs at 0.01% and all CPUs drop to zero.

When I use a Blu-ray disk as source (using Vista), with DTSMA, the video encodes fine but does not have audio in the MKV output file. When I use an MKV or remuxed M2TS file as source (Vista or Ubuntu) that has the DTS core demuxed/remuxed using eac3to and mkvmerge (or tsmuxer), the encode hangs, and this is the log I've included below.

I have manually validated that all lines of the code in the posted patch file are present in their respective files on my system, so I'm not sure what else it might be. I'm sure I can get this to work with help. I must be doing something wrong here.

Thank you very much!

Code: Select all

### CLI Query:  -i "C:\Users\Dad\Desktop\Hellboy II - The Golden Army.mkv" -t 1 -c 1-20 -o "C:\Users\Dad\Desktop\test.mkv" -f mkv -4  -w 1920 -P  --detelecine --decomb -e x264 -q 22 -a 1 -E dts -6 auto -R 0 -B 0 -D 1 -x level=41:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all:b-adapt=2 -v 

#########################################

[22:55:42] hb_init: checking cpu count
[22:55:42] hb_init: starting libhb thread
HandBrake svn2282 (2009033001) - Cygwin i686 - http://handbrake.fr
4 CPUs detected
Opening C:\Users\Dad\Desktop\Hellboy II - The Golden Army.mkv...
[22:55:42] hb_scan: path=C:\Users\Dad\Desktop\Hellboy II - The Golden Army.mkv, title_index=1
[22:55:42] scan: trying to open with libdvdread
[22:55:42] dvd: not a dvd - trying as a stream/file instead
Input #0, matroska, from 'C:\Users\Dad\Desktop\Hellboy II - The Golden Army.mkv':
  Duration: 01:59:48.91, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, yuv420p, 1920x1072, PAR 127:128 DAR 1905:1072, 23.98 tbr, 1k tbn, 48 tbc
    Stream #0.1(eng): Audio: dca, 48000 Hz, 5.1, s16
    Stream #0.2(eng): Subtitle: 0x0000
[22:55:42] scan: decoding previews for title 1
[22:55:42] scan: audio 0x1: DCA, rate=48000Hz, bitrate=1536000 English (DTS) (5.1 ch)
Scanning title 1...
Scanning title 1...
[22:55:42] scan: 10 previews, 1920x1072, 23.976 fps, autocrop = 16/24/0/0, aspect 16:9, PAR 1:1
[22:55:42] scan: title (0) job->width:1936, job->height:1040
[22:55:43] libhb: scan thread found 1 valid title(s)
+ title 1:
  + vts 0, ttn 0, cells 0->0 (0 blocks)
  + duration: 01:59:48
  + size: 1920x1072, aspect: 1.79, 23.976 fps
  + autocrop: 16/24/0/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:07:00
    + 2: cells 0->0, 0 blocks, duration 00:04:48
    + 3: cells 0->0, 0 blocks, duration 00:05:57
    + 4: cells 0->0, 0 blocks, duration 00:08:50
    + 5: cells 0->0, 0 blocks, duration 00:03:20
    + 6: cells 0->0, 0 blocks, duration 00:04:47
    + 7: cells 0->0, 0 blocks, duration 00:03:49
    + 8: cells 0->0, 0 blocks, duration 00:05:53
    + 9: cells 0->0, 0 blocks, duration 00:03:54
    + 10: cells 0->0, 0 blocks, duration 00:06:44
    + 11: cells 0->0, 0 blocks, duration 00:04:08
    + 12: cells 0->0, 0 blocks, duration 00:06:22
    + 13: cells 0->0, 0 blocks, duration 00:07:19
    + 14: cells 0->0, 0 blocks, duration 00:03:11
    + 15: cells 0->0, 0 blocks, duration 00:05:49
    + 16: cells 0->0, 0 blocks, duration 00:04:19
    + 17: cells 0->0, 0 blocks, duration 00:09:14
    + 18: cells 0->0, 0 blocks, duration 00:06:34
    + 19: cells 0->0, 0 blocks, duration 00:09:45
    + 20: cells 0->0, 0 blocks, duration 00:07:54
  + audio tracks:
    + 1, English (DTS) (5.1 ch), 48000Hz, 1536000bps
  + subtitle tracks:
Invalid sample rate 0, using input rate 48000
[22:55:43] 1 job(s) to process
[22:55:43] starting job
[22:55:43] job configuration:
[22:55:43]  * source
[22:55:43]    + C:\Users\Dad\Desktop\Hellboy II - The Golden Army.mkv
[22:55:43]    + title 1, chapter(s) 1 to 20
[22:55:43]    + container: matroska
[22:55:43]  * destination
[22:55:43]    + C:\Users\Dad\Desktop\test.mkv
[22:55:43]    + container: Matroska (.mkv)
[22:55:43]  * video track
[22:55:43]    + decoder: h264
[22:55:43]    + frame rate: 23.976 fps -> variable fps
[22:55:43]    + loose anamorphic
[22:55:43]      + storage dimensions: 1920 * 1072 -> 1920 * 1024, crop 16/24/0/0
[22:55:43]      + pixel aspect ratio: 127 / 128
[22:55:43]      + display dimensions: 1905 * 1024
[22:55:43]    + filters
[22:55:43]      + Detelecine (pullup) (default settings)
[22:55:43]      + Decomb (default settings)
[22:55:43]    + encoder: x264
[22:55:43]      + options: level=41:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all:b-adapt=2
[22:55:43]      + quality: 22.00 (RF)
[22:55:43]  * audio track 0
[22:55:43]    + decoder: English (DTS) (5.1 ch) (track 1, id 1)
[22:55:43]      + bitrate: 1536 kbps, samplerate: 48000 Hz
[22:55:43]    + DCA passthrough
[22:55:43] dvd: not a dvd - trying as a stream/file instead
[22:55:43] yadif thread started for segment 0
[22:55:43] yadif thread started for segment 1
[22:55:43] yadif thread started for segment 2
[22:55:43] yadif thread started for segment 3
[22:55:43] decomb thread started for segment 0
[22:55:43] decomb thread started for segment 1
[22:55:43] decomb thread started for segment 2
[22:55:43] decomb thread started for segment 3
[22:55:43] encx264: keyint-min: 24, keyint-max: 240
[22:55:43] encx264: encoding with stored aspect 127/128
[22:55:43] encx264: Encoding at constant RF 22.000000
x264 [info]: using SAR=127/128
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 PHADD SSE4.1 Cache64
x264 [info]: profile Main, level 4.1
[22:55:43] sync: expecting 172385 video frames
[22:55:43] reader: first SCR 0
^C

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Wed Apr 08, 2009 6:12 pm

Don't know what the problem might be, but here's a patch against latest svn that I'm using.
http://handbrake.fr/pastebin/pastebin.php?show=524

geure
Posts: 3
Joined: Tue Apr 07, 2009 4:24 am

Re: DTS Passthrough (sort of)

Post by geure » Fri Apr 10, 2009 3:29 am

Thanks for the patch.

Update - same behavior with the lastest patch but I've discovered that disabling detelecine and not using b-adapt=2 allows the encode to proceed normally on Ubuntu. For Vista, disabling these options got the encoder moving further but it hangs later on.

Anyway, at least I've made some progress....

mnnbzxcv
Posts: 1
Joined: Sun Apr 19, 2009 6:45 pm

Re: DTS Passthrough (sort of)

Post by mnnbzxcv » Sun Apr 19, 2009 6:58 pm

I've had the same issues as geure. It seems to differ from movie to movie. 'Bolt' is an example of having the problem. The only way I was able to get past the .1% progress was changing the container from mkv to the now depricated avi. Although that only got me about a third of the way through encoding. On some movies lowering b-frames to 2 allowed me to make some progress. When I didn't see the problem I often saw 20+ hour encode times versus my typical 4-6 when using DTS pass through.

The other issue I had had with the patch was av sync being way off with Mythtv's internal player. The movies that I was able to convert (such as 'Quantum of Solace') played well in mplayer, but not in mythtv. The audio would quickly get 30+ seconds ahead of the video. Using 'Ripbot264' (a Windows front end to eac3to, x264.exe and other tools) results in mkvs that play perfectly with all players I've tried.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5469
Joined: Sat Feb 09, 2008 7:21 pm

Re: DTS Passthrough (sort of)

Post by JohnAStebbins » Mon Apr 20, 2009 5:35 am

I've checked this patch in to svn. So please give it a try. Try mkv again as well. I've made a small change that should reduce the likelyhood of stalling while encoding to mkv. I don't know what those sync issues with mythtv are. Sync for DTS is handled almost exactly the same as ac3. Only difference is in cases where there is a really bad discontinuity in the audio, which shouldn't happen with a clean source. Were you using mkv or mp4 for those encodes. I've seen in other threads that mythtv doesn't handle our mp4's well.

geure
Posts: 3
Joined: Tue Apr 07, 2009 4:24 am

Re: DTS Passthrough (sort of)

Post by geure » Thu Apr 23, 2009 3:10 am

It's a thing of beauty! Smooth sailing for me with the latest svn. Success on both Ubuntu and Windows Vista and XP. Thanks much!!!

I have hacked the win gui to include dts in the drop-downs. It's probably not optimal but it works for me so far.
http://handbrake.fr/pastebin/pastebin.php?show=548

dynaflash
Veteran User
Posts: 3820
Joined: Thu Nov 02, 2006 8:19 pm

Re: DTS Passthrough (sort of)

Post by dynaflash » Sun Apr 26, 2009 7:37 pm

I will be adding it to the macgui shortly. I have another checkin coming up first though.

Apex
Posts: 3
Joined: Wed Apr 22, 2009 9:46 am

Re: DTS Passthrough (sort of)

Post by Apex » Mon May 11, 2009 8:01 am

@dynaflash

Thanks. I would really like to test the new DTS Passthrough Feature.
Last edited by Apex on Mon May 11, 2009 2:19 pm, edited 1 time in total.

User avatar
s55
HandBrake Team
Posts: 9591
Joined: Sun Dec 24, 2006 1:05 pm

Re: DTS Passthrough (sort of)

Post by s55 » Mon May 11, 2009 1:43 pm

WinGUI code has been checked in.

dynaflash
Veteran User
Posts: 3820
Joined: Thu Nov 02, 2006 8:19 pm

Re: DTS Passthrough (sort of)

Post by dynaflash » Tue May 12, 2009 6:08 pm

MacGui implementation checked in http://trac.handbrake.fr/changeset/2413 .

techmanrc
Posts: 1
Joined: Wed May 27, 2009 12:02 am

Re: DTS Passthrough (sort of)

Post by techmanrc » Wed May 27, 2009 12:16 am

I was thrilled to find this post about DTS passthrough support in the SVN builds of HandBrake. I've built the SVN 2446 revision of HandBrake for Mac OS 10.5 and have had mixed results with DTS passthrough. I've done seven encodes with DTS passthrough. Of the seven only four were successful. The three that failed, failed in various ways. One has audio and blank video, the other two have about 20 minutes of video but the full audio track. All encodes started with the AppleTV preset, with the only modifications being the switch to the MKV container, and adding DTS passthrough as a third audio track. I can provide encode logs for all the sessions, and am willing to help test this as much as I can, to help improve HandBrake. Please let me know the best way to provide the logs. Thanks.

TedJ
Veteran User
Posts: 5388
Joined: Wed Feb 20, 2008 11:25 pm

Re: DTS Passthrough (sort of)

Post by TedJ » Wed May 27, 2009 1:06 am

If you can provide activity logs, please do. You can either upload the logs to a pastebin site and post the links or submit them directly to the forum in a post, using the [code] / [/code] blocks to enclose them.

jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Re: DTS Passthrough (sort of)

Post by jbrjake » Wed May 27, 2009 2:03 pm

...and of course bug reports about checked in svn trunk code belong in bug reports, not long-in-the-tooth development threads that are already past their checkin date.

Vortec4800
Posts: 22
Joined: Sat Feb 16, 2008 7:57 am

Re: DTS Passthrough (sort of)

Post by Vortec4800 » Sat Jun 06, 2009 4:31 pm

Forgive my misunderstanding, but would this allow the AppleTV to pass a DTS audio encoding through to my receiver like it does AC3, or would the AppleTV just look at it and say "I don't know what this is or what to do with it" and ignore it (or possibly not play at all?) I know the AppleTV doesn't actually process the AC3 audio, and it wouldn't process the DTS audio either so it isn't a matter of the AppleTV not being powerful enough, just not being cooperative and recognizing the track as pass-through audio.

Post Reply