tommed
tommed

Reputation: 1561

FFmpeg av_read_frame returns a size but no data?

I have written some C code to access ffmpeg and wrapped it in a C++/CLI (.NET managed) class. The program fetches a live video stream and extracts frames and converts them to PNG files.

Unfortunately the images that are saved to disk are always black (opening them in Notepad++ shows that they are full of nulls).

I am using the assemblies aformat/codec-55.dll and the development headers and libs for compilation from ffmpeg-20131120-git-e502783-win64-dev. The whole project is compiled using Managed C++ (Cpp/cli) .NET 4.0 for 64-bit.

After some investigation the problem appears to be that av_read_frame fills the AVPacket->size value correctly, but the AVPAcket->data is always null. When the frame is finished (got==1) then the data for the AVFrame is just a matrix of nulls. :(

Here is the code: Example code (sorry, but it didnt paste well into SO)

I think the problem is at line 34 when the packet is returned like so: size is set but data is empty

Please, how can I get this to work? What have I done wrong?

Upvotes: 4

Views: 2818

Answers (1)

iriusf
iriusf

Reputation: 51

Decoding part seems fine to me. I am not so sure about the encoding & saving to PNG. Why don't you try to just dump (frame->linesize*frame->height) bytes from frame->data to disk with fwrite and have a look to it with Irfanview (for instance)?

Upvotes: 1

Related Questions