Problem: extracted alpha plane from a grayscale PNG is shifted by 1 pixel to the left

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem: extracted alpha plane from a grayscale PNG is shifted by 1 pixel to the left

Mikhail V
I have a strange problem with extracting alpha plane from an grayscale
PNG with alpha channel.
So I have an image with alpha in it and use this command:

ffmpeg -i 1-open-patch.png  -vf alphaextract   -pix_fmt gray  testgray_alpha.png
or
ffmpeg -i 1-open-patch.png  -vf alphaextract   testgray_alpha.png
(wich works same way I think)

Problem:  the output alpha plane is shifted 1 pixel to the left. The
data is ok - but the position is 1 pixel shifted.
The problem appears only with ya8 pixel format. If I use same but RGBa
image the output plane is correctly positioned.

Windows 10 latest build

Console  output:

ffmpeg -i 1-open-patch.png  -vf alphaextract  testgray_alpha.png
ffmpeg version N-93532-g772c73e61f Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20190212
  configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libdav1d --enable-libbluray --enable-libfreetype
--enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus
--enable-libshine --enable-libsnappy --enable-libsoxr
--enable-libtheora --enable-libtwolame --enable-libvpx
--enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265
--enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib
--enable-gmp --enable-libvidstab --enable-libvorbis
--enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex
--enable-libxvid --enable-libaom --enable-libmfx --enable-amf
--enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc
--enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 48.101 / 58. 48.101
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, png_pipe, from '1-open-patch.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, ya8(pc), 800x600 [SAR 2835:2835 DAR 4:3],
25 tbr, 25 tbn, 25 tbc
File 'testgray_alpha.png' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'testgray_alpha.png':
  Metadata:
    encoder         : Lavf58.26.101
    Stream #0:0: Video: png, gray, 800x600 [SAR 2835:2835 DAR 4:3],
q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.48.101 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=0.853x
video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: unknown



Mikhail
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Problem: extracted alpha plane from a grayscale PNG is shifted by 1 pixel to the left

Carl Eugen Hoyos-2
2019-04-07 2:17 GMT+02:00, Mikhail V <[hidden email]>:

> I have a strange problem with extracting alpha plane from an grayscale
> PNG with alpha channel.
> So I have an image with alpha in it and use this command:
>
> ffmpeg -i 1-open-patch.png  -vf alphaextract   -pix_fmt gray
> testgray_alpha.png
> or
> ffmpeg -i 1-open-patch.png  -vf alphaextract   testgray_alpha.png
> (wich works same way I think)
>
> Problem:  the output alpha plane is shifted 1 pixel to the left. The
> data is ok - but the position is 1 pixel shifted.
> The problem appears only with ya8 pixel format. If I use same but RGBa
> image the output plane is correctly positioned.

Please test the inlined patch.

Carl Eugen


diff --git a/libavfilter/vf_extractplanes.c b/libavfilter/vf_extractplanes.c
index 739c242..2f2c8e1 100644
--- a/libavfilter/vf_extractplanes.c
+++ b/libavfilter/vf_extractplanes.c
@@ -226,6 +226,8 @@ static int config_input(AVFilterLink *inlink)
         for (i = 0; i < 4; i++)
             s->map[i] = rgba_map[s->map[i]];
     }
+    if (inlink->format == AV_PIX_FMT_GRAY8A)
+        s->map[0] = 1;

     return 0;
 }
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".