Seamlessly branching multi-disc movies with Atmos

DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Hi,

I'm making a backup of my LOTR Extended films, and in that process I want to combine the two discs into one MKV file. I did that with MakeMKV and MKVToolnix (separating out the appropriate black frames and then merging), which works perfectly when played in VLC. However, if I play it through my home theatre, there is a 1s audio gap where my AVR prepares to play the next Atmos track. This is obviously not ideal.

I know DGDemux can properly combine two Atmos tracks as long as they're part of the same on-disc playlist. Is there some part of this program that can do this with these two Atmos tracks that have had the end and start silence removed, respectively? Or if not, are you able to point me towards a program that can help me achieve what I'm trying to do?
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

Welcome to the forum, horseshowers, and thank you for your question.

Deleting video by hand without deleting the corresponding audio is problematic. I guess you know that now.

We need to know if the silence/blackness is confined to a single M2TS. Then you could use skip_first and skip_last as needed. Load the first disk into DGDemux. Choose your playlist and then highlight the first M2TS in the list and hit Preview. If it contains only the silence/blackness then skip_first will get rid of it. Ditto for skip_last. If it looks that way, then you can demux with those needed options. Then you can do the same for the second disk. Then for video merge the two by hand using binary copy (copy /b file1+file2 out). Do the same for your audio. Now mux the resulting streams into MKV.

If the silence/blackness is not contained in separate M2TS files, we'll have to :scratch: some more.
User avatar
hubblec4
Posts: 221
Joined: Tue May 02, 2023 6:03 pm

Seamlessly branching multi-disc movies with Atmos

Post by hubblec4 »

Hi horseshowers

I have also experience with such movies and in the beginning of using MKV, I had also cut streams and append them and so on.

But I use now an easier method, called Ordered Chapters.
VLC can handle Ordered Chapters but not perfect. MPC-HC/BE or mpv are better.
Only with Ordered Chapters you are able to cut and merge video/audio content frame exactly and all is done virtually.
This means you don't need cut and merge something.
With my chapterEditor is it easy to create the needed Ordered Chapters.
https://forum.doom9.net/showthread.php?t=169984
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

Thank you, hubblec4. Easier is usually better, but I'm a pedal to the metal kind of squirrel. :cry:

Feel free to support horseshowers using cE here if you like. I can learn too.
:salute:
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Sun Jul 16, 2023 7:53 am
Welcome to the forum, horseshowers, and thank you for your question.
Thank you. It's refreshing to meet a dev that actually cares about the user.
Deleting video by hand without deleting the corresponding audio is problematic. I guess you know that now.
I did delete the video and audio together, they are in sync, and it works perfectly with the AC3 fallback track and the commentary tracks. The issue is only with splicing the two Atmos tracks together, and only with bitstream to AVRs (at least with my Denon, and I assume it happens with other AVRs too).

I'm not even sure if this is something that can be done in the MKV or if it has to be fixed in the player, like multi-file UHD films had to be - the Exoplayer on my Shield still can't play Apocalypse Now properly because it was split up on the disc: https://github.com/google/ExoPlayer/issues/10520
We need to know if the silence/blackness is confined to a single M2TS.
If the silence/blackness is not contained in separate M2TS files, we'll have to :scratch: some more.
The silence and blackness is contained in the M2TS files, unfortunately.
hubblec4 wrote:
Sun Jul 16, 2023 10:58 am
Hi horseshowers

I have also experience with such movies and in the beginning of using MKV, I had also cut streams and append them and so on.

But I use now an easier method, called Ordered Chapters.
Ordered Chapters are a very cool feature, but it's my understanding that Plex doesn't support it, and thus it's sadly useless to me. Thanks for the tip tho.
User avatar
hubblec4
Posts: 221
Joined: Tue May 02, 2023 6:03 pm

Seamlessly branching multi-disc movies with Atmos

Post by hubblec4 »

Yes, Plex is a very cool video playback tool, but the missing support of Ordered Chapters in this times is very shame. Maybe if MKV is more popular, then Plex will add ordered chapter support.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

horseshowers wrote:
Sun Jul 16, 2023 12:55 pm
I did delete the video and audio together
As documented in other threads here, we discovered when implementing gaps correction you cannot arbitrarily cut and recombine THD and Atmos audio. It has to be done in a very specific way. If the rules aren't followed problems like those you are experiencing can occur.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Tue Jul 18, 2023 6:03 am
horseshowers wrote:
Sun Jul 16, 2023 12:55 pm
I did delete the video and audio together
As documented in other threads here, we discovered when implementing gaps correction you cannot arbitrarily cut and recombine THD and Atmos audio. It has to be done in a very specific way. If the rules aren't followed problems like those you are experiencing can occur.
I tried to search around on the forums before posting but didn't find anything useful. You got any links? I just want the audio to be seamless, the way it was clearly intended to be seeing as they didn't even add a fade when splitting the disc.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

I knew you were gonna ask that. Rather than point you to a massive thread, I'll explain it here.

THD/Atmos has what are called major and minor frames. A stream starts with a major frame and that is followed by a bunch of minor frames (call that a cycle). Then another major and a bunch of minors, etc. Looks like this:

+----------------+-------------- etc.

What we found is that to cut any of this audio (in the compressed domain) without annoying the decoders, you have to cut only minors from the end of a cycle, or full cycles. In your case we have:

Code: Select all

+--------------------- (end of first disk stream)
+--------------------- (beginning of second disk stream)
***                ***
The asterisks are audio you want to remove because it corresponds to black frames.

You cannot cut just the asterisks because it violates the rules at the beginnings of the streams. You could cut an entire cycle, however, so that the disk streams still start with a major. Cutting from the end is fine because that always follows the rules.

Bottom line: your cutting must be cycle-aware. Cut only full cycles or minors from the end of a cycle. DG gaps correction always removes minors from the end of the last cycle of an M2TS.When the silence/blackness is confined to a leading/trailing M2TS things are easy -- just get rid of that M2TS. If not, well, you'll need some special processing or a special tool, which I don't think anyone has provided.

Of course you can just decode everything to raw audio/video, cut as you like, and re-encode. That might be the best option for you.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Tue Jul 18, 2023 11:48 am
I knew you were gonna ask that. Rather than point you to a massive thread, I'll explain it here.

Bottom line: your cutting must be cycle-aware. Cut only full cycles or minors from the end of a cycle. DG gaps correction always removes minors from the end of the last cycle of an M2TS.When the silence/blackness is confined to a leading/trailing M2TS things are easy -- just get rid of that M2TS. If not, well, you'll need some special processing or a special tool, which I don't think anyone has provided.
I see. Thanks for the very good explanation. I take it you're not aware of a tool that can help me determine good cut-points? Is the cycle always the same length or does it vary, and if the former, how long is it?
Of course you can just decode everything to raw audio/video, cut as you like, and re-encode. That might be the best option for you.
If it was just TrueHD I'd do that, easiest thing in the world, but I don't know of any way to do it while keeping the Atmos metadata.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

Cycles can vary in length.

Using the same technology as our gaps correction for THD/Atmos, I could whip up a small utility for editing THD/Atmos streams. Easiest would be to just allow for cuts at the beginning and end, specified by amount of time to cut. Edited streams could then be concatenated without issues. It would be up to you to cut the video accordingly. More general would be to allow cuts anywhere. I'll experiment with this after I finish up the DTS Express support.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

If you don't mind remuxing to MKV, there may be a solution with MKVToolnix:

https://forum.videohelp.com/threads/400 ... lby-TrueHD

Read the entire thread.

I think even if it can be coerced into doing what you want, my proposed approach is simpler and more direct.

TSMuxer may also be an option. 'Split & cut' on the M2TS.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Wed Jul 19, 2023 6:18 am
Using the same technology as our gaps correction for THD/Atmos, I could whip up a small utility for editing THD/Atmos streams. Easiest would be to just allow for cuts at the beginning and end, specified by amount of time to cut. Edited streams could then be concatenated without issues. It would be up to you to cut the video accordingly. More general would be to allow cuts anywhere.
That would be much appreciated. Do you have any idea how long it may take you? Don't want to rush you, I'd just like to know how long of a wait I can expect.
Rocky wrote:
Wed Jul 19, 2023 7:00 am
If you don't mind remuxing to MKV, there may be a solution with MKVToolnix:

TSMuxer may also be an option. 'Split & cut' on the M2TS.
MKVToolnix is how I cut the files initially.

Since starting this thread I've also successfully extended an Atmos track from the Hobbit 3 by 2s to properly sync it up with the 3D bluray and that worked perfectly. Idk if I just got lucky with my cut points or if it's because every audio part I worked with came from the same M2TS track originally.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

horseshowers wrote:
Wed Jul 19, 2023 8:48 am
Do you have any idea how long it may take you?
A few days just to make the utility. Ideally, I'd like to get the disks and test with those. Speaking of which, can you give me a link to purchase them, preferably from amazon? I need the exact same disks you are using.
Since starting this thread I've also successfully extended an Atmos track from the Hobbit 3 by 2s to properly sync it up with the 3D bluray and that worked perfectly. Idk if I just got lucky with my cut points or if it's because every audio part I worked with came from the same M2TS track originally.
Without knowing exactly what you did (full process) it's hard to comment. Let's leave that aside for now and see how I get on.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Wed Jul 19, 2023 10:11 am
horseshowers wrote:
Wed Jul 19, 2023 8:48 am
Do you have any idea how long it may take you?
About a week (or less) just to make the utility.
Cool, thanks for info.
Ideally, I'd like to get the disks and test with those. Speaking of which, can you give me a link to purchase them, preferably from amazon? I need the exact same disks you are using.
I'm not entirely sure it's the exact same discs as I didn't buy them from Amazon, but the pictures here match my box set.

I could alternatively send you a full disc copy of one of the movies to ensure you have the exact same files I'm working with, purely for research purposes of course and I expect you will delete the files when you're done.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

horseshowers wrote:
Wed Jul 19, 2023 11:33 am
I could alternatively send you a full disc copy
How would you do that?

EDIT: Are you looking to keep the embedded AC3? That affects the design of the utility.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Wed Jul 19, 2023 11:45 am
horseshowers wrote:
Wed Jul 19, 2023 11:33 am
I could alternatively send you a full disc copy
How would you do that?
I already have all the discs ripped to my drive, I could upload one of the films to gofile and send you the link, or make a private torrent.
EDIT: Are you looking to keep the embedded AC3? That affects the design of the utility.
It doesn't matter to me, since MakeMKV puts that onto a separate track, and combining the AC3 tracks doesn't cause any issues. However it might matter to someone else, so I'll leave that decision to you.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

horseshowers wrote:
Wed Jul 19, 2023 12:09 pm
I already have all the discs ripped to my drive, I could upload one of the films to gofile and send you the link
Do it!

EDIT: I will have a test version of the utility for you later this evening. :wow:
User avatar
SomeHumanPerson
Posts: 96
Joined: Fri Mar 24, 2023 10:41 am

Seamlessly branching multi-disc movies with Atmos

Post by SomeHumanPerson »

If you end up making the generalized version (cut anywhere, roughly speaking), that would be amazing. In theory that should allow for some ability (maybe not perfect depending on the size of these groupings you describe) to make arbitrary sync corrections on Atmos tracks without losing the Atmos (currently impossible AFAIK).

I should probably prepare for my hopes to be dashed by physics and math.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

SomeHumanPerson wrote:
Wed Jul 19, 2023 7:09 pm
I should probably prepare for my hopes to be dashed by physics and math.
Nah, it's a walk in the park. Two days maximum, given how easy this first version was. :o

Here is an initial test version. It supports cutting at the beginning and end. Streams are THD only, no embedded AC3.

thdtrim infile.thd outfile.thd secs_to_cut_at_start secs_to_cut_at_end

E.g., cut 10.5 secs at start and 3.3 at end:

thdtrim test.thd out.thd 10.5 3.3

You would trim your first disk stream, then your second disk stream, and then join them by:

copy /b out1.thd+out2.thd final.thd

Let me know if it works, i.e., decoders are happy with the result. Basic testing was OK for me.

https://rationalqm.us/misc/horseshowers.zip

As Sherman would say: YMBDN
User avatar
SomeHumanPerson
Posts: 96
Joined: Fri Mar 24, 2023 10:41 am

Seamlessly branching multi-disc movies with Atmos

Post by SomeHumanPerson »

How precise is this going to be? As in, what range of durations can be expected in these frame cycles that are the limitation on where you can cut? Is it always/typically/maybe/never going to be sub-video-frame timing?

Can you provide feedback from the tool as to exactly where you end up making the cut (if that is meaningful based on the answer to the questions above)?

(Sorry if these questions are dumb; I'm not well versed in audio encoding implementations.)
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

Great questions. Well, it's not great. Typically:

For the starting cut, the worst case is 72ms off from what you ask for, with the average case at 36ms.

For the end cut the worst case is 0.6ms.

Yes, I can output the actual cut points.

Sync correction as in our gaps correction is always 0.6ms granular, because we always remove minors. Trimming is a different animal, because streams must start with a major.
User avatar
SomeHumanPerson
Posts: 96
Joined: Fri Mar 24, 2023 10:41 am

Seamlessly branching multi-disc movies with Atmos

Post by SomeHumanPerson »

Thank you, that's very helpful information.
DAE avatar
horseshowers
Posts: 20
Joined: Sun Jul 16, 2023 4:09 am

Seamlessly branching multi-disc movies with Atmos

Post by horseshowers »

Rocky wrote:
Wed Jul 19, 2023 12:36 pm
horseshowers wrote:
Wed Jul 19, 2023 12:09 pm
I already have all the discs ripped to my drive, I could upload one of the films to gofile and send you the link
Do it!
Sent you a PM. Took a while to upload due to the size, will probably take a while to download as well.
EDIT: I will have a test version of the utility for you later this evening. :wow:
Great! I'll download it now and see if it works.

Edit: tested it, same issue unfortunately. The files play perfectly in VLC on my PC, but when playing Atmos through my AVR I get the audio dropout at the joint.
User avatar
Rocky
Posts: 3621
Joined: Fri Sep 06, 2019 12:57 pm

Seamlessly branching multi-disc movies with Atmos

Post by Rocky »

Please tell me your command lines used for the trimming so I can duplicate what you did.

I don't have an AVR so if it is not something obvious then we may be at the end of what I can do.

EDIT: If you just join the streams without trimming, does it drop out?

EDIT2: How long is the dropout? Does audio recover?
Post Reply