subtitles: improve support for libavformat demuxed subtitles

Make demux_lavf not error out if no video or audio track is present.
This allows opening subtitle files with the demuxer.

Improve the test whether subtitles read from demuxers must do explicit
packet reads. (I'm not sure whether always doing these reads could have
bad effects, such as reading too many audio and video packets at once,
so be conservative.)
This commit is contained in:
wm4 2012-11-15 21:09:15 +01:00
parent 589bda26ce
commit f7163c8065
2 changed files with 19 additions and 7 deletions

View File

@ -1675,6 +1675,23 @@ double playing_audio_pts(struct MPContext *mpctx)
return pts - mpctx->opts.playback_speed *ao_get_delay(mpctx->ao);
}
// When reading subtitles from a demuxer, and we don't read video or audio
// from the demuxer, we must explicitly read subtitle packets. (Normally,
// subs are interleaved with video and audio, so we get them automatically.)
static bool is_non_interleaved(struct MPContext *mpctx, struct track *track)
{
if (track->is_external || !track->demuxer)
return true;
struct demuxer *demuxer = track->demuxer;
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
struct track *other = mpctx->current_track[type];
if (other != track && other->demuxer && other->demuxer == demuxer)
return false;
}
return true;
}
static void reset_subtitles(struct MPContext *mpctx)
{
if (mpctx->sh_sub)
@ -1765,7 +1782,7 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl)
spudec_assemble(vo_spudec, packet, len, timestamp);
}
} else if (d_sub && (is_text_sub(type) || (sh_sub && sh_sub->active))) {
bool non_interleaved = track->is_external; // if demuxing subs only
bool non_interleaved = is_non_interleaved(mpctx, track);
if (non_interleaved)
ds_get_next_pts(d_sub);

View File

@ -693,12 +693,7 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
mp_msg(MSGT_HEADER, MSGL_V, "LAVF: build %d\n", LIBAVFORMAT_BUILD);
demuxer->audio->id = -2; // wait for higher-level code to select track
if (!priv->video_streams) {
if (!priv->audio_streams) {
mp_msg(MSGT_HEADER, MSGL_ERR,
"LAVF: no audio or video headers found - broken file?\n");
return NULL;
}
demuxer->video->id = -2; // audio-only
demuxer->video->id = -2; // audio-only / sub-only
}
// disabled because unreliable per-stream bitrate values returned