元数据不显示ffmpeg c++

Metadata is not showing ffmpeg C++

本文关键字:c++ ffmpeg 显示 元数据      更新时间:2023-10-16

我正在将h264编码的视频数据和PCM g711编码的音频数据混合到.mov媒体容器中。我试图在标题上写元数据,但元数据没有显示,当我去文件->右键单击->属性->详细信息在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中使用mediainfoexiftools查看文件是否包含任何元数据。我也尝试了ffmpeg -i output.mov,但没有显示元数据。

怎么了?av_dict_set中的flags0可以吗?我需要为不同的平台(windows/linux)设置不同的标志吗?

我看到了这个链接,它说,对于windows,我必须使用id3v2_version 3-write_id3v1 1使元数据工作。如果是这样,我如何在c++中做到这一点?

我有一些类似于你的代码,但我将AVDictionary添加到我的AVFormatContext元数据参数,它为我工作的方式。以下是基于您的代码的代码片段:

AVDictionary *pMetaData = NULL;
av_dict_set(&pMetaData, "title", "Cloud Recording", 0);
m_pFormatCtx->metadata = pMetaData;
avformat_write_header(m_pFormatCtx, NULL);