"Forced" subtitles

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.

*******************************
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

"Forced" subtitles

Post by Utumno »

Is anybody already working on attempting to add extended forced subtitle support into HandBrake ?

I see activity on other subtitle areas and closed captioning, but nothing I can immediately attribute to the support of forced subtitles. For me, personally, the absence of reasonably reliable forced subtitling where the DVD does not specifically provide a separate subtitle track for those forced subtitles in HB is the sole "missing link" on translating the DVD movie experience into an mp4/m4v file. So, I was thinking of working on some code to permit this but see little point in reinventing what other people are doing.

So - anybody looking at this in the community ? If not, I'll crank out Xcode and take a look myself.
rhester
Veteran User
Posts: 2888
Joined: Tue Apr 18, 2006 10:24 pm

Post by rhester »

There was some investigation into it that led to nothing. In short, to achieve this, you will need to manually parse and interpret the pre- and post-cell codes for each PGC and tie them to the subtitle reference in the IFO. In short, you'll have to write about 15% of a full-blown DVD player. Not even mencoder handles this - I don't think VLC does either, but I reserve the right to be wrong on that one.

Forced subtitles are a very major PITA, but if you are up to the challenge, many (including myself) would be grateful!

Rodney
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

rhester wrote:There was some investigation into it that led to nothing. In short, to achieve this, you will need to manually parse and interpret the pre- and post-cell codes for each PGC and tie them to the subtitle reference in the IFO. In short, you'll have to write about 15% of a full-blown DVD player. Not even mencoder handles this - I don't think VLC does either, but I reserve the right to be wrong on that one.

Forced subtitles are a very major PITA, but if you are up to the challenge, many (including myself) would be grateful!

Rodney
OK I'm going to take a look at this. No promises on timelines though.
saintdev
Enlightened
Posts: 146
Joined: Wed Dec 20, 2006 4:17 am

Post by saintdev »

I haven't really looked at it, but doesn't libdvdnav support forced subtitles? I thought that VLC was able to play them, and this is the only way I can think of how without too much work.
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

* adds libdvdnav to the investigation list

thanks @saintdev
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Re: "Forced" subtitles

Post by eddyg »

Utumno wrote:Is anybody already working on attempting to add extended forced subtitle support into HandBrake ?

I see activity on other subtitle areas and closed captioning, but nothing I can immediately attribute to the support of forced subtitles. For me, personally, the absence of reasonably reliable forced subtitling where the DVD does not specifically provide a separate subtitle track for those forced subtitles in HB is the sole "missing link" on translating the DVD movie experience into an mp4/m4v file. So, I was thinking of working on some code to permit this but see little point in reinventing what other people are doing.

So - anybody looking at this in the community ? If not, I'll crank out Xcode and take a look myself.
I added some code for the CLI that will attempt to guess whether subtitles should be enabled. It currently only works in 2-pass mode.

What it does is count the number of subtitles for the given language, and then selects one if it is less than 10% of the count of the maximum.

This works for titles like Kill Bill which has some Japanese that needs subtitles.

To make this work for single pass is quite easy - I just haven't done it as I always do 2-pass. In single pass you need a pre-scan that does the counting.

I attempted to parse the pre and post commands, and gave up - too hard. What I am doing works most of the time. It is still caught out now and then by commentary tracks which are very verbose whilst the normal subtitles are not.

In the CLI see --subtitle-scan.

Cheers, Ed.
rhester
Veteran User
Posts: 2888
Joined: Tue Apr 18, 2006 10:24 pm

Post by rhester »

I suppose I should point out there are two types of forced subtitles.

One, which used to be more common, is that a single code is used in the DVD nav to force the selection of a subtitle, for which there is an entire (though nearly entirely blank) subtitle stream on the DVD. (Kill Bill is a good example of this.)

The second, which is increasingly more frequently used, has only one subtitle stream that is optional, but at select points in the movie, DVD nav codes are used to check to see if the subtitle is turned on, and turns it on if it isn't. After the "forced" segment has played, further nav codes check the prior state of subtitles, and if they were off before the force, turns them back off again. (Star Wars Episode IV is a good example of this.)

The first one is pretty easy to detect and handle (mencoder and VLC do it, and eddyg's solution is a fine one). The second one is beyond nightmarish...and, sadly, the one most people are looking for.

Rodney
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

rhester wrote:I suppose I should point out there are two types of forced subtitles.

One, which used to be more common, is that a single code is used in the DVD nav to force the selection of a subtitle, for which there is an entire (though nearly entirely blank) subtitle stream on the DVD. (Kill Bill is a good example of this.)

The second, which is increasingly more frequently used, has only one subtitle stream that is optional, but at select points in the movie, DVD nav codes are used to check to see if the subtitle is turned on, and turns it on if it isn't. After the "forced" segment has played, further nav codes check the prior state of subtitles, and if they were off before the force, turns them back off again. (Star Wars Episode IV is a good example of this.)

The first one is pretty easy to detect and handle (mencoder and VLC do it, and eddyg's solution is a fine one). The second one is beyond nightmarish...and, sadly, the one most people are looking for.

Rodney
Hi Rodney,

That explains a lot, thanks. I was wondering why my technique didn't work yesterday for MIB. They must be using Cell commands to trigger the subtitles on and off.

At least you don't need a fully blown interpreter for those though. Should be able to look for the cell commands and then look them up in the cell command table (all of which we have already), and if they are an instruction to turn on subtitles we can do it there and then.

The issues come from interpreting pre and post commands, which are tied into the button presses in the menus, that is hard.

Cheers, Ed.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

eddyg wrote:That explains a lot, thanks. I was wondering why my technique didn't work yesterday for MIB. They must be using Cell commands to trigger the subtitles on and off.
Using pgcedit I don't see any cell commands in MIB. So I'm not sure how they are doing it (if indeed they are).

Cheers, Ed.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

eddyg wrote:
eddyg wrote:That explains a lot, thanks. I was wondering why my technique didn't work yesterday for MIB. They must be using Cell commands to trigger the subtitles on and off.
Using pgcedit I don't see any cell commands in MIB. So I'm not sure how they are doing it (if indeed they are).

Cheers, Ed.
Correct me if I'm wrong but the pre-commands are only executed from the menus. And can do funky stuff like turning on and off subtitles and jumping into the middle of the title. The post-commands occur when you stop the title. So the only way to get subtitles to enable/disable within the title (without having a dedicated subtitle stream) is to use cell commands.

Cheers, Ed.
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

eddyg wrote:
rhester wrote:I suppose I should point out there are two types of forced subtitles.

One, which used to be more common, is that a single code is used in the DVD nav to force the selection of a subtitle, for which there is an entire (though nearly entirely blank) subtitle stream on the DVD. (Kill Bill is a good example of this.)

The second, which is increasingly more frequently used, has only one subtitle stream that is optional, but at select points in the movie, DVD nav codes are used to check to see if the subtitle is turned on, and turns it on if it isn't. After the "forced" segment has played, further nav codes check the prior state of subtitles, and if they were off before the force, turns them back off again. (Star Wars Episode IV is a good example of this.)

The first one is pretty easy to detect and handle (mencoder and VLC do it, and eddyg's solution is a fine one). The second one is beyond nightmarish...and, sadly, the one most people are looking for.

Rodney
Hi Rodney,

That explains a lot, thanks. I was wondering why my technique didn't work yesterday for MIB. They must be using Cell commands to trigger the subtitles on and off.

At least you don't need a fully blown interpreter for those though. Should be able to look for the cell commands and then look them up in the cell command table (all of which we have already), and if they are an instruction to turn on subtitles we can do it there and then.

The issues come from interpreting pre and post commands, which are tied into the button presses in the menus, that is hard.

Cheers, Ed.
@rhester - yes, it's the second solution I'm pursuing.

@eddyg - the cell commands route is the method I am looking at pursuing. I'm hoping that all we need to do is recognise the cell "forced subtitle" command appropriately, grab the subpicture and then render it overlaid. You won't get fanciness, but you will at least get basic forced subtitle support. This is my goal, but I'm very strapped for time at the moment so the delivery won't be quick. If you fancy taking a look as well, you'll probably get there quicker, particularly with your (excellent) work on auto-detecting a distinct forced subtitle stream.

Cheers,

Ut.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

Utumno wrote:@eddyg - the cell commands route is the method I am looking at pursuing. I'm hoping that all we need to do is recognise the cell "forced subtitle" command appropriately, grab the subpicture and then render it overlaid. You won't get fanciness, but you will at least get basic forced subtitle support. This is my goal, but I'm very strapped for time at the moment so the delivery won't be quick. If you fancy taking a look as well, you'll probably get there quicker, particularly with your (excellent) work on auto-detecting a distinct forced subtitle stream.
.
Why thanks.

The problem I'm encountering is that I haven't encountered a title that is using these forced subtitles as yet. I'll keep an eye out for one though.

Cheers, Ed.
rhester
Veteran User
Posts: 2888
Joined: Tue Apr 18, 2006 10:24 pm

Post by rhester »

I can't vouch for the "special edition" release, but disc 2 (the "bonus disc") of Star Wars Episode IV: A New Hope is the original 1977 release transferred from laserdisc to DVD and it most definitely uses 'keyed' subtitles. It's been giving me fits. :) The Greedo scene is the easiest to see it happening on.

Rodney
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

eddyg wrote:
Utumno wrote:@eddyg - the cell commands route is the method I am looking at pursuing. I'm hoping that all we need to do is recognise the cell "forced subtitle" command appropriately, grab the subpicture and then render it overlaid. You won't get fanciness, but you will at least get basic forced subtitle support. This is my goal, but I'm very strapped for time at the moment so the delivery won't be quick. If you fancy taking a look as well, you'll probably get there quicker, particularly with your (excellent) work on auto-detecting a distinct forced subtitle stream.
.
Why thanks.

The problem I'm encountering is that I haven't encountered a title that is using these forced subtitles as yet. I'll keep an eye out for one though.

Cheers, Ed.
I have several examples, but then I'm a sucker for a crap action film :) If you have "The Da Vinci Code" or "Die Another Day" then you'll see the problem I think. Both titles use the "standard" English subtitles, switching them on and off according to the "forced" flag. "Da Vinci" is a particularly severe example.

Cheers,

Ut.
Kurtz
Posts: 37
Joined: Wed Feb 21, 2007 6:52 pm

Examples of forced subtitles

Post by Kurtz »

In an attempt to help more forced subtitles examples

the Mummy (1999) seems to have them missed. Although that was a single pass so Im going to try 2 pass and see if that helps.

Mummy returns has them and they show up in handbrake, that was a 2 pass rip (hence reason above), but look as if they were already burned into movie so ill check on the dvd.

Also Stargate the original movie has them missing and that was 2 pass encode. this one really p***es me off.

what's weird is it seems some work and others don't. Somewhat explained by some of the replies already given.

hope that helps and ill keep a look out for more
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Re: Examples of forced subtitles

Post by Utumno »

Kurtz wrote:In an attempt to help more forced subtitles examples

the Mummy (1999) seems to have them missed. Although that was a single pass so Im going to try 2 pass and see if that helps.

Mummy returns has them and they show up in handbrake, that was a 2 pass rip (hence reason above), but look as if they were already burned into movie so ill check on the dvd.

Also Stargate the original movie has them missing and that was 2 pass encode. this one really p***es me off.

what's weird is it seems some work and others don't. Somewhat explained by some of the replies already given.

hope that helps and ill keep a look out for more
The Mummy has a separate discrete forced subtitles track. HandBrake is perfectly capable of embedding these (although you will have to work out which subtitle track is the forced subtitle track manually).

The Mummy Returns has hard-burned faux-subtitles actually burned into the movie video and has no "forced" subtitle track at all.

Of course the mastering may vary by region, and even revision of disk. But this is how my "Mummy"'s are structured.

Cheers,

Ut.

PS : have confirmed that mencoder handles forced subtitles correctly in all my test cases so far (not that many, but enough to make me reasonably confident the approach is worth pursuing. Now to dive back 20 years into my C coding past ... *shudder* :)
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

Utumno wrote:
I have several examples, but then I'm a sucker for a crap action film :) If you have "The Da Vinci Code" or "Die Another Day" then you'll see the problem I think. Both titles use the "standard" English subtitles, switching them on and off according to the "forced" flag. "Da Vinci" is a particularly severe example.
.
I've got the Da Vinci Code, Extended Edition, PAL. I'll rerip that and take a look at the cell commands. I didn't notice a problem with that in the past - but I wouldn't have had the subtitles on :) That I only do for non-English titles, and I guess they haven't been using forced subtitles.

Cheers, Ed.
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

eddyg wrote:
Utumno wrote:
I have several examples, but then I'm a sucker for a crap action film :) If you have "The Da Vinci Code" or "Die Another Day" then you'll see the problem I think. Both titles use the "standard" English subtitles, switching them on and off according to the "forced" flag. "Da Vinci" is a particularly severe example.
.
I've got the Da Vinci Code, Extended Edition, PAL. I'll rerip that and take a look at the cell commands. I didn't notice a problem with that in the past - but I wouldn't have had the subtitles on :) That I only do for non-English titles, and I guess they haven't been using forced subtitles.

Cheers, Ed.
Let me know how you get on Ed. On my DVD version (standard edition, PAL) right at the start of Chapter 2 there's a telephone conversation between Silas and "The Teacher" entirely in French. This is the first major example of the use of forced subtitles in the movie, but a good example of what to expect throughout the movie (because the invisibly forced subtitles drive the plot along). It may be that the Extended Edition has been mastered differently, but hopefully you'll see the same thing.

Ut.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

Utumno wrote: Let me know how you get on Ed. On my DVD version (standard edition, PAL) right at the start of Chapter 2 there's a telephone conversation between Silas and "The Teacher" entirely in French. This is the first major example of the use of forced subtitles in the movie, but a good example of what to expect throughout the movie (because the invisibly forced subtitles drive the plot along). It may be that the Extended Edition has been mastered differently, but hopefully you'll see the same thing.
Ut.
Yes I see - I'd never noticed that the subtitles were missing. I checked for Cell commands and didn't see any. So I'm not sure how it works as yet. However now that I know that it's there in that title I've got something to work with.

Cheers, Ed.
Kurtz
Posts: 37
Joined: Wed Feb 21, 2007 6:52 pm

Post by Kurtz »

Thanks for heads up for mummy films
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

eddyg wrote:
Utumno wrote: Let me know how you get on Ed. On my DVD version (standard edition, PAL) right at the start of Chapter 2 there's a telephone conversation between Silas and "The Teacher" entirely in French. This is the first major example of the use of forced subtitles in the movie, but a good example of what to expect throughout the movie (because the invisibly forced subtitles drive the plot along). It may be that the Extended Edition has been mastered differently, but hopefully you'll see the same thing.
Ut.
Yes I see - I'd never noticed that the subtitles were missing. I checked for Cell commands and didn't see any. So I'm not sure how it works as yet. However now that I know that it's there in that title I've got something to work with.

Cheers, Ed.
Ed, I'm hoping you've delved into subtitles and IFO's a bit more than me. It looks to me as though the forced status is held per-subpicture stream and is in the IFO. As such, it should be available to us through libdvdread somehow though I'm pretty sure it's not exposed to libhb yet.

http://dvd.sourceforge.net/dvdinfo/ifo.html#spatt

Then, inside the "code extension" SPRM :-

http://dvd.sourceforge.net/dvdinfo/sprm.html

Register 2 equalling 63 seems to imply forcing the subpicture. See also register 9. I've not done any hb code investigation yet ... day job getting in the way ... :( and I'm not at all convinced that I've got this approach right.

Hopefully we should just be able to select a standard subtitle stream using the usual HandBrake subtitle selector, then filter rendering that subtitle stream on a per-subpicture basis depending on whether that subpicture is identified as a forced subpicture or not in the IFO. Scanning shouldn't be necessary and it should work equally well on 1 or 2 pass encodes ... and if we're really lucky the addition of a simple toggle ("Render forced only") to the UI and CLI will enable the "forced only" filter or not.

I fully expect to have misunderstood how the IFO works however, I am very new to understanding the intricacies of how DVD's are put together. If you or anyone else has any ideas, thoughts or pointers, I'd welcome them. Meanwhile I'm proceeding with digging into libdvdread to see if this approach might be viable.

Cheers,

Ut.
Kurtz
Posts: 37
Joined: Wed Feb 21, 2007 6:52 pm

oooo

Post by Kurtz »

Hey
I also have limited knowledge of the IFO but from the docs you seem to be onto the right path.

SPRM 19- preferred sub-picture language extension- also has a forced option of 9=forced

not sure if that is more optional and it doesn't say bit0-bit5 which looks important.

so from the look of that it seems 2=63 is the way to go.

but someone will know for sure.
Utumno
Posts: 23
Joined: Fri May 25, 2007 8:53 am

Post by Utumno »

Success. I have the forced subtitle support working and burn-in test cases running overnight. It was surprisingly easy and didn't need 15% of a DVD player writing ;)

At present forced subtitles are "forced on" for a selected subtitle stream (so the current subtitle support is, effectively, broken) but that's just a matter of adding a CLI switch.

I'll add the switch later this week and submit the code to the devs for general derision and potential inclusion in HB.
saintdev
Enlightened
Posts: 146
Joined: Wed Dec 20, 2006 4:17 am

Post by saintdev »

Utumno wrote:Success. I have the forced subtitle support working and burn-in test cases running overnight. It was surprisingly easy and didn't need 15% of a DVD player writing ;)

At present forced subtitles are "forced on" for a selected subtitle stream (so the current subtitle support is, effectively, broken) but that's just a matter of adding a CLI switch.

I'll add the switch later this week and submit the code to the devs for general derision and potential inclusion in HB.
Yeah, I saw the forced start last night when I was looking through the dvd info. Was wondering if that had something to do with it. It appears it does. Great job!!


Now I just need to get to work on non-burned subtitles for Matroska :)
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

Utumno wrote:Success. I have the forced subtitle support working and burn-in test cases running overnight. It was surprisingly easy and didn't need 15% of a DVD player writing ;)

At present forced subtitles are "forced on" for a selected subtitle stream (so the current subtitle support is, effectively, broken) but that's just a matter of adding a CLI switch.

I'll add the switch later this week and submit the code to the devs for general derision and potential inclusion in HB.
Well done!

So I assume it had nothing to do with Cell commands, but instead were some bits in the sub-pictures themselves that said whether that sub-picture was to be forced or not?

Cheers, Ed.
Post Reply