mirror of https://github.com/mpv-player/mpv
sd_ass: handle libavformat ASS comment packets as well
Currently, we are filtering libavformat style ASS packets by checking whether they are prefixed "Dialogue: ". Unfortunately, comment packets are demuxed too. These start with "Comment: ", so they are not caught. Change the filtering, and use the codec ID instead. libavformat uses "ssa" as codec ID for ASS subtitles, while mpv uses "ass". Also, at least FFmpeg will change the ASS packet format to the same format mpv and Matroska use, and identify these with "ass" as codec ID, so this is works out nicely.
This commit is contained in:
parent
bd45eb468c
commit
1058d80a5e
30
sub/sd_ass.c
30
sub/sd_ass.c
|
@ -41,17 +41,14 @@ struct sd_ass_priv {
|
||||||
char last_text[500];
|
char last_text[500];
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool is_native_ass(const char *t)
|
|
||||||
{
|
|
||||||
return strcmp(t, "ass") == 0 || strcmp(t, "ssa") == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool supports_format(const char *format)
|
static bool supports_format(const char *format)
|
||||||
{
|
{
|
||||||
// ass-text is produced by converters and the subreader.c ssa parser; this
|
// ass-text is produced by converters and the subreader.c ssa parser; this
|
||||||
// format has ASS tags, but doesn't start with any prelude, nor does it
|
// format has ASS tags, but doesn't start with any prelude, nor does it
|
||||||
// have extradata.
|
// have extradata.
|
||||||
return format && (is_native_ass(format) || strcmp(format, "ass-text") == 0);
|
return format && (strcmp(format, "ass") == 0 ||
|
||||||
|
strcmp(format, "ssa") == 0 ||
|
||||||
|
strcmp(format, "ass-text") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_last_event(ASS_Track *track)
|
static void free_last_event(ASS_Track *track)
|
||||||
|
@ -64,7 +61,7 @@ static void free_last_event(ASS_Track *track)
|
||||||
static int init(struct sd *sd)
|
static int init(struct sd *sd)
|
||||||
{
|
{
|
||||||
struct MPOpts *opts = sd->opts;
|
struct MPOpts *opts = sd->opts;
|
||||||
if (!sd->ass_library || !sd->ass_renderer)
|
if (!sd->ass_library || !sd->ass_renderer || !sd->codec)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
bool is_converted = sd->converted_from != NULL;
|
bool is_converted = sd->converted_from != NULL;
|
||||||
|
@ -99,16 +96,15 @@ static void decode(struct sd *sd, struct demux_packet *packet)
|
||||||
unsigned char *text = data;
|
unsigned char *text = data;
|
||||||
struct sd_ass_priv *ctx = sd->priv;
|
struct sd_ass_priv *ctx = sd->priv;
|
||||||
ASS_Track *track = ctx->ass_track;
|
ASS_Track *track = ctx->ass_track;
|
||||||
if (is_native_ass(sd->codec)) {
|
if (strcmp(sd->codec, "ass") == 0) {
|
||||||
if (bstr_startswith0((bstr){data, data_len}, "Dialogue: ")) {
|
ass_process_chunk(track, data, data_len,
|
||||||
// broken ffmpeg ASS packet format
|
(long long)(pts*1000 + 0.5),
|
||||||
ctx->flush_on_seek = true;
|
(long long)(duration*1000 + 0.5));
|
||||||
ass_process_data(track, data, data_len);
|
return;
|
||||||
} else {
|
} else if (strcmp(sd->codec, "ssa") == 0) {
|
||||||
ass_process_chunk(track, data, data_len,
|
// broken ffmpeg ASS packet format
|
||||||
(long long)(pts*1000 + 0.5),
|
ctx->flush_on_seek = true;
|
||||||
(long long)(duration*1000 + 0.5));
|
ass_process_data(track, data, data_len);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// plaintext subs
|
// plaintext subs
|
||||||
|
|
|
@ -87,7 +87,7 @@ static int init(struct sd *sd)
|
||||||
avctx->time_base = (AVRational) {1, 1000};
|
avctx->time_base = (AVRational) {1, 1000};
|
||||||
priv->avctx = avctx;
|
priv->avctx = avctx;
|
||||||
sd->priv = priv;
|
sd->priv = priv;
|
||||||
sd->output_codec = "ass";
|
sd->output_codec = "ssa";
|
||||||
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) {
|
if (sd->output_extradata) {
|
||||||
|
|
Loading…
Reference in New Issue