Why FFMpeg av_probe_input_format function is doing an access violation?

Viewed 180

I'm trying to probe a buffer of DHAV containing an H264 video stream. I use the code below to do that :

AVProbeData probeData;
probeData.buf_size = len < 4096 ? len : 4096;
probeData.filename = "stream";
probeData.buf = (unsigned char*)malloc(probeData.buf_size);
memcpy(probeData.buf, lpData, probeData.buf_size);

AVInputFormat* pAVInputFormat = av_probe_input_format(&probeData, 1);

My problem is that I have an Access violation exception during the call to av_probe_input_format. If I change the second argument to 0, I have no error, but the Format is not found. Any idea? I use an FFMpeg version compiled through vcpkg.

1 Answers

It's almost correct, first of all initialize the struct to 0 since it has other fields too.

The buffer must have an extra AVPROBE_PADDING_SIZE zero-filled bytes at the end.

Regarding av_probe_input_format, if the second parameter is 0 it will only check demuxers with the flag AVFMT_NOFILE so it's normal.

AVProbeData probeData = {0};
probeData.buf_size = len < 4096 ? len : 4096;
probeData.filename = "stream";
probeData.buf = av_mallocz(probeData.buf_size + AVPROBE_PADDING_SIZE);
memcpy(probeData.buf, lpData, probeData.buf_size);

I don't have a DAV to test, maybe you can upload the first 4096 bytes somewhere. It works with other formats.

Related