'Add frame number/index to AVFrame object
I have an application that encodes a video stream coming from a camera in H264 and stores it on the disk. In another part of the application I'm loading this movie and showing it to the user. All of this works except the fact that the unique frame index number that I add when encoding the frames aren't the same as the frame numbers that I get when I decode the file.
this is a snippet of my code when I encode a frame. I use "display_picture_number" to store this unique frame number, is this correct? why is the number not the same?
void MovieCodec::createFrame( const MyImage& image, AVFrame* frame )
{
frame->format = streamPixelFormat;
frame->width = image.width();
frame->height = image.height();
frame->pict_type = AV_PICTURE_TYPE_P;
frame->display_picture_number = image.uniqueImageNumber();
int ret = av_image_alloc( frame->data, frame->linesize, frame->width, frame->height, AV_PIX_FMT_BGR24, 1);
if (ret < 0)
{
return;
}
struct SwsContext* sws_ctx = sws_getContext((int)image.width(), (int)image.height(), AV_PIX_FMT_BGR24,
(int)image.width(), (int)image.height(), streamPixelFormat,
0, NULL, NULL, NULL);
const uint8_t* rgbData[1] = { (uint8_t* )image.getData() };
int rgbLineSize[1] = { 3 * (int)image.width() };
sws_scale(sws_ctx, rgbData, rgbLineSize, 0, image.height(), frame->data, frame->linesize);
}
Solution 1:[1]
Check AVFrame structure documentation.
You cannot set display_picture_number as this is will not be processed by ffmpeg during encoding
You could use AVFrame 's metadata instead to store some "notes"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SuRGeoNix |
