[英]ffmpeg sidedata or metadata per frame
I'm trying to add either some side data or metadata per frame using the FFMpeg encoding example 我正在尝试使用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);
}
I have also tried using and setting it equal to a AVDictionary 我也尝试过使用并将其设置为等于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);
As well, you might need to allocate the data in the AVFrameSideData. 同样,您可能需要在AVFrameSideData中分配数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.