[FFmpeg-cvslog] avcodec/dvdsubenc: Add dvdsub workaround for some players

Oliver Fromme git at videolan.org
Wed Jul 9 20:19:48 CEST 2014


ffmpeg | branch: master | Oliver Fromme <oliver at fromme.com> | Wed Jul  9 18:43:58 2014 +0200| [a32dcaaaf809b63d9cffd61fa4a2d2c1976727ce] | committer: Michael Niedermayer

avcodec/dvdsubenc: Add dvdsub workaround for some players

The issue affects dvdsub subtitles (a.k.a. VOBSUB).

Some players -- in particular hardware players -- cut off
the lowest row of pixels if the number of rows in the subtitle
is odd.

The patch below implements a work-around for that.  If the
number of rows is odd, it is simply rounded up to an even
number, adding an invisible (i.e. fully transparent) row.
The work-around can be enabled or disabled with a new
option -even_rows_fix.  The default is disabled, so there
is no change of behaviour for users who don't care about it.

The overhead for the fix is low, and in many cases even zero:
For subtitles with an odd number of rows (i.e. in 50% of
cases on average), the size increases by two bytes because
a fully transparent row is encoded as 0x00 0x00.  However,
in the VOBSUB standard, all data packets are padded to 2KB
anyway, so in most cases the additional bytes just use some
part of the padding, so there is no overhead.  Only in the
rare case that the 2KB boundary is hit (0.1% chance), a full
2KB block is added.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a32dcaaaf809b63d9cffd61fa4a2d2c1976727ce
---

 libavcodec/dvdsubenc.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index d19d071..ced09dd 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -24,9 +24,12 @@
 #include "libavutil/avassert.h"
 #include "libavutil/bprint.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
 
 typedef struct {
+    AVClass *class;
     uint32_t global_palette[16];
+    int even_rows_fix;
 } DVDSubtitleContext;
 
 // ncnt is the nibble counter
@@ -345,6 +348,13 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
     dvd_encode_rle(&q, vrect.pict.data[0] + vrect.w, vrect.w * 2,
                    vrect.w, vrect.h >> 1, cmap);
 
+    if (dvdc->even_rows_fix && (vrect.h & 1)) {
+        // Work-around for some players that want the height to be even.
+        vrect.h++;
+        *q++ = 0x00; // 0x00 0x00 == empty row, i.e. fully transparent
+        *q++ = 0x00;
+    }
+
     // set data packet size
     qq = outbuf + 2;
     bytestream_put_be16(&qq, q - outbuf);
@@ -439,6 +449,20 @@ static int dvdsub_encode(AVCodecContext *avctx,
     return ret;
 }
 
+#define OFFSET(x) offsetof(DVDSubtitleContext, x)
+#define SE AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    {"even_rows_fix", "Make number of rows even (workaround for some players)", OFFSET(even_rows_fix), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SE},
+    { NULL },
+};
+
+static const AVClass dvdsubenc_class = {
+    .class_name = "VOBSUB subtitle encoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_dvdsub_encoder = {
     .name           = "dvdsub",
     .long_name      = NULL_IF_CONFIG_SMALL("DVD subtitles"),
@@ -446,5 +470,6 @@ AVCodec ff_dvdsub_encoder = {
     .id             = AV_CODEC_ID_DVD_SUBTITLE,
     .init           = dvdsub_init,
     .encode_sub     = dvdsub_encode,
+    .priv_class     = &dvdsubenc_class,
     .priv_data_size = sizeof(DVDSubtitleContext),
 };



More information about the ffmpeg-cvslog mailing list