Re: [PATCH 1/6] vo_png: switch to new FFmpeg API.

Alexander Strasser <[email protected]>
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
On 2020-12-20 18:50 +0100, Reimar Döffinger wrote:
> ---
>  libvo/vo_png.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/libvo/vo_png.c b/libvo/vo_png.c
> index 5696a1f3e..7523dca74 100644
> --- a/libvo/vo_png.c
> +++ b/libvo/vo_png.c
> @@ -150,8 +150,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
>
>  static uint32_t draw_image(mp_image_t* mpi){
>      AVFrame *pic;
> -    int buffersize;
> -    int res, got_pkt;
> +    int res;
>      char buf[100];
>      FILE *outfile;
>      AVPacket pkt;
> @@ -174,26 +173,25 @@ static uint32_t draw_image(mp_image_t* mpi){
>      pic->format = imgfmt2pixfmt(png_format);
>      pic->data[0] = mpi->planes[0];
>      pic->linesize[0] = mpi->stride[0];
> -    buffersize = mpi->w * mpi->h * 8;
> -    if (outbuffer_size < buffersize) {
> -        av_freep(&outbuffer);
> -        outbuffer = av_malloc(buffersize);
> -        outbuffer_size = buffersize;
> -    }
>      av_init_packet(&pkt);
> -    pkt.data = outbuffer;
> -    pkt.size = outbuffer_size;

> -    res = avcodec_encode_video2(avctx, &pkt, pic, &got_pkt);
> +    res = avcodec_send_frame(avctx, pic);
> +    if (res >= 0) {
> +        res = avcodec_receive_packet(avctx, &pkt);
> +        if (res == AVERROR(EAGAIN)) {
> +            avcodec_send_frame(avctx, NULL);
> +            res = avcodec_receive_packet(avctx, &pkt);
> +        }
> +    }

I don't like how this gets harder to read after the patch.

Did you try it like this?

1, avcodec_send_frame(avctx, pic)
2. avcodec_send_frame(avctx, NULL)
3. avcodec_receive_packet(avctx, &pkt)


>      av_frame_free(&pic);
>
> -    if (res < 0 || !got_pkt) {
> +    if (res < 0) {
>   	    mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
>      } else {
> -        fwrite(outbuffer, pkt.size, 1, outfile);
> +        fwrite(pkt.data, pkt.size, 1, outfile);
>      }
>
>      fclose(outfile);
> -    av_free_packet(&pkt);
> +    av_packet_unref(&pkt);
>
>      return VO_TRUE;
>  }
> @@ -251,7 +249,6 @@ static int preinit(const char *arg)
>      if (subopt_parse(arg, subopts) != 0) {
>          return -1;
>      }
> -    avcodec_register_all();
>      return 0;
>  }

Otherwise LGTM.


Thanks,
  Alexander
_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.