Dan Gordon
Dan Gordon

Reputation: 38

ffmpeg sidedata or metadata per frame

I'm trying to add either some side data or metadata per frame using the FFMpeg encoding example

Here's what I have tried so far:

/* encode 1 second of video */
for (i = 0; i < 25; i++) {
    fflush(stdout);
    /* make sure the frame data is writable */
    ret = av_frame_make_writable(frame);
    if (ret < 0)
        exit(1);
    /* prepare a dummy image */
    /* Y */
    for (y = 0; y < c->height; y++) {
        for (x = 0; x < c->width; x++) {
            frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
        }
    }
    /* Cb and Cr */
    for (y = 0; y < c->height/2; y++) {
        for (x = 0; x < c->width/2; x++) {
            frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
            frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
        }
    }
    frame->pts = I;

    AVFrameSideData *angle = av_frame_new_side_data (frame, AV_FRAME_DATA_GOP_TIMECODE, sizeof(int32_t));
    if(!angle)
        return AVERROR(ENOMEM);
    unint8_t a = i; 
    angle->data = &a;

    frame->side_data = angle
    /* encode the image */
    encode(c, frame, pkt, f);
}

I have also tried using and setting it equal to a AVDictionary

AVDictionary *d = NULL;
av_dict_set(&d, "foo", "bar", 0);
frame->metadata = d;

But nothing is getting added to the encode.

How do I add data to each frame individually?

Upvotes: 2

Views: 4108

Answers (1)

Radiateurs
Radiateurs

Reputation: 5

You should try to apply the data directly to the frame's side data

av_dict_set(&(frame->metadata), "foo", "bar", 0);

As well, you might need to allocate the data in the AVFrameSideData.

Upvotes: 1

Related Questions