我将h264编码的视频数据和PCM g711编码的音频数据混合到.mov
媒体容器中。我正在尝试在 header 上写元数据,但是当我在Windows上以及在Ubuntu中同样转到文件->右键单击->属性->详细信息时,元数据未显示。这是我的代码-
// Instead of creating new AVDictionary object, I also tried following way
// stated here: http://stackoverflow.com/questions/17024192/how-to-set-header-metadata-to-encoded-video
// but no luck
AVDictionary* pMetaData = m_pFormatCtx->metadata;
av_dict_set(&pMetaData, "title", "Cloud Recording", 0);
av_dict_set(&pMetaData, "artist", "Foobar", 0);
av_dict_set(&pMetaData, "copyright", "Foobar", 0);
av_dict_set(&pMetaData, "filename", m_sFilename.c_str(), 0);
time_t now = time(0);
struct tm tStruct = *localtime(&now);
char date[100];
strftime(date, sizeof(date), "%c", &tStruct); // i.e. Thu Aug 23 14:55:02 2001
av_dict_set(&pMetaData, "date", date, 0);
av_dict_set(&pMetaData, "creation_time", date, 0);
av_dict_set(&pMetaData, "comment", "This video has been created using Eyeball MSDK", 0);
// ....................
// .................
/* write the stream header, if any */
int ret = avformat_write_header(m_pFormatCtx, &pMetaData);
我还尝试在Linux中使用
mediainfo
和exiftools
查看文件是否包含任何元数据。我也尝试了ffmpeg -i output.mov
,但是没有显示元数据。有什么问题?
flags
中的0
值av_dict_set
可以吗?我是否需要为不同的平台(Windows / Linux)设置不同的标志?我看到了this link,它说对于Windows,我必须使用
id3v2_version 3
和-write_id3v1 1
来使元数据正常工作。如果是这样,如何在C++中做到这一点? 最佳答案
我有一些与您的代码相似的东西,但是我将AVDictionary
添加到我的AVFormatContext
metadata参数中,它对我有用。这是根据您的代码片段。
AVDictionary *pMetaData = NULL;
av_dict_set(&pMetaData, "title", "Cloud Recording", 0);
m_pFormatCtx->metadata = pMetaData;
avformat_write_header(m_pFormatCtx, NULL);