[FFmpeg-devel] [PATCH] Guess the duration before converting video

Michael Niedermayer michaelni
Mon Feb 1 13:41:00 CET 2010


On Sun, Jan 31, 2010 at 07:08:27PM -0600, Justin Johnson wrote:
> This patch guesses at the duration of the output file, and in the case
> of encoding to flv the duration header is filled in ahead of time.
> This allows for on-the-fly encoding to flv, which behaves like a
> progressive download.
> In particular I'm using this with MythTV's mythweb plugin to allow
> streaming of recorded shows via flash. In order to get a working
> scrubber, this patch to ffmpeg as well as another patch for mythweb
> must be applied.
> I don't believe this interferes with the functionality of ffmpeg, as
> it is my understanding that any duration gets calculated after the
> file is finished being encoded, this just preempts that and guesses
> the duration beforehand. If it turns out that it's incorrect (only
> encoding part of a file, or the encode is canceled by the user), it is
> overwritten.
> --Justin Johnson

>  ffmpeg.c             |   11 +++++++++++
>  libavformat/flvenc.c |    2 +-
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 57eb28c2951e3ac014aeb28448e1e6d67847b3ce  ffmpeg.diff
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 21580)
> +++ ffmpeg.c	(working copy)
> @@ -2104,6 +2104,17 @@
>          ist->is_start = 1;
>      }
>  
> +    /* set the duration of the output to the duration of the input
> +     * if the output ends up being different, it'll be corrected later */
> +    for (i=0;i<nb_output_files;i++) {
> +        AVFormatContext *out_file;
> +        AVFormatContext *in_file;
> +
> +        out_file = output_files[i];
> +        in_file = input_files[i];
> +        out_file->duration = in_file->duration;
> +    }

-t -ss flags are not considered


> +
>      /* set meta data information from input file if required */
>      for (i=0;i<nb_meta_data_maps;i++) {
>          AVFormatContext *out_file;
> Index: libavformat/flvenc.c
> ===================================================================
> --- libavformat/flvenc.c	(revision 21580)
> +++ libavformat/flvenc.c	(working copy)
> @@ -221,7 +221,7 @@
>  
>      put_amf_string(pb, "duration");
>      flv->duration_offset= url_ftell(pb);
> -    put_amf_double(pb, 0); // delayed write
> +    put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect


ok

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100201/2f3c1dea/attachment.pgp>



More information about the ffmpeg-devel mailing list