Subtitle position

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.

*******************************
Post Reply
haiki
Posts: 4
Joined: Fri Jan 18, 2008 9:56 pm

Subtitle position

Post by haiki » Fri Jan 18, 2008 10:09 pm

Hi,

I'm very new to encoding video, but I'm trying to ready some DVDs to play on an AppleTV, and using the default setting in Handbrake works fine, except I'm not so happy about the positioning of the subtitles for a lot of movies. I've taken a snapshot of an example: <http://img.skitch.com/20080118-j7hyas7d ... uk116m.png>. Is there a setting I can change to place the subtitles towards the bottom of the screen/picture?

Cheers,
Nils

royone
Regular User
Posts: 124
Joined: Thu Sep 06, 2007 6:06 pm

Re: Subtitle position

Post by royone » Fri Jan 18, 2008 11:06 pm

What I do is set the cropping for the bottom of the frame to zero, and all the other crop sides are as autocrop suggests. Then I have some space at the bottom, and the subtitles show up a bit lower.

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

Re: Subtitle position

Post by jbrjake » Fri Jan 18, 2008 11:20 pm

Cyander had some code to reposition them but I don't know what happened, he never submitted it if I recall correctly.

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

Re: Subtitle position

Post by eddyg » Sun Jan 20, 2008 8:44 pm

Here is the previous thread on this, and the code was never submitted.

http://forum.handbrake.fr/viewtopic.php ... tion#p3405

As Cyander says the change is actually rather easy, we just have to decide what that change should be.

Here is the code from render.c:

Code: Select all

   /* If necessary, move the subtitle so it is not in a cropped zone.
       When it won't fit, we center it so we loose as much on both ends.
       Otherwise we try to leave a 20px margin around it. */

    if( sub->height > title->height - job->crop[0] - job->crop[1] - 40 )
        offset_top = job->crop[0] + ( title->height - job->crop[0] -
                job->crop[1] - sub->height ) / 2;
    else if( sub->y < job->crop[0] + 20 )
        offset_top = job->crop[0] + 20;
    else if( sub->y > title->height - job->crop[1] - 20 - sub->height )
        offset_top = title->height - job->crop[1] - 20 - sub->height;
    else
        offset_top = sub->y;

    if( sub->width > title->width - job->crop[2] - job->crop[3] - 40 )
        offset_left = job->crop[2] + ( title->width - job->crop[2] -
                job->crop[3] - sub->width ) / 2;
    else if( sub->x < job->crop[2] + 20 )
        offset_left = job->crop[2] + 20;
    else if( sub->x > title->width - job->crop[3] - 20 - sub->width )
        offset_left = title->width - job->crop[3] - 20 - sub->width;
    else
        offset_left = sub->x;
It is using a fixed 20pxl offset. I believe that what Cyander implemented was a percentage based offset to keep the bottom of the subtitles as close as possible to the bottom but without entering a possible overscan exclusion zone.

So how about changing the above code to 2% or 20pxl whichever is lower?

Cheers, Ed.

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

Re: Subtitle position

Post by eddyg » Sun Jan 20, 2008 10:50 pm

Here is what it looks like at 2% margin or 20px whichever is lowest.

Image

Using the following code changes:

Code: Select all

Index: render.c
===================================================================
--- render.c	(revision 1215)
+++ render.c	(working copy)
@@ -65,7 +65,7 @@
 {
     hb_buffer_t * sub = *_sub;
     hb_title_t * title = job->title;
-    int i, j, offset_top, offset_left;
+    int i, j, offset_top, offset_left, margin_top;
     uint8_t * lum, * alpha, * out, * sub_chromaU, * sub_chromaV;
 
     if( !sub )
@@ -73,19 +73,54 @@
         return;
     }
 
-    /* If necessary, move the subtitle so it is not in a cropped zone.
-       When it won't fit, we center it so we loose as much on both ends.
-       Otherwise we try to leave a 20px margin around it. */
+    
+    /* 
+     * If necessary, move the subtitle so it is not in a cropped zone.
+     * When it won't fit, we center it so we lose as much on both ends.
+     * Otherwise we try to leave a 20px or 2% margin around it. 
+     */
 
-    if( sub->height > title->height - job->crop[0] - job->crop[1] - 40 )
+    margin_top = ( ( title->height - job->crop[0] - job->crop[1] ) * 2 ) / 100;
+
+    if( margin_top > 20 )
+    {
+        margin_top = 20;
+    }
+
+    if( sub->height > title->height - job->crop[0] - job->crop[1] - 
+        ( margin_top * 2 ) )
+    {
+        /*
+         * The subtitle won't fit in the cropped zone, so center
+         * it vertically so we fit in as much as we can.
+         */
         offset_top = job->crop[0] + ( title->height - job->crop[0] -
-                job->crop[1] - sub->height ) / 2;
-    else if( sub->y < job->crop[0] + 20 )
-        offset_top = job->crop[0] + 20;
-    else if( sub->y > title->height - job->crop[1] - 20 - sub->height )
-        offset_top = title->height - job->crop[1] - 20 - sub->height;
+                                      job->crop[1] - sub->height ) / 2;
+    }
+    else if( sub->y < job->crop[0] + margin_top )
+    {
+        /*
+         * The subtitle fits in the cropped zone, but is currently positioned
+         * within our margin, so move it outside of our margin.
+         */
+        offset_top = job->crop[0] + margin_top;
+    }
+    else if( sub->y > title->height - job->crop[1] - margin_top - sub->height )
+    {
+        /*
+         * The subtitle fits in the cropped zone, and is not within the top
+         * margin but is within the bottom margin, so move it to be within
+         * the margin.
+         */
+        offset_top = title->height - job->crop[1] - margin_top - sub->height;
+    }
     else
+    {
+        /*
+         * The subtitle is fine where it is.
+         */
         offset_top = sub->y;
+    }
 
     if( sub->width > title->width - job->crop[2] - job->crop[3] - 40 )
         offset_left = job->crop[2] + ( title->width - job->crop[2] -

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

Re: Subtitle position

Post by eddyg » Mon Jan 21, 2008 3:29 am

So is 2% too close to the edge? Maybe it should be 3%?

Any preferences?

It's easy to change should we wish, and also to feed in jbrjakes excellent idea of presenting the subtitles in the preview window and allowing repositioning of the subtitle if required.

haiki
Posts: 4
Joined: Fri Jan 18, 2008 9:56 pm

Re: Subtitle position

Post by haiki » Mon Jan 21, 2008 1:47 pm

Presumably you're not asking me, but since it was me starting the thread, I'd like to say it's encouraging to see someone is looking at it. I'm sure subtitles is both relevant and important for a lot of people. The 2% looks perfect to me; I'm from a "subtitling" country, and at that position is where I'm used to see them!

Nils

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

Re: Subtitle position

Post by eddyg » Mon Jan 21, 2008 8:55 pm

haiki wrote:Presumably you're not asking me, but since it was me starting the thread, I'd like to say it's encouraging to see someone is looking at it. I'm sure subtitles is both relevant and important for a lot of people. The 2% looks perfect to me; I'm from a "subtitling" country, and at that position is where I'm used to see them!

Nils
Actually that is very useful input to know that it is pretty much where you expect to see it. I'll go with 2% then.

Cheers, Ed.

haiki
Posts: 4
Joined: Fri Jan 18, 2008 9:56 pm

Re: Subtitle position

Post by haiki » Wed Feb 20, 2008 10:07 am

Hey there,
I was very pleased to see this: "35 - Better subtitle positioning" in the list of changes for version 0.92. Having said that, I can't see much difference in the postition of the subtitles. I'm using the default settings for AppleTV (although I change the sound to AAC only, since my "surround" system consists of two speakers ;)). So I end up with a result like this:
Image
This is the same position the DVD player put the subtitles.
Is there a setting I need to change? Otherwise the release looks great! :)

Cheers,
Nils

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

Re: Subtitle position

Post by jbrjake » Wed Feb 20, 2008 3:28 pm

Hrm...I included that in the changeset because of eddyg's http://trac.handbrake.fr/changeset/1218 :
"Change subtitle position to prevent displaying within a 2% margin of the height of the screen, rather than using a 20px fixed margin."

Not exactly what you were hoping for?

haiki
Posts: 4
Joined: Fri Jan 18, 2008 9:56 pm

Re: Subtitle position

Post by haiki » Wed Feb 20, 2008 3:42 pm

well, maybe I misunderstood where eddyg was taking this, but it was my understanding that the new position would be pushed down to the bottom of the picture. So was the change to prevent it displaying too far down? Oh well, it's still watchable :)

Cheers,
Nils

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

Re: Subtitle position

Post by eddyg » Wed Feb 20, 2008 7:15 pm

The subtitle is moved only if it was within or close to a cropping region, otherwise it stays where the DVD authors instructed it to be. If it is within the cropping region I have moved it to be within 2-3% of the border of the screen, rather than a fixed 20px margin. This works better on small screens like iPods.

This will not affect films that are 16x9 already.

Cheers, Ed.

Cyander
Regular User
Posts: 94
Joined: Tue Mar 20, 2007 9:19 pm

Re: Subtitle position

Post by Cyander » Sat Feb 23, 2008 10:07 pm

The reason I didn't submit the code is that it wasn't finished, and honestly, posting it now without changing a lot of it would be pretty worthless due to all the changes to subtitles since I last worked on it. :)

There are a couple reasons why the code I wrote might not be a great addition as-is either. It forces it to move, which is not ideal in all cases. Some subtitles are positioned with the intention of overlaying themselves on top of text to be translated.

Oh, and I wanted to get around to some subtitle scaling code that I never did.

Depending on how the rest of my life treats me in this next week, I might take a second look at some subtitle position/size tweaking.

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

Re: Subtitle position

Post by eddyg » Sun Feb 24, 2008 8:49 pm

Cyander wrote:The reason I didn't submit the code is that it wasn't finished, and honestly, posting it now without changing a lot of it would be pretty worthless due to all the changes to subtitles since I last worked on it. :)

There are a couple reasons why the code I wrote might not be a great addition as-is either. It forces it to move, which is not ideal in all cases. Some subtitles are positioned with the intention of overlaying themselves on top of text to be translated.
This is why I didn't force the move unless the subtitle was within a threshold of our cropping zone. In which case it had to be moved. All I changed was the amount it was moved by to be in relation to the screen resolution rather than fixed.

I found that it was not a good idea to arbitrarily move the position of the subtitles as I encountered a number of occasions where the DVD author had deliberately positioned the subtitles in particular unusual positions, such as at the top of the screen, or to the left or right out of the way of something else on the screen.

Admittedly I also encountered some occasions where the DVD author for some unknown reason put the subtitles too high (for me), however it's hard to deduce their reasoning for that, and is too hard to auto-correct.

Cheers, Ed.

Post Reply