[Committed] PGS 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.

*******************************
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

[Committed] PGS Subtitles

Post by izgood »

This patch adds PGS subtitles (most bluray) to HandBrake : http://paste.handbrake.fr/pastebin.php?show=3122

It currently only works on Mac since I don't have linux or windows. I would need some help to make it work on those platforms.
Also the code only works for burned in subs. Since PGS are graphics we can only burn the image...

The code basically converts PGS subs bitmap data to HandBrake's internal format for subtitles.

It does not currently support multiple subtitle rectangle within the same frame since the last subtitle rectangle replaces the previous one (with out->stop = -1)

I tested it using makemkv to generate the source mkv.

This is my first hb patch so be gentle ;-)
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

Re: PGS Subtitles

Post by izgood »

I forgot to mention that I use ffmpeg to decode the subtitle data.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

Is this the same patch as this pull request for my github?
https://github.com/jstebbins/HandBrake/pull/1

If so, I haven't forgotten about it. It's getting closer to the top of my list now that the filter pipeline changes are committed.
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

Re: PGS Subtitles

Post by izgood »

Not the same. Duplicate work I guess...
I noticed though that the code didn't tag the stop time of the subtitles to -1. I had to do that in order to get the subtitles to disappear correctly.
Also I don't have the code to Correctly detect whether a subtitle supports alpha.
Anyway good to see it's in the pipeline.
rzm2357
Posts: 3
Joined: Wed Dec 28, 2011 4:21 am

Re: PGS Subtitles

Post by rzm2357 »

Just added a new pull request on github to add PGSSUB burn-in support to the CLI.
rzm2357
Posts: 3
Joined: Wed Dec 28, 2011 4:21 am

Re: PGS Subtitles

Post by rzm2357 »

I think I also figured out how to properly pass through PGSSUBs to .mkv files as well. Pull request updated.
R6acer
Posts: 4
Joined: Thu Mar 22, 2012 2:33 pm

Re: PGS Subtitles

Post by R6acer »

This sounds like you are heading in the right direction can't wait for the windows version to get PSG support
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

I should have time this weekend to review this. If all looks good (or close enough that I can easily fix it) it may get into a nightly build by Monday.
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

Re: PGS Subtitles

Post by izgood »

Just a heads up, I had to add a timeout for subtitles in avatar. The problem is that avatar subs don't send out an empty sub command to clear the display (for the navi subs at least).
So I hardcoded a 6 seconds timeout in sync.c :

Code: Select all

Index: sync.c
===================================================================
--- sync.c	(revision 4505)
+++ sync.c	(working copy)
@@ -642,6 +642,15 @@
                 {
                     sub->stop = sub->next->start;
                 }
+                else if ( !sub->next && sub->stop == -1)
+                {
+                    int64_t cur_sub_dur = cur->start - sub->start;
+                    if(cur_sub_dur > (6 * 90000))
+                    {
+                        hb_log( "subtitle timeout" );
+                        sub->stop = cur->start;
+                    }
+                }
 
                 // Need to re-write subtitle timestamps to account
                 // for any slippage.
If you don't do that the sub stays there untill the next one comes along, which could be a long time.
On VLC they have the same problem but they just clear after the 20s timeout that ffmpeg puts in there.
Deleted User 11865

Re: PGS Subtitles

Post by Deleted User 11865 »

We had something similar for VobSub without stop display commands (set to 3 seconds). I think we should handle PGS the same way we now handle VobSub - i.e. clear the current subtitle packet when a stop display command is found, or when the next subtitle packet comes along. Of course this would have to be tested.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

I had a look at the PGS patch that David Mitchell supplied. It was missing a bunch of stuff. It only detected PGS in sources that we decode with libav. It didn't do anything for PGS in TS files or in BD sources. So I added this, updated some things that needed changing to work with svn head, and checked it into a branch on my github https://github.com/jstebbins/HandBrake/tree/pgs

Unfortunately, this is not ready to go into svn yet. I looked into the problem izgood pointed out, and it turns out that libav's PGS parser totally ignores timestamps and does not process the end segment correctly. I'm amazed it works as well as it does. They also don't expose the "forced" flag, which we really want in order to process foreign audio segments correctly. So this code isn't going to get in till I've had time to write a patch to address these 2 things.

In the mean time, rzm2357, it would be helpful if you could rebase your pull request on this new pgs branch.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

izgood wrote:Just a heads up, I had to add a timeout for subtitles in avatar. The problem is that avatar subs don't send out an empty sub command to clear the display (for the navi subs at least).
So I hardcoded a 6 seconds timeout in sync.c :
*snip*
If you don't do that the sub stays there untill the next one comes along, which could be a long time.
On VLC they have the same problem but they just clear after the 20s timeout that ffmpeg puts in there.
I have a theory I would like to confirm. How did you extract the Navi subtitles from the original BD? I had a look at my copy of this BD and the empty sub commands are all there. But they are not marked as "forced". The Navi subs are combined with a full english subtitle track and are flagged with the forced flag. If you used a tool that only extracts the forced subtitles, it may have skipped these empty subs. If this theory hold up, I think you need to report a "bug" to whoever made the tool you used.
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

Re: PGS Subtitles

Post by izgood »

I used makemkv to rip the BD with all sub tracks selected. Which tool do you use?
Did you use the 2nd english track (navi subs only) ? I don't want the english subs, just the navi ones.
On VLC when I select the first english sub track the subs go away on their own but the problem persists if I choose the second english subtitle track.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

Ah, I'm using the first (and only) english subtitle track on my version. My copy of avatar has 4 tracks, the other 3 are alternate languages. I use AnyDVD. The only english track has subs for everything, but the navi subs are marked as forced, so they can be selectively displayed without the rest of the english subs. I think makemkv is playing tricks on you. I don't think there *is* a "second navi subs only" track. My guess is MakeMkv recognized that there are forced subs in the first track and gave them to you as a separate track option. And I'll bet their extraction process for the forced subs is flawed.

I've updated my git PGS branch with a patch to libav to fix their timestamp handling and add support for the forced subs flag. Then I added support for using the forced flag and doing foreign audio search with PGS to HB.
https://github.com/jstebbins/HandBrake/ ... ef97228528
nightstrm
Veteran User
Posts: 1887
Joined: Fri Mar 23, 2007 5:43 am

Re: PGS Subtitles

Post by nightstrm »

Great development, will begin re-ripping the BR discs from my collection with forced PGS subtitles so I'll have a number of sources ready for testing. =)
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

PGS passthru to mkv and some corrections to color conversions
https://github.com/jstebbins/HandBrake/commits/pgs
izgood
Posts: 8
Joined: Sun Apr 01, 2012 12:14 pm

Re: PGS Subtitles

Post by izgood »

Tested the latest code and it works. I used the first english sub track which has both english and navi. The navi subs are marked as forced.
I also tested on Star Wars episode I but I don't think they use the forced subtitles but instead have a separate track for alien subs. At least the first track didn't produce any subs (when burning in forced only).
Are there tools out there to scan PGS subtitles for forced subs ?
Deleted User 11865

Re: PGS Subtitles

Post by Deleted User 11865 »

izgood wrote:Are there tools out there to scan PGS subtitles for forced subs ?
HandBrake, via Foreign Audio Search + Forced only. Though it won't work for all Star Wars BD discs - there are multiple English subtitle tracks with forced subs, and Foreign Audio Search picks the first one, which isn't always the one with the alien dialogue.
RoverTX
Novice
Posts: 57
Joined: Sun Oct 18, 2009 9:41 pm

Re: PGS Subtitles

Post by RoverTX »

What is the time frame for this getting into the nightly? Or is it far enough down the pipeline that I should go and compile from github, and finally upgrade to the new Xcode?
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

It's getting fairly close. We've transitioned to review board for the final reviewing and tweaking. Some of HandBrake's developers are still adjusting to using git, so this makes it more accessible for them. :mrgreen:
https://reviews.handbrake.fr/r/290/

There's a known bug in the most recent patch with foreign audio search combined with burned subs. I'll fix it this evening, then if nothing else turns up, this might get committed right after the fix.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

Committed https://trac.handbrake.fr/changeset/4605
Grab the next nightly build!
firewing1
Posts: 21
Joined: Sat May 23, 2009 8:18 pm

Re: PGS Subtitles

Post by firewing1 »

This is awesome, thanks to everyone involved in making it happen.

I'm rebuilding HB from SVN since I want to try this out asap :P
firewing1
Posts: 21
Joined: Sat May 23, 2009 8:18 pm

Re: PGS Subtitles

Post by firewing1 »

Now that this is committed, let me know if I should move this discussion to a separate thread.

I tested this last night and detection of the PGS subtitle tracks as well as burned-in subtitles worked perfectly, but I wasn't able to get a non-burned subtitle track to work. I don't know if HB or VLC/QuickTime X is to blame, but after doing a transcode with a PGS subtitle track added (forced only: no, burned in: no, default: yes) neither VLC nor QT X detects any subtitle tracks. On the other hand, I examined the output file with MP4Box and it does list a third (albeit disabled) text track.

What would be the next step to troubleshoot this?
User avatar
s55
HandBrake Team
Posts: 10350
Joined: Sun Dec 24, 2006 1:05 pm

Re: PGS Subtitles

Post by s55 »

I don't think passthru pgs to mp4 is supported (although the UI's probably still waiting for updates to prevent that and other things). It's burn-in only. I could be wrong, and I'm sure rodeo will correct me if I am, but I don't think it's supported by the mp4 spec.

Passthru should work with mkv though.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: PGS Subtitles

Post by JohnAStebbins »

PGS is not suported in mp4 files. The mp4 spec doesn't include it as far as i know. HB only supports soft pgs subs in mkv.
Post Reply