[FFmpeg-devel] [PATCH] Fix colors for DVD subtitles

Alexandre Colucci alexandre at elgato.com
Wed Apr 27 12:31:14 CEST 2011


On 26 avr. 2011, at 22:08, Reimar Döffinger wrote:

> On Tue, Apr 26, 2011 at 09:20:50PM +0200, Alexandre Colucci wrote:
>> As per the DVD specifications and the DVD implementation guidelines, the alpha values are meant to be in increasing order for the 4 color indexes. In particular see section 5.4.3 Allocation of pixel data:
>> 
>> 00 - Background pixel
>> 01 - Pattern pixel
>> 10 - Emphasis pixel-1
>> 11 - Emphasis pixel-2
>> 
>> All commercial DVDs adhere to this. The way this was meant by the DVD committee was to allow implementors to choose any index values in the 0-15 range in *ascending* order.
> 
> I am not exactly convinced, I have seen this guess_palette algorithm
> both work an fail, if all adhered to this it should fail for
> all cases with more than one non-transparent colour.
> 
>> Just compare the attached screenshots attached to the patch, they speak for themselves. The screenshots are from Con Air btw, not from some handmade source.
> 
> I don't doubt that it works for your case, I just don't believe it
> works for all (even just all commercial) DVDs.


I haven't seen it not working ever but I am addressing that issue in the attached new patch.


> There is also the issue that for e.g. a opaque colors you change
> the brightness levels from 0.5 and 1 to 0 and 1 which I don't
> think is correct for DVDs that use them only for alpha-blending,
> which is a quite common use.


The correct way is to use the full range 0 to 1, that is what VLC does too. That way the text is most readable due to maximum contrast. Just consider white text on a gray background for simplicity where you have to choose two colors, your code chooses gray and white whereas using the full range chooses black and white.


> What do you think about attached patch? It uses a table that makes
> it less confusing/obfuscated which values are picked and also tries
> to guess which way to order them.


I think it is much better than the original code. However it has the following problems:
- it only cares about strictly ascending or descending alpha orders and fails with anything else.
- not using the full range I already mentioned
- it never gets the subtitle_color correctly even for the highest alpha due to the multiply by 255 then divide by 256 bug.


> 
>> That said, the correct way is really not "guessing" but really using the actual color table in the PGC, see 4.3 Program Chain Information (7) PGC_SP_PLT in the DVD specifications. That is what VLC does and that is why they do not use this code (one of the reasons to be more precise), the guessing is really just a crutch for standalone vob files.
> 
> You're really supposed to use .idx files for standalone subs that
> contain the proper palette and more stuff.
> However I can't imagine VLC does not have similar guessing code, at
> least MPlayer does.
> <dvdsub.diff>_______________________________________________

Attached is a new patch that fixes all that we talked about, hope you'll like it.
Also attached is a simple C program that prints out the guessed palette for a set of unordered alpha values, just replace the alphas with any test values you like.

Alexandre

-------------- next part --------------
A non-text attachment was scrubbed...
Name: colors.c
Type: application/octet-stream
Size: 1463 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110427/315af1b2/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submission.diff
Type: application/octet-stream
Size: 2809 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110427/315af1b2/attachment-0001.obj>
-------------- next part --------------



More information about the ffmpeg-devel mailing list