From 5e2c211a4e1d67748348295b191acb2dfb76d024 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Jun 2013 20:34:20 +0200 Subject: sd_lavc_conv: strip style header Normally, libavcodec subtitle converters will output a style header like this as part of the extradata: Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,1,1,0,2,10,10,10,0,0 We don't want that, so use some bruteforce to get rid of them. --- sub/sd_lavc_conv.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sub') diff --git a/sub/sd_lavc_conv.c b/sub/sd_lavc_conv.c index 744aa83440..9c7a6f2c5f 100644 --- a/sub/sd_lavc_conv.c +++ b/sub/sd_lavc_conv.c @@ -27,6 +27,7 @@ #include "talloc.h" #include "core/mp_msg.h" #include "core/av_common.h" +#include "core/bstr.h" #include "sd.h" struct sd_lavc_priv { @@ -55,6 +56,19 @@ static bool supports_format(const char *format) #endif } +// Disable style definitions generated by the libavcodec converter. +// We always want the user defined style instead. +static void disable_styles(bstr header) +{ + while (header.len) { + int n = bstr_find(header, bstr0("\nStyle: ")); + if (n < 0) + break; + header.start[n + 1] = '#'; // turn into a comment + header = bstr_cut(header, 2); + } +} + static int init(struct sd *sd) { struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv); @@ -76,6 +90,11 @@ static int init(struct sd *sd) sd->output_codec = "ass"; sd->output_extradata = avctx->subtitle_header; sd->output_extradata_len = avctx->subtitle_header_size; + if (sd->output_extradata) { + sd->output_extradata = talloc_memdup(sd, sd->output_extradata, + sd->output_extradata_len); + disable_styles((bstr){sd->output_extradata, sd->output_extradata_len}); + } return 0; error: -- cgit v1.2.3