[Libav-user] AVFrame to PNG

Strahinja Radman dr.strashni at gmail.com
Thu Apr 13 06:18:50 EEST 2023


On Thu, 13 Apr 2023 at 04:32, Gustav González <xtingray at gmail.com> wrote:

> Hi,
> Currently, I am working on a little Libav example to split a small MP4
> video into a PNG sequence.
> So far, this is what I have right now:
> https://github.com/xtingray/MP4toPNG/blob/main/cutter.c
>
> If you clone the repository on a Unix environment, it's effortless to test
> the example by running the build.sh script.
> Most of the implementation is working: I load the MP4 input file, split
> the video into AVFrame variables, and then I use the libpng library to
> create the PNG files.
> My only problem is that the images generated are misconfigured and
> gray-colored, just like this one:
> https://github.com/xtingray/MP4toPNG/blob/main/output/frame-1.png
>
> I am guessing the error is related to the way I take the AVFrame data and
> store it for the PNG file, but I am not sure at all:
>
> png_bytep *row_pointers = (png_bytep *) malloc(sizeof(png_bytep) * frame->
> height);
> for (int y = 0; y < frame->height; y++) {
> row_pointers[y] = (png_bytep) (frame->data[0] + y * frame->linesize[0]);
> }
>
> I appreciate any hint to fix the error. Thank you!
>
> --
>   Gustav Gonzalez
>   xtingray at gmail.com
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
Hi Gustav,

Thats because you are only saving luminance component. There are also two
more components for color, in following arrays frame->data[1] and
frame->data[2].

Kind regards,
Strahinja
-- 

Regards
Strahinja Radman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230413/f3e7cec9/attachment.htm>


More information about the Libav-user mailing list