[FFmpeg-cvslog] movenc: Write file with minimal number of chunks for the given interleaving .

Geek.Song ffmpeg at gmail.com
Tue Nov 29 16:38:06 CET 2011


Good job!

But the definition of "uint64_t  chunkSize; " in the struct
"MOVIentry" is redundant, it is can be localized in ''build_chunks()'
such as:

static void build_chunks(MOVTrack *trk)
{
    int i;
    MOVIentry *chunk= &trk->cluster[0];
    uint64_t chunkSize = chunk->size;
    chunk->chunkNum= 1;
    trk->chunkCount= 1;
    for(i=1; i<trk->entry; i++){
        if(chunk->pos + chunkSize == trk->cluster[i].pos){
            chunkSize             += trk->cluster[i].size;
            chunk->samplesInChunk += trk->cluster[i].samplesInChunk;
        }else{
            trk->cluster[i].chunkNum = chunk->chunkNum+1;
            chunk=&trk->cluster[i];
            chunkSize = chunk->size;
            trk->chunkCount++;
        }
    }
}

On Tue, Nov 29, 2011 at 12:05 PM, Michael Niedermayer <git at videolan.org> wrote:
> ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Nov 29 04:03:22 2011 +0100| [fc09bf57a60d4c4a6d339b204b3282337067c06d] | committer: Michael Niedermayer
>
> movenc: Write file with minimal number of chunks for the given interleaving.
>
> Reviewed-by: Baptiste Coudurier <baptiste.coudurier at gmail.com>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
>
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fc09bf57a60d4c4a6d339b204b3282337067c06d
> ---
>
>  libavformat/movenc.c          |   31 +++++++++++++++++++++++++++----
>  libavformat/movenc.h          |    3 +++
>  tests/ref/acodec/alac         |    4 ++--
>  tests/ref/acodec/pcm          |   16 ++++++++--------
>  tests/ref/lavf/mov            |    4 ++--
>  tests/ref/vsynth1/dnxhd_1080i |    4 ++--
>  tests/ref/vsynth1/mpeg4       |    4 ++--
>  tests/ref/vsynth1/prores      |    4 ++--
>  tests/ref/vsynth1/qtrle       |    4 ++--
>  tests/ref/vsynth1/qtrlegray   |    4 ++--
>  tests/ref/vsynth1/svq1        |    4 ++--
>  tests/ref/vsynth2/dnxhd_1080i |    4 ++--
>  tests/ref/vsynth2/mpeg4       |    4 ++--
>  tests/ref/vsynth2/prores      |    4 ++--
>  tests/ref/vsynth2/qtrle       |    4 ++--
>  tests/ref/vsynth2/qtrlegray   |    4 ++--
>  tests/ref/vsynth2/svq1        |    4 ++--
>  17 files changed, 66 insertions(+), 40 deletions(-)
>
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index efa0b92..d72ac4d 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -81,8 +81,10 @@ static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track)
>     } else
>         ffio_wfourcc(pb, "stco");
>     avio_wb32(pb, 0); /* version & flags */
> -    avio_wb32(pb, track->entry); /* entry count */
> +    avio_wb32(pb, track->chunkCount); /* entry count */
>     for (i=0; i<track->entry; i++) {
> +        if(!track->cluster[i].chunkNum)
> +            continue;
>         if(mode64 == 1)
>             avio_wb64(pb, track->cluster[i].pos);
>         else
> @@ -140,11 +142,11 @@ static int mov_write_stsc_tag(AVIOContext *pb, MOVTrack *track)
>     ffio_wfourcc(pb, "stsc");
>     avio_wb32(pb, 0); // version & flags
>     entryPos = avio_tell(pb);
> -    avio_wb32(pb, track->entry); // entry count
> +    avio_wb32(pb, track->chunkCount); // entry count
>     for (i=0; i<track->entry; i++) {
> -        if(oldval != track->cluster[i].samplesInChunk)
> +        if(oldval != track->cluster[i].samplesInChunk && track->cluster[i].chunkNum)
>         {
> -            avio_wb32(pb, i+1); // first chunk
> +            avio_wb32(pb, track->cluster[i].chunkNum); // first chunk
>             avio_wb32(pb, track->cluster[i].samplesInChunk); // samples per chunk
>             avio_wb32(pb, 0x1); // sample description index
>             oldval = track->cluster[i].samplesInChunk;
> @@ -1805,6 +1807,24 @@ static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s)
>     return 0;
>  }
>
> +static void build_chunks(MOVTrack *trk)
> +{
> +    int i;
> +    MOVIentry *chunk= &trk->cluster[0];
> +    chunk->chunkNum= 1;
> +    trk->chunkCount= 1;
> +    for(i=1; i<trk->entry; i++){
> +        if(chunk->pos + chunk->chunkSize == trk->cluster[i].pos){
> +            chunk->chunkSize      += trk->cluster[i].size;
> +            chunk->samplesInChunk += trk->cluster[i].entries;
> +        }else{
> +            trk->cluster[i].chunkNum = chunk->chunkNum+1;
> +            chunk=&trk->cluster[i];
> +            trk->chunkCount++;
> +        }
> +    }
> +}
> +
>  static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
>                               AVFormatContext *s)
>  {
> @@ -1818,6 +1838,8 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
>
>         mov->tracks[i].time = mov->time;
>         mov->tracks[i].trackID = i+1;
> +
> +        build_chunks(&mov->tracks[i]);
>     }
>
>     if (mov->chapter_track)
> @@ -2070,6 +2092,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
>
>     trk->cluster[trk->entry].pos = avio_tell(pb) - size;
>     trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
> +    trk->cluster[trk->entry].chunkSize =
>     trk->cluster[trk->entry].size = size;
>     trk->cluster[trk->entry].entries = samplesInChunk;
>     trk->cluster[trk->entry].dts = pkt->dts;
> diff --git a/libavformat/movenc.h b/libavformat/movenc.h
> index 1aa23fa..b022f48 100644
> --- a/libavformat/movenc.h
> +++ b/libavformat/movenc.h
> @@ -43,6 +43,8 @@ typedef struct MOVIentry {
>     unsigned int size;
>     uint64_t     pos;
>     unsigned int samplesInChunk;
> +    unsigned int chunkNum;              ///< Chunk number if the current entry is a chunk start otherwise 0
> +    uint64_t     chunkSize;
>     unsigned int entries;
>     int          cts;
>     int64_t      dts;
> @@ -73,6 +75,7 @@ typedef struct MOVIndex {
>     int64_t     trackDuration;
>     long        sampleCount;
>     long        sampleSize;
> +    long        chunkCount;
>     int         hasKeyframes;
>  #define MOV_TRACK_CTTS         0x0001
>  #define MOV_TRACK_STPS         0x0002

-- 
-----------------------------------------------------------------------------------------
My key fingerprint: d1:03:f5:32:26:ff:d7:3c:e4:42:e3:51:ec:92:78:b2


More information about the ffmpeg-cvslog mailing list