如何将标头元数据设置为编码视频?

Jon*_*ona 8 c c++ ffmpeg

我正在将一些图像编码到mp4容器内的h264视频中.我基本上使用的是ffmpeg示例muxing.c.问题是我正在尝试在mp4容器中设置一些元数据,如艺术家,标题等......

我认为使用以下方法可行,但它没有:

AVDictionary *opts = NULL;
av_dict_set(&opts, "title", "Super Lucky Dude", 0);
av_dict_set(&opts, "author", "Jacky Chan", 0);
av_dict_set(&opts, "album", "Chinese Movie", 0);
av_dict_set(&opts, "year", "05/10/2013", 0);
av_dict_set(&opts, "comment", "This video was created using example app.", 0);
av_dict_set(&opts, "genre", "Action", 0);

// Write the stream header, if any.
ret = avformat_write_header(oc, &opts);
Run Code Online (Sandbox Code Playgroud)

创建整个视频后,我没有看到任何元数据写入视频文件.任何指针如何正确地做到这一点?

Jon*_*ona 7

解决方案是实际使用metadata变量AVFormatContext而不是创建自己的变量AVDictionary并将其传递给avformat_write_header function.