[FFmpeg-devel] Status of dvdsub "forced_subs_only" patch

Nicholas Robbins nickrobbins at yahoo.com
Tue Sep 16 19:31:39 CEST 2014

Ok, I seem to have a partial solution.

I thought that the place to put this would be in the dvdsubenc.c. So I made the following changes (sorry for inline patch)

diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index 425f0af..7cae3f4 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -30,6 +30,7 @@ typedef struct {
     AVClass *class;
     uint32_t global_palette[16];
     int even_rows_fix;
+    int only_enc_forced;
} DVDSubtitleContext;

// ncnt is the nibble counter
@@ -277,6 +278,9 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
             forced = 1;
+    if (!forced && dvdc->only_enc_forced)
+       return 0; 
     vrect = *h->rects[0];

     if (rects > 1) {
@@ -453,6 +457,7 @@ static int dvdsub_encode(AVCodecContext *avctx,
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},
+    {"only_enc_forced", "Only encode forced subtitles", OFFSET(only_enc_forced), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, SE},
     { NULL },

Ok, with this change, ffmpeg compiles fine. To do my testing, I have a file called subs.mkv that just has two subtitle tracks. Both tracks have about 1000 subtitles. Track 0 has 46 forced subtitles, and track 1 has zero. 

The commands I am using are 

ffmpeg -i subs.mkv -map 0 -c:s dvdsub -only_enc_forced 1 only.mkv

This produces a smaller file. (from 7.9M to 240K)

If I pull out the subs & idx's using  

mkvextract tracks rec.mkv 0:subs-0.sub 1:subs-1.sub produces strange results. The idx's are the same size (49K & 61K) as the original idx's, but the .sub files are smaller (2.3M & 2.8M from 4.9M and 5.5M)

However, something isn't right. If I try to open these new sub/idx's in BDsup2sub I get: "ERROR: Invalid control buffer size"

However, if I put the only.mkv through ffmpeg again with:

ffmpeg -i only.mkv -map 0 -c:s dvdsub recode.mkv

And then pull the mkv's out with similar mkvextract command, it get the 46 (in 0) and 0 (in 1) subtitles I was expecting.

The file sizes are also saner (idx's 2.2K & 219B, .subs 184K and 0B)

So, it seems like what I am doing produces a mangled dvdsub track, but one that ffmpeg can make sense of. It isn't just some muxing thing since if I run only.mkv through mkvmerge, it doesn't get fixed.

How can I finish this patch?


More information about the ffmpeg-devel mailing list