diff options
author | Clément Bœsch <u@pkh.me> | 2015-02-08 12:38:06 +0100 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2015-05-14 12:11:34 +0200 |
commit | 5c219e289e7f3a7e369f692053bd0c1d35937a33 (patch) | |
tree | 2db3235c1a13db45fa73d2b8ec560eedf3ed2814 /libavcodec | |
parent | 56bc0a6736cdc7edab837ff8f304661fd16de0e4 (diff) | |
download | ffmpeg-5c219e289e7f3a7e369f692053bd0c1d35937a33.tar.gz |
avcodec/srtdec: attempt to correct SubRip positioning
The positioning was completely wrong. First, the coordinates are
expressed in ASS playback resolution (which is by default 384x288).
Secondly, the coordinates define a drawing rectangle, not a moving area.
The previous code was making subtitles move from a random position to
another random position.
Here we rescale assuming the video resolution is a DVD one (720x480). We
can't really do anything better so far, but since this positioning
information is often from a DVD rip we can consider them relatively
safe.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/srtdec.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index a2e62271c8..ed3af95063 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -66,10 +66,22 @@ static void srt_to_ass(AVCodecContext *avctx, AVBPrint *dst, strcpy(stack[0].param[PARAM_FACE], "{\\fn}"); if (x1 >= 0 && y1 >= 0) { - if (x2 >= 0 && y2 >= 0 && (x2 != x1 || y2 != y1)) - av_bprintf(dst, "{\\an1}{\\move(%d,%d,%d,%d)}", x1, y1, x2, y2); - else - av_bprintf(dst, "{\\an1}{\\pos(%d,%d)}", x1, y1); + /* XXX: here we rescale coordinate assuming they are in DVD resolution + * (720x480) since we don't have anything better */ + + if (x2 >= 0 && y2 >= 0 && (x2 != x1 || y2 != y1) && x2 >= x1 && y2 >= y1) { + /* text rectangle defined, write the text at the center of the rectangle */ + const int cx = x1 + (x2 - x1)/2; + const int cy = y1 + (y2 - y1)/2; + const int scaled_x = cx * ASS_DEFAULT_PLAYRESX / 720; + const int scaled_y = cy * ASS_DEFAULT_PLAYRESY / 480; + av_bprintf(dst, "{\\an5}{\\pos(%d,%d)}", scaled_x, scaled_y); + } else { + /* only the top left corner, assume the text starts in that corner */ + const int scaled_x = x1 * ASS_DEFAULT_PLAYRESX / 720; + const int scaled_y = y1 * ASS_DEFAULT_PLAYRESY / 480; + av_bprintf(dst, "{\\an1}{\\pos(%d,%d)}", scaled_x, scaled_y); + } } for (; !end && *in; in++) { |