繁体   English   中英

每帧ffmpeg边数据或元数据

[英]ffmpeg sidedata or metadata per frame

我正在尝试使用FFMpeg编码示例在每帧添加一些辅助数据或元数据

到目前为止,这是我尝试过的:

/* 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);
}

我也尝试过使用并将其设置为等于AVDictionary

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

但是什么都没有添加到编码中。

如何分别向每个帧添加数据?

您应该尝试将数据直接应用于框架的侧面数据

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

同样,您可能需要在AVFrameSideData中分配数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM