c - 每帧的 ffmpeg 边数据或元数据

标签 c ffmpeg metadata

我正在尝试使用 the FFMpeg encoding example 添加一些边数据或每帧元数据

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

/* 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 中分配数据。

关于c - 每帧的 ffmpeg 边数据或元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51415447/

相关文章:

c - C 中类型转换丢失的信息

尝试用图像制作幻灯片时,ffmpeg 抛出 "Output file #0 does not contain any stream"

jsf - 当使用 <ui :composition> templating, 时,我应该在哪里声明 <f :metadata>?

python - 从文本生成关键字的简单方法是什么?

c - 编写 Linux 内存驱动程序以将小写字母转换为大写字母

c - 获取将文档打印到 IPP 打印机的真实用户

c - 我如何处理 GTK+3 中的键盘事件?

php - 使用 ffmpeg 将 mp3 转换为 ogg

ffmpeg 故意丢帧以降低文件大小

c# - ASP.NET登录控件连接字符串错误: Keyword not supported: 'metadata'