How to set header metadata to encoded video?

2019-02-06 23:10发布

I'm encoding some images into an h264 video inside an mp4 container. I'm essentially using the ffmpeg example muxing.c. The thing is I'm trying to set some metadata in the mp4 container such as artist, title, etc...

I thought using the following would work but it didn't:

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);

After the whole video is created I don't see any metadata written to the video file. Any pointers how to actually do this properly?

标签: c++ c ffmpeg
1条回答
欢心
2楼-- · 2019-02-06 23:24

The solution was to actually use the metadata variable from AVFormatContext instead of creating my own AVDictionary and passing it to the avformat_write_header function.

查看更多
登录 后发表回答