[FFmpeg-devel] [PATCH 2/3] concatdec: add force_duration option

Nicolas George george at nsup.org
Mon Jun 23 16:59:27 CEST 2014


Le quintidi 5 messidor, an CCXXII, Andrey Utkin a écrit :
> When set to 1, demuxer stops reading file when timestamp reaches stated duration
> ---
>  libavformat/concatdec.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
> index b3e6a37..263e00f 100644
> --- a/libavformat/concatdec.c
> +++ b/libavformat/concatdec.c
> @@ -56,6 +56,7 @@ typedef struct {
>      int seekable;
>      ConcatMatchMode stream_match_mode;
>      unsigned auto_convert;
> +    int force_duration;
>  } ConcatContext;
>  
>  static int concat_probe(AVProbeData *probe)
> @@ -516,6 +517,18 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
>              av_packet_unref(pkt);
>              continue;
>          }

> +        if (cat->force_duration && cat->cur_file->duration != AV_NOPTS_VALUE
> +                && pkt->pts != AV_NOPTS_VALUE) {
> +            int64_t duration_up_to_now = av_rescale_q(pkt->pts,
> +                    cat->avf->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q)
> +                - cat->cur_file->start_time;
> +            if (duration_up_to_now > cat->cur_file->duration) {
> +                av_packet_unref(pkt);
> +                if ((ret = open_next_file(avf)) < 0)
> +                    return ret;
> +                continue;
> +            }
> +        }
>          pkt->stream_index = cs->out_stream_index;
>          break;
>      }
> @@ -629,6 +642,8 @@ static const AVOption options[] = {
>        OFFSET(safe), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DEC },
>      { "auto_convert", "automatically convert bitstream format",
>        OFFSET(auto_convert), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
> +    { "force_duration", "stop reading file when timestamp reaches stated duration",
> +      OFFSET(force_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
>      { NULL }
>  };

I do not oppose the feature, but I find it a bit specific. Can you share the
intended use-case? Maybe a more elegant / generic solution can be found.

Also, "force_duration" seems a bit vague. Maybe "truncate_at_duration"? I
have no great idea for it, so please do not hesitate to suggest some.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140623/cdc8767f/attachment.asc>


More information about the ffmpeg-devel mailing list