每帧ffmpeg边数据或元数据 [英] ffmpeg sidedata or metadata per frame
本文介绍了每帧ffmpeg边数据或元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 FFMpeg每帧添加一些辅助数据或元数据编码示例
这是我到目前为止尝试过的:
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);
}
我也尝试过使用并将其设置为等于AVDictionary
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?
推荐答案
您应尝试将数据直接应用于框架的侧面数据
You should try to apply the data directly to the frame's side data
av_dict_set(&(frame->metadata), "foo", "bar", 0);
同样,您可能需要在AVFrameSideData中分配数据.
As well, you might need to allocate the data in the AVFrameSideData.
这篇关于每帧ffmpeg边数据或元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文