[FFmpeg-devel] [patch 3/3] Make timing calculations less dependant on start_time being defined.

Benoit Fouet benoit.fouet
Mon Sep 3 10:14:05 CEST 2007


Neil Brown wrote:
> On Friday August 31, michaelni at gmx.at wrote:
>   
>> ok, then the patch is ok
>>
>>     
>
> You seem to have said this to a couple of patches which nonetheless
> have not been applied.   Confused.
>
>   

the one i just applied (on start time) needed further test

> Benoit Fouet asked that patches be attached, so here are two patches
> that I believe have been agreed upon, but are not yet in svn.  Can
> they be included?
>   

i have not seen the other one ok'd

> Make sure that if a stream has a duration but the container doesn't
> then the container duration is set from the stream duration.
>
> The current code will only do this if the stream has both a duration
> and a start_time.
> ---
>  libavformat/utils.c |   35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
>
> --- ffmpeg.orig/libavformat/utils.c
> +++ ffmpeg/libavformat/utils.c
> @@ -1359,19 +1359,18 @@ int av_seek_frame(AVFormatContext *s, in
>  /*******************************************************/
>  
>  /**
> - * Returns TRUE if the stream has accurate timings in any stream.
> + * Returns TRUE if the stream has accurate duration in any stream.
>   *
> - * @return TRUE if the stream has accurate timings for at least one component.
> + * @return TRUE if the stream has accurate duration for at least one component.
>   */
> -static int av_has_timings(AVFormatContext *ic)
> +static int av_has_duration(AVFormatContext *ic)
>  {
>      int i;
>      AVStream *st;
>  
>      for(i = 0;i < ic->nb_streams; i++) {
>          st = ic->streams[i];
> -        if (st->start_time != AV_NOPTS_VALUE &&
> -            st->duration != AV_NOPTS_VALUE)
> +        if (st->duration != AV_NOPTS_VALUE)
>              return 1;
>      }
>      return 0;
> @@ -1385,11 +1384,13 @@ static int av_has_timings(AVFormatContex
>  static void av_update_stream_timings(AVFormatContext *ic)
>  {
>      int64_t start_time, start_time1, end_time, end_time1;
> +    int64_t duration, duration1;
>      int i;
>      AVStream *st;
>  
>      start_time = INT64_MAX;
>      end_time = INT64_MIN;
> +    duration = INT64_MIN;
>      for(i = 0;i < ic->nb_streams; i++) {
>          st = ic->streams[i];
>          if (st->start_time != AV_NOPTS_VALUE) {
> @@ -1403,19 +1404,27 @@ static void av_update_stream_timings(AVF
>                      end_time = end_time1;
>              }
>          }
> +        if (st->duration != AV_NOPTS_VALUE) {
> +            duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);
> +            if (duration1 > duration)
> +                duration = duration1;
> +        }
>      }
>      if (start_time != INT64_MAX) {
>          ic->start_time = start_time;
>          if (end_time != INT64_MIN) {
> -            ic->duration = end_time - start_time;
> -            if (ic->file_size > 0) {
> -                /* compute the bit rate */
> -                ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
> -                    (double)ic->duration;
> -            }
> +            if (end_time - start_time > duration)
> +                duration = end_time - start_time;
> +        }
> +    }
> +    if (duration != INT64_MIN) {
> +        ic->duration = duration;
> +        if (ic->file_size > 0) {
> +            /* compute the bit rate */
> +            ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
> +                (double)ic->duration;
>          }
>      }
> -
>  }
>  
>  static void fill_all_stream_timings(AVFormatContext *ic)
> @@ -1581,7 +1590,7 @@ static void av_estimate_timings(AVFormat
>          file_size && !ic->pb.is_streamed) {
>          /* get accurate estimate from the PTSes */
>          av_estimate_timings_from_pts(ic, old_offset);
> -    } else if (av_has_timings(ic)) {
> +    } else if (av_has_duration(ic)) {
>          /* at least one components has timings - we use them for all
>             the components */
>          fill_all_stream_timings(ic);
>   

-- 
Ben
Purple Labs S.A.
www.purplelabs.com




More information about the ffmpeg-devel mailing list