I'm trying to create an mp4 video using a camera that provides h264 raw compressed data (annex b format), without decoding or encoding operations.I use v4l2 to get frames from the camera and for each frame I fill an AVPacket and write it to the file using av_write_frame. It works well, but the video is not so fluid and using ffprobe I noticed that there are no B-frames in the video, but only I-frames and P-frames.
for(int i = 0; i<100; i++){
// Dequeue the buffer
if(ioctl(fd, VIDIOC_DQBUF, &bufferinfo) < 0)
perror("Could not dequeue the buffer, VIDIOC_DQBUF");
AVPacket packet;
av_init_packet(&packet);
packet.stream_index = videoStream->index;
//buffer is allocated with mmap
packet.data = (uint8_t*)buffer;
//byteused is about 20/40 kB
packet.size = bufferinfo.bytesused;
packet.pts = (1.0 / 30) * 24000 * i;
err = av_write_frame(outputFormatCtx, &packet);
if(err < 0)
cout << "Error write frame "<<endl;
printf("Write frame (size= %2d)\n", packet.size);
if(ioctl(fd, VIDIOC_QBUF, &bufferinfo) < 0){
perror("Could not queue buffer, VIDIOC_QBUF");
return 1;
}
av_packet_unref(&packet);
}
err = av_write_trailer(outputFormatCtx);
if( err < 0)
cout<<"Error : av_write_trailer()" << endl;
I don't understand if the problem is the capture or the file writing. Thanks.