I'm trying to create a custom I/O layer to pass raw H.264 frame data to FFMPEG from QUdpSocket datagrams. The H.264 frames don't have any sort of container and are simply streamed from the frame grabbing device. Something is going wrong, because for some reason FFMPEG thinks the access unit has a size of 1 when I call avcodec_decode_video2():
[h264 @ 0x1030dd000] missing picture in access unit with size 1
[h264 @ 0x1030dd000] no frame!
My first step is to probe the first frame for the AVInputFormat:
socket->readDatagram(datagram.data(), datagram.size());
AVProbeData probeData;
probeData.filename = udpUrl.toStdString().c_str();
probeData.buf_size = datagram.size() + AVPROBE_PADDING_SIZE;
probeData.buf = (unsigned char *)malloc(datagram.size() + AVPROBE_PADDING_SIZE);
memcpy(&probeData.buf[AVPROBE_PADDING_SIZE], datagram.data(), datagram.size());
inputFormat = av_probe_input_format(&probeData, 1);
Next I allocate an AVIOContext:
buffer = (unsigned char *)malloc(bufferSize);
ioContext = avio_alloc_context(buffer, bufferSize, 0, socket, &readFrame, NULL, NULL);
After which I call avformat_open_input_stream():
if (av_open_input_stream(&formatContext, ioContext, "", inputFormat, NULL) != 0)
Which seems to return successfully. However, the video stream is missing important information such as width, height, and pixel format, which then causes av_find_stream_info() to fail. I can set these parameters manually, but it doesn't result in a successful decode, and it makes me wonder what else I'm missing.
From what I can tell, the NAL units are intact:
First Frame
00:00:00:01:27:64:00:28:ad:84:09:26:6e:23:34:90:81:24:cd:c4:66:92:10:24:99:b8:8c:d2:42:04:93:37:11:9a:48:40:92:66:e2:33:49:08:12:4c:dc:46:69:21:05:5a:eb:d7:d7:e4:fe:bf:27:d7:ae:b5:50:82:ad:75:eb:eb:f2:7f:5f:93:eb:d7:5a:ab:40:50:1e:c8:
00:00:00:01:28:ee:3c:b0:
00:00:00:01:25:88:84:27:...
Second Frame
00:00:00:01:21:9a:59:15:...
Am I missing an API call? Can anyone see something that I might be doing wrong?