]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/srtdec.c
Merge commit '149fa0b7ac180fe1df48a2e379c560813555bf57'
[ffmpeg] / libavcodec / srtdec.c
index a2e62271c85dd03c6e8a63aa875171e3ab7ad8a0..ed3af95063b4f7fa46b448efe5321ddf89821215 100644 (file)
@@ -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++) {