使用 FFmpeg 检索和保存媒体元数据 [英] Retrieving and Saving media metadata using FFmpeg
问题描述
我想读取媒体文件中的元数据,然后将该元数据保存在一个 text/xml 文件中,以便我以后可以将该数据插入到我的数据库中.我更喜欢使用 ffmpeg.
MediaInfo 也能做到同样的事情吗??我知道我可以使用 MediaInfo 获取单个曲目的元数据,但我想自动化它;就像每当发现新的媒体文件时,读取其元数据,然后将其存储在 txt/xml 文件中.
或者,我可以使用其他任何工具/实用程序/API 吗?
您可以使用 -f ffmetadata
选项将全局元数据保存到文本文件中,如下所示:
ffmpeg -i in.mp4 -f ffmetadata in.txt
如果您还需要来自视频和音频流的元数据(例如,如果全局元数据不包含创建时间),请使用:
ffmpeg -i in.mp4 -c copy -map_metadata 0 -map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a -f ffmetadata in.txt
有关详细信息,请参阅 ffmpeg 文档中的元数据部分.
要从文件中恢复元数据,请参阅https://stackoverflow.com/a/50580239/2235831.>
I want to read the metadata in media files and then save that metadata in a text/xml file, so that I can later insert that data in my database. I would prefer to use ffmpeg.
Also is the same thing possible with MediaInfo?? I know I can get the metadata for individual tracks using MediaInfo, but I would want to automate it; as in whenever a new media file is found, read its metadata and then store it in a txt/xml file.
Or, is there any other tool/utility/API that I can use for this?
You can save the global metadata to a text file using the -f ffmetadata
option as follows:
ffmpeg -i in.mp4 -f ffmetadata in.txt
If you also need metadata from the video and audio streams (for example if the global metadata does not contain the creation time) use:
ffmpeg -i in.mp4 -c copy -map_metadata 0 -map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a -f ffmetadata in.txt
For details, see Metadata section in ffmpeg documentation.
For restoring metadata from a file see https://stackoverflow.com/a/50580239/2235831.
这篇关于使用 FFmpeg 检索和保存媒体元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!