[FFmpeg-devel] [PATCH] Add ICO muxer

Michael Bradshaw mbradshaw at sorensonmedia.com
Sun Aug 12 18:13:39 CEST 2012


On Sun, Aug 12, 2012 at 7:38 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Thu, Aug 09, 2012 at 08:35:34PM -0600, Michael Bradshaw wrote:
>> Hi,
>>
>> Attached patch adds support for ICO muxing. I expect I'll need to make
>> changes, so please don't hold back in your reviews (I've never written
>> a muxer before so I'm still unsure if I got all the API contracts
>> right). I'm mostly unsure of the flushing (if I didn't flush, my very
>> small files would have missing data).
> [...]
>> +static int ico_write_trailer(AVFormatContext *s)
>> +{
>> +    IcoMuxContext *ico = s->priv_data;
>> +    AVIOContext *pb = s->pb;
>> +    int i;
>> +
>> +    if (ico->current_image != ico->nb_images) {
>> +        av_log(s, AV_LOG_ERROR, "Error: ico is missing %d frames\n", ico->nb_images - ico->current_image);
>> +        return AVERROR(EIO);
>> +    }
>> +
>> +    avio_seek(pb, 6, SEEK_SET);
>> +
>> +    for (i = 0; i < ico->nb_images; i++) {
>> +        avio_w8(pb, ico->images[i].width);
>> +        avio_w8(pb, ico->images[i].height);
>> +
>> +        if (s->streams[i]->codec->codec_id == CODEC_ID_BMP &&
>> +            s->streams[i]->codec->pix_fmt == PIX_FMT_PAL8) {
>> +            avio_w8(pb, (ico->images[i].bits >= 8) ? 0 : 1 << ico->images[i].bits);
>> +        } else {
>> +            avio_w8(pb, 0);
>> +        }
>> +
>> +        avio_w8(pb, 0); // reserved
>> +        avio_wl16(pb, 1); // color planes
>> +        avio_wl16(pb, ico->images[i].bits);
>> +        avio_wl32(pb, ico->images[i].size);
>> +        avio_wl32(pb, ico->images[i].offset);
>> +    }
>> +
>
>> +    avio_flush(pb);
>
> av_write_trailer()
> calls avio_flush(), so this should not be needed

Fixed (I'll send an updated patch in a minute when I finish testing my changes).

Thanks for the review!

--Michael


More information about the ffmpeg-devel mailing list