[FFmpeg-devel] [vf_ass.c] 2 lines of code that need your attention

REN Lifeng renlifeng at wowfly.com
Fri Mar 16 03:03:29 CET 2012

Hi developer of the ASS/SSA video filter,

I found 2 places that need your attention.

1. division of int or float

137:    double dar = inlink->w / inlink->h * sar;

Suppose w is 640 h is 272 and sar is 1.0, dar will be 2.0 instead of

2. aspec ratiot of video  v.s. aspect ratio of display

146:    ass_set_aspect_ratio(ass->renderer, dar, sar);

 * \param dar display aspect ratio (DAR), prescaled for output PAR

I has a Karaoke vedio with size of 640x272 and a subtitle in ASS format.
With line 146, there are cases where multiple words changes color
simultaneously. This should not happen. And this problem will not arise
if we play the video and subtitle with Mplayer. And it will not arise if
we remove line 146 from vf_ass.c.

To provide more details, I also the following comparation. With
attatched subtitle, test1 generate 22 images among which only one
Chinese character is split. test2 generate 23 images where 2 characters
are split. You may need some Chinese fonts to reproduce the problem.

The only difference between test1 and test2 is:

diff -u /home/rlf/prog/source/libass-0.10.0/test/test1.c /home/rlf/prog/source/libass-0.10.0/test/test2.c
--- /home/rlf/prog/source/libass-0.10.0/test/test1.c	2012-03-16 09:38:40.285505399 +0800
+++ /home/rlf/prog/source/libass-0.10.0/test/test2.c	2012-03-16 09:37:34.013507495 +0800
@@ -51,6 +51,7 @@
     ass_set_frame_size(ass_renderer, frame_w, frame_h);
     ass_set_fonts(ass_renderer, NULL, NULL, 1, NULL, 1);
+    ass_set_aspect_ratio(ass_renderer, (double)frame_w/frame_h, 1.0);
 static void dump_bitmap(unsigned char *bitmap, int w, int stride, int h, char *name)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test1.c
Type: text/x-csrc
Size: 2926 bytes
Desc: without calling ass_set_aspect_ratio
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120316/cc9178d6/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.c
Type: text/x-csrc
Size: 2996 bytes
Desc: calling ass_set_aspect_ratio
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120316/cc9178d6/attachment-0001.bin>
-------------- next part --------------
[Script Info]
; Script generated by Aegisub 2.1.9
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
PlayResX: 640
PlayResY: 480
ScaledBorderAndShadow: yes
Audio File: 001.mp3
Video Aspect Ratio: 0
Video Zoom: 16
Video Position: 312
Video File: 001.mpg

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,60,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1

Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.63,0:00:04.44,Default,,0000,0000,0000,,{\K36}?{\K30}?{\K99}?{\K60}{\K29}?{\K24}?{\K28}?{\K75}?
Dialogue: 0,0:00:05.58,0:00:09.43,Default,,0000,0000,0000,,{\K30}?{\K34}?{\K103}?{\K22}?{\K26}?{\K43}?{\K32}?{\K31}?{\K64}?
-------------- next part --------------

REN Lifeng

More information about the ffmpeg-devel mailing list