[MPlayer-dev-eng] [PATCH] vf_screenshot: do not silently create empty screenshot files.

Anton Sviridenko anton at corp.bluecherry.net
Sat Dec 6 18:07:01 CET 2014


> Besides that, could you comment on my other vf_screenshot patch?

Yes, it is reasonable improvement

On Sat, Dec 6, 2014 at 3:34 PM, Reimar Döffinger
<Reimar.Doeffinger at gmx.de> wrote:
> On encode error, print a message and don't open the file.
> ---
>  libmpcodecs/vf_screenshot.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/libmpcodecs/vf_screenshot.c b/libmpcodecs/vf_screenshot.c
> index 360df9d..841990f 100644
> --- a/libmpcodecs/vf_screenshot.c
> +++ b/libmpcodecs/vf_screenshot.c
> @@ -107,18 +107,22 @@ static void write_png(struct vf_priv_s *priv)
>      AVPacket pkt;
>      int res, got_pkt;
>
> +    av_init_packet(&pkt);
> +    pkt.data = priv->outbuffer;
> +    pkt.size = priv->outbuffer_size;
> +    res = avcodec_encode_video2(priv->avctx, &pkt, priv->pic, &got_pkt);
> +    if (res < 0 || !got_pkt || pkt.size <= 0) {
> +        mp_msg(MSGT_VFILTER,MSGL_ERR,"\nFailed to encode screenshot %s!\n", fname);
> +        return;
> +    }
> +
>      fp = fopen (fname, "wb");
>      if (fp == NULL) {
>          mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname);
>          return;
>      }
>
> -    av_init_packet(&pkt);
> -    pkt.data = priv->outbuffer;
> -    pkt.size = priv->outbuffer_size;
> -    res = avcodec_encode_video2(priv->avctx, &pkt, priv->pic, &got_pkt);
> -    if (res >= 0 && got_pkt && pkt.size > 0)
> -        fwrite(priv->outbuffer, pkt.size, 1, fp);
> +    fwrite(priv->outbuffer, pkt.size, 1, fp);
>
>      fclose (fp);
>      mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname);
> --
> 2.1.3
>
> _______________________________________________
> MPlayer-dev-eng mailing list
> MPlayer-dev-eng at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng


More information about the MPlayer-dev-eng mailing list