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.
This commit is contained in:
wm4 2013-06-02 20:34:20 +02:00
parent d5520d20b2
commit 5e2c211a4e
1 changed files with 19 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "talloc.h" #include "talloc.h"
#include "core/mp_msg.h" #include "core/mp_msg.h"
#include "core/av_common.h" #include "core/av_common.h"
#include "core/bstr.h"
#include "sd.h" #include "sd.h"
struct sd_lavc_priv { struct sd_lavc_priv {
@ -55,6 +56,19 @@ static bool supports_format(const char *format)
#endif #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) static int init(struct sd *sd)
{ {
struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv); 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_codec = "ass";
sd->output_extradata = avctx->subtitle_header; sd->output_extradata = avctx->subtitle_header;
sd->output_extradata_len = avctx->subtitle_header_size; 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; return 0;
error: error: