ffmpeg sidedata or metadata per frame

雨燕双飞 提交于 2020-01-25 04:35:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/51415447/ffmpeg-sidedata-or-metadata-per-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!