[Libav-user] AVFrame to PNG

Gustav González xtingray at gmail.com
Thu Apr 13 05:32:29 EEST 2023


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230412/b0451550/attachment.htm>


More information about the Libav-user mailing list