[FFmpeg-devel] [PATCH 3/3] avformat/webpenc: Check seeks
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Sun Apr 11 04:21:33 EEST 2021
James Almer:
> On 4/10/2021 9:43 PM, Andreas Rheinhardt wrote:
>> When writing the trailer, the WebP muxer unconditionally seeks back
>> to the front to update some elements. Yet this doesn't work if
>> the seek failed, so check for this.
>>
>> (This has been mentioned in ticket #9179.)
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
>> ---
>> Â libavformat/webpenc.c | 8 ++++----
>> Â 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
>> index 3962986c32..a24920d181 100644
>> --- a/libavformat/webpenc.c
>> +++ b/libavformat/webpenc.c
>> @@ -174,8 +174,8 @@ static int webp_write_trailer(AVFormatContext *s)
>> Â Â Â Â Â Â if (w->using_webp_anim_encoder) {
>> Â Â Â Â Â Â Â Â Â if ((w->frame_count > 1) && w->loop) {Â // Write loop count.
>> -Â Â Â Â Â Â Â Â Â Â Â avio_seek(s->pb, 42, SEEK_SET);
>> -Â Â Â Â Â Â Â Â Â Â Â avio_wl16(s->pb, w->loop);
>> +Â Â Â Â Â Â Â Â Â Â Â if (avio_seek(s->pb, 42, SEEK_SET) == 42)
>
> I think it's better if you also check for (s->pb->seekable &
> AVIO_SEEKABLE_NORMAL) before calling avio_seek() + avio_w* to begin with.
>
Actually I intentionally didn't do that because the seek might work even
when said flag is not set (when the destination is still in the
AVIOContext's buffer).
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â avio_wl16(s->pb, w->loop);
>> Â Â Â Â Â Â Â Â Â }
>> Â Â Â Â Â } else {
>> Â Â Â Â Â Â Â Â Â int ret;
>> @@ -183,8 +183,8 @@ static int webp_write_trailer(AVFormatContext *s)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
>> Â Â Â Â Â Â Â Â Â Â filesize = avio_tell(s->pb);
>> -Â Â Â Â Â Â Â avio_seek(s->pb, 4, SEEK_SET);
>> -Â Â Â Â Â Â Â avio_wl32(s->pb, filesize - 8);
>> +Â Â Â Â Â Â Â if (avio_seek(s->pb, 4, SEEK_SET) == 4)
>> +Â Â Â Â Â Â Â Â Â Â Â avio_wl32(s->pb, filesize - 8);
>> Â Â Â Â Â Â Â Â Â // Note: without the following, avio only writes 8 bytes to
>> the file.
>> Â Â Â Â Â Â Â Â Â avio_seek(s->pb, filesize, SEEK_SET);
>> Â Â Â Â Â }
>>
>
More information about the ffmpeg-devel
mailing list