[FFmpeg-devel] [PATCH 2/3] Add av_load_index_file and av_save_index_file

Michael Niedermayer michaelni
Tue Aug 17 14:07:58 CEST 2010


On Fri, Aug 13, 2010 at 08:14:44AM +0200, Michael Chinen wrote:
> $subj

>  avformat.h |   12 ++++
>  utils.c    |  170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 182 insertions(+)
> d6ef375c8e8619e8f90458ac1a93592bb8ccd814  0002-Add-av_load_index_file-and-av_save_index_file.patch
> From 546d4247de28a98cc483719823459efff137a5ec Mon Sep 17 00:00:00 2001
> From: Michael Chinen <mchinen at gmail.com>
> Date: Fri, 13 Aug 2010 05:47:42 +0200
> Subject: [PATCH 2/3] Add av_load_index_file and av_save_index_file
> 
> ---
>  libavformat/avformat.h |   12 ++++
>  libavformat/utils.c    |  170 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 182 insertions(+), 0 deletions(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 2919056..29f105b 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1233,6 +1233,18 @@ int av_build_index(AVFormatContext *s, int flags);
>  #define AV_BUILD_INDEX_USE_CBR  0x0002 ///< Detect and use CBR instead of index seeking
>  
>  /**
> + * Saves the index table built with av_build_index to a file.
> + * @return 0 if succesful or a negative value on failure.
> + */
> +int av_save_index_file(AVFormatContext *ic, const char *filename);
> +
> +/**
> + * Loads the index saved with av_save_index.
> + * @return 0 if successful or a negative value on failure.
> + */
> +int av_load_index_file(AVFormatContext *ic, const char *filename);
> +
> +/**
>   * Ensure the index uses less memory than the maximum specified in
>   * AVFormatContext.max_index_size by discarding entries if it grows
>   * too large.
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index a8b67cd..496bd70 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -1878,6 +1878,176 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
>      // try some generic seek like av_seek_frame_generic() but with new ts semantics
>  }
>  
> +/**
> + * Save the flags, size, and differences for the index table
> + */
> +#define FF_SAVEINDEX_PACKETSIZE 1000
> +static int av_save_index_stream(ByteIOContext *bc, AVStream *st,
> +                                AVFormatContext *ic) {
> +    AVIndexEntry start_ie;
> +    AVIndexEntry *last_ie, *curr_ie;
> +    int i;
> +
> +    //we may need to save something like codec id to be safe.
> +    ff_put_v(bc, st->seek_table_flags);
> +    //we only write the index if we have a finished table.
> +    if (st->seek_table_flags & AV_SEEKTABLE_FINISHED) {
> +        ff_put_v(bc, st->nb_index_entries);
> +
> +        memset(&start_ie, 0, sizeof(AVIndexEntry));
> +        last_ie = &start_ie;
> +        for (i = 0; i < st->nb_index_entries; i++) {
> +            curr_ie = &st->index_entries[i];

> +            ff_put_v(bc, curr_ie->pos - last_ie->pos);
> +            ff_put_v(bc, curr_ie->timestamp - last_ie->timestamp);
> +            ff_put_v(bc, curr_ie->flags - last_ie->flags);
> +            ff_put_v(bc, curr_ie->size - last_ie->size);
> +            ff_put_v(bc, curr_ie->min_distance - last_ie->min_distance);

vertical align please


> +            last_ie = curr_ie;

> +            if (i % FF_SAVEINDEX_PACKETSIZE == 0)
> +                put_flush_packet(bc);

why?


[...]

> +static int av_load_index(ByteIOContext *bc, AVFormatContext *ic) {
> +    int i, ret;
> +    uint64_t v;
> +    char read_str[256];
> +
> +    get_strz(bc, read_str, 255);

s/255/sizeof()/

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

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100817/8812dcf1/attachment.pgp>



More information about the ffmpeg-devel mailing list