[FFmpeg-devel] [PATCH 2/3] avformat/rawvideodec: Rework packet size calculation

Michael Niedermayer michaelni at gmx.at
Sat Nov 21 19:23:08 CET 2015


On Fri, Nov 20, 2015 at 09:34:12PM -0800, Timothy Gu wrote:
> Calculate packet size only once, and propagate errors earlier in the chain.
> 
> Also remove use of the deprecated av_image_get_buffer_size().
> ---
>  libavformat/rawvideodec.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c
> index 7f355ef..5fd58d3 100644
> --- a/libavformat/rawvideodec.c
> +++ b/libavformat/rawvideodec.c
> @@ -39,6 +39,7 @@ static int rawvideo_read_header(AVFormatContext *ctx)
>      RawVideoDemuxerContext *s = ctx->priv_data;
>      enum AVPixelFormat pix_fmt;
>      AVStream *st;
> +    int packet_size;
>  
>      st = avformat_new_stream(ctx, NULL);
>      if (!st)
> @@ -59,7 +60,11 @@ static int rawvideo_read_header(AVFormatContext *ctx)
>      st->codec->width  = s->width;
>      st->codec->height = s->height;
>      st->codec->pix_fmt = pix_fmt;
> -    st->codec->bit_rate = av_rescale_q(avpicture_get_size(st->codec->pix_fmt, s->width, s->height),
> +    packet_size = av_image_get_buffer_size(st->codec->pix_fmt, s->width, s->height, 1);
> +    if (packet_size < 0)
> +        return packet_size;
> +    ctx->packet_size = packet_size;
> +    st->codec->bit_rate = av_rescale_q(ctx->packet_size,
>                                         (AVRational){8,1}, st->time_base);
>  
>      return 0;
> @@ -68,18 +73,14 @@ static int rawvideo_read_header(AVFormatContext *ctx)
>  
>  static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
> -    int packet_size, ret, width, height;
> +    int ret, width, height;
>      AVStream *st = s->streams[0];

width and height are unused after this
patch should be fine otherwise

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

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151121/c19e7ba0/attachment.sig>


More information about the ffmpeg-devel mailing list