[FFmpeg-devel] [PATCH 4/6] avformat: add argo_asf muxer

Zane van Iperen zane at zanevaniperen.com
Sun Aug 2 16:11:50 EEST 2020


On Sun, 2 Aug 2020 14:43:20 +0200
"Andreas Rheinhardt" <andreas.rheinhardt at gmail.com> wrote:

> > So, something like this basically:
> >
> >     static int argo_asf_write_packet(AVFormatContext *s, AVPacket *pkt)
> >     {
> >         if (pkt->size != 17 && pkt->size != 34)
> >             return AVERROR(EINVAL);
> >
> >         avio_write(s->pb, pkt->data, pkt->size);
> >         return 0;
> >     }
> >  
> I think it is rather AVERROR_INVALIDDATA. But even then there are still
> two problems: You allow 17 byte packets in case of stereo, yet in this
> case you still assert that the data size is divisible by 34. And more
> serious: Currently, the AVIOContext's position is incremented even if a
> write error happened or if writing is not even attempted because of an
> earlier write error, yet there is no guarantee that it always stays that
> way.

Yeah, it's late here, I shouldn't be doing this when tired.
That check should have been:

    if (pkt->size != 17 * s->streams[0]->codecpar->channels)
        return AVERROR_INVALIDDATA;

> 
> For the record, AVStream.nb_frames contains the number of frames
> successfully written. You could simply use that and ignore any
> divisibility. Or you could check the sizes in a custom write_packet
> function and still just use AVStream.nb_frames when writing the trailer.
> 
I didn't know about AVStream.nb_frames, that makes things much nicer.
I've removed the assert and changed it to do what you suggested.


Zane



More information about the ffmpeg-devel mailing list