[FFmpeg-devel] [PATCH 1/2] lavf/subtitles: add ff_subtitles_queue_seek().

Clément Bœsch ubitux at gmail.com
Sat Dec 1 01:17:08 CET 2012


On Fri, Nov 23, 2012 at 09:45:01PM +0100, Clément Bœsch wrote:
> This function is almost identical to lavf/assdec:read_seek2(). It
> performs a generic seek for text subtitles demuxers for the new seeking
> API.
> 
> The seek callback in the ASS demuxer will be removed when it is
> redesigned to use FFDemuxSubtitlesQueue.
> ---
>  libavformat/subtitles.c | 38 ++++++++++++++++++++++++++++++++++++++
>  libavformat/subtitles.h |  7 +++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> index 1204526..3661495 100644
> --- a/libavformat/subtitles.c
> +++ b/libavformat/subtitles.c
> @@ -91,6 +91,44 @@ int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
>      return 0;
>  }
>  
> +int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index,
> +                            int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
> +{
> +    if (flags & AVSEEK_FLAG_BYTE) {
> +        return AVERROR(ENOSYS);
> +    } else if (flags & AVSEEK_FLAG_FRAME) {
> +        if (ts < 0 || ts >= q->nb_subs)
> +            return AVERROR(ERANGE);
> +        q->current_sub_idx = ts;
> +    } else {
> +        int i, idx = -1;
> +        int64_t min_ts_diff = INT64_MAX;
> +        if (stream_index == -1) {
> +            AVRational time_base = s->streams[0]->time_base;
> +            ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base);
> +            min_ts = av_rescale_rnd(min_ts, time_base.den,
> +                                    time_base.num * (int64_t)AV_TIME_BASE,
> +                                    AV_ROUND_UP);
> +            max_ts = av_rescale_rnd(max_ts, time_base.den,
> +                                    time_base.num * (int64_t)AV_TIME_BASE,
> +                                    AV_ROUND_DOWN);
> +        }
> +        /* TODO: q->subs[] is sorted by pts so we could do a binary search */
> +        for (i = 0; i < q->nb_subs; i++) {
> +            int64_t pts = q->subs[i].pts;
> +            int64_t ts_diff = FFABS(pts - ts);

This is changed to uint64_t locally. I'll push the 2 patches of this
patchset soon, along with the 3rd one to adjust seeking posted later in
the thread.

These patches are blocking the ASS rewrite patches posted a while ago too,
and will be quite handy for the SRT patches I sent recently as well. Also
the seek will be shared with the pending VobSub demuxer so I'd like to get
this upstream soon to move ahead (and the JSON demuxer from Nicolas). And
not speaking about the subtitles filter in queue…

After all this stuff goes in, I'll:
 - do something about the FFmpeg-style ASS packets
 - go back to the StyledSubtitles API
 - profit

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121201/51e6b1de/attachment.asc>


More information about the ffmpeg-devel mailing list