【问题标题】:Retrieving and Saving media metadata using FFmpeg使用 FFmpeg 检索和保存媒体元数据
【发布时间】:2012-03-16 21:39:15
【问题描述】:

我想读取媒体文件中的元数据,然后将该元数据保存在 text/xml 文件中,以便以后可以将该数据插入到我的数据库中。我更喜欢使用 ffmpeg。

MediaInfo 也可以做同样的事情吗??我知道我可以使用 MediaInfo 获取单个曲目的元数据,但我想自动化它;就像每当找到新的媒体文件时,读取其元数据,然后将其存储在 txt/xml 文件中。

或者,我可以为此使用任何其他工具/实用程序/API吗?

【问题讨论】:

  • 以及如何通过ffmpeg获取节目指南(EPG)?!
  • 似乎没人知道,或者目前无法从 .ts 文件(扩展名为 .eit 的文本文件)中导出 EPG 信息并将其作为元数据放入 MP4 中。真的,我在互联网上搜索了几个小时,我什么也没找到。我认为这可能是对系列中的一章进行简短描述的明显和最佳步骤。从技术上讲似乎很容易,但没有工具支持。
  • 顺便有一个叫metaX (danhinsley.com) 的软件,可以从互联网上检索元数据,并为.mp4 .mkv 等设置元数据。你只需要知道serie/movie/show 并且您将查找数据。不幸的是,它不适用于 EPG 信息或 .ts 文件,并且该软件不适用于系列中的章节。如果您可以导出 EPG 数据,可以解决一些问题。

标签: ffmpeg metadata media


【解决方案1】:

您可以使用-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 文档中的Metadata 部分。

要从文件中恢复元数据,请参阅https://stackoverflow.com/a/50580239/2235831

【讨论】:

  • 我发现 avprobe 会打印更多信息(它与 ffmpeg 一起提供)。像“avprobe -show_format input_video -v 0”这样的东西可能会有所帮助。
  • 我认为这个页面比链接的页面提供更多信息:ffmpeg.org/ffmpeg-formats.html#Metadata
  • 如果您的系统上没有avprobe,它可能以ffprobe 的形式存在。
  • @DmitryShkuropatsky [mpegts @ 0000000002f6f2a0] PES 数据包大小不匹配。输出文件为空,未编码任何内容。 -------- 输出内容为:;FFMETADATA1 encoder=Lavf56.40.101
  • 以及如何通过ffmpeg获取节目指南(EPG)?!
【解决方案2】:

我更喜欢使用 exiftool,它提供了比 ffmpeg 更多的输出。举个例子(来自iphone的文件):

exiftool IMG_0014.MOV >a.txt

输出是


ExifTool Version Number         : 8.60
File Name                       : IMG_0014.MOV
Directory                       : .
File Size                       : 19 MB
File Modification Date/Time     : 2013:07:19 12:03:22-10:00
File Permissions                : rw-r--r--
File Type                       : MOV
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Movie Data Size                 : 19979709
Movie Header Version            : 0
Modify Date                     : 2013:07:19 22:03:21
Time Scale                      : 600
Duration                        : 7.27 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2013:07:19 22:03:13
Track Modify Date               : 2013:07:19 22:03:21
Track ID                        : 1
Track Duration                  : 7.27 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1080
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1080
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 27.011
Camera Identifier               : Back
Frame Readout Time              : 28512 microseconds
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2013:07:19 22:03:13
Media Modify Date               : 2013:07:19 22:03:21
Media Time Scale                : 44100
Media Duration                  : 7.31 s
Media Language Code             : und
Balance                         : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Audio Format                    : chan
Model                           : iPhone 4S
Software Version                : 6.1.3
Create Date                     : 2013:07:20 08:03:13+10:00
Make                            : Apple
Handler Type                    : Metadata Tags
Make (und-AU)                   : Apple
Creation Date (und-AU)          : 2013:07:20 08:03:13+10:00
Software (und-AU)               : 6.1.3
Model (und-AU)                  : iPhone 4S
Avg Bitrate                     : 22 Mbps
Image Size                      : 1920x1080
Rotation                        : 90

如果我使用 ffmpeg

 ffmpeg -i IMG_0014.MOV -f ffmetadata metadata.txt

输出是

;FFMETADATA1
major_brand=qt  
minor_version=0
compatible_brands=qt  
date-eng=2013-07-20T08:03:13+1000
encoder=6.1.3
encoder-eng=6.1.3
date=2013-07-20T08:03:13+1000

【讨论】:

  • 很遗憾,exiftool 不允许将元数据保存回视频文件。
  • 以及如何通过ffmpeg获取节目指南(EPG)?!
  • 有没有Android版本的exiftool,在exiftool的网站上搜索过,但没有找到。
  • @Filipe Correia,exiftool 手册页的 NAME 行说,“exiftool - 读取和写入文件中的元信息”所以你能更具体地说明你发表评论的原因吗?
  • @DavidN.Jafferian 评论来自 2013 年,但从那时起 exiftool 也获得了将元数据写入视频文件的能力
【解决方案3】:

还有atomicparsley 用于 MPEG-4 文件。

【讨论】:

    【解决方案4】:

    您可以使用ffprobeffmpeg 附带)收集有关多媒体文件的信息。有关多媒体文件整体内容的信息,请使用

    ffprobe -show_streams -show_format DV06xx.avi 
    

    有关视频文件中每一帧的信息,请使用

    ffprobe -show_frames DV06xx.avi 
    

    但是,ffprobe 检索的信息不如我最喜欢的工具 Mediainfo 检索的信息多,例如,“ffprobe”不显示视频第一帧的时间码(尽管手册页另有声明)或记录日期。

    如果你在命令行运行mediainfo,你甚至可以请求以XML格式输出:

    mediainfo --OUTPUT=XML DV06xx.avi 
    

    在我的示例中,输出为:

    <?xml version="1.0" encoding="UTF-8"?>
    <Mediainfo version="0.7.63">
    <File>
    <track type="General">
    <Complete_name>DV06xx.avi</Complete_name>
    <Format>AVI</Format>
    <Format_Info>Audio Video Interleave</Format_Info>
    <Commercial_name>DVCPRO</Commercial_name>
    <Format_profile>OpenDML</Format_profile>
    <File_size>13.3 GiB</File_size>
    <Duration>1h 2mn</Duration>
    <Overall_bit_rate_mode>Constant</Overall_bit_rate_mode>
    <Overall_bit_rate>30.5 Mbps</Overall_bit_rate>
    <Recorded_date>2004-03-28 15:42:35.000</Recorded_date>
    </track>
    
    <track type="Video">
    <ID>0</ID>
    <Format>DV</Format>
    <Commercial_name>DVCPRO</Commercial_name>
    <Codec_ID>dvsd</Codec_ID>
    <Codec_ID_Hint>Sony</Codec_ID_Hint>
    <Duration>1h 2mn</Duration>
    <Bit_rate_mode>Constant</Bit_rate_mode>
    <Bit_rate>24.4 Mbps</Bit_rate>
    <Encoded_bit_rate>28.8 Mbps</Encoded_bit_rate>
    <Width>720 pixels</Width>
    <Height>576 pixels</Height>
    <Display_aspect_ratio>4:3</Display_aspect_ratio>
    <Frame_rate_mode>Constant</Frame_rate_mode>
    <Frame_rate>25.000 fps</Frame_rate>
    <Standard>PAL</Standard>
    <Color_space>YUV</Color_space>
    <Chroma_subsampling>4:2:0</Chroma_subsampling>
    <Bit_depth>8 bits</Bit_depth>
    <Scan_type>Interlaced</Scan_type>
    <Scan_order>Bottom Field First</Scan_order>
    <Compression_mode>Lossy</Compression_mode>
    <Bits__Pixel_Frame_>2.357</Bits__Pixel_Frame_>
    <Time_code_of_first_frame>00:00:01:10</Time_code_of_first_frame>
    <Time_code_source>Subcode time code</Time_code_source>
    <Stream_size>12.6 GiB (94%)</Stream_size>
    <Encoding_settings>ae mode=full automatic / wb mode=automatic / white balance= / fcm=manual focus</Encoding_settings>
    </track>
    
    <track type="Audio">
    <ID>1</ID>
    <Format>PCM</Format>
    <Format_settings__Endianness>Little</Format_settings__Endianness>
    <Format_settings__Sign>Signed</Format_settings__Sign>
    <Codec_ID>1</Codec_ID>
    <Duration>1h 2mn</Duration>
    <Bit_rate_mode>Constant</Bit_rate_mode>
    <Bit_rate>1 536 Kbps</Bit_rate>
    <Channel_s_>2 channels</Channel_s_>
    <Sampling_rate>48.0 KHz</Sampling_rate>
    <Bit_depth>16 bits</Bit_depth>
    <Stream_size>688 MiB (5%)</Stream_size>
    <Alignment>Aligned on interleaves</Alignment>
    <Interleave__duration>40 ms (1.00 video frame)</Interleave__duration>
    <Interleave__preload_duration>40 ms</Interleave__preload_duration>
    </track>
    
    </File>
    </Mediainfo>
    

    添加可选参数-f 将产生更详细的信息。

    【讨论】:

    • 以及如何通过ffmpeg获取节目指南(EPG)?!
    • mediainfo 导出的内容不一定是ffmpeg 显示的“元数据”,例如标题、艺术家、曲目等。
    【解决方案5】:

    您可以在视频上设置元数据,下面提到设置专辑_艺术家

    ffmpeg -i source.mp4 -metadata album_artist='stack developer' -y -r 1 -acodec copy -vcodec copy destination.mp4
    

    并将元标记检索为:

    ffmpeg -i destination.mp4
    

    在命令行上使用它。

    【讨论】:

      【解决方案6】:

      假设我需要帧数和持续时间。要通过 MediaInfo cli 获取此信息,请使用此代码。MediaInfo --inform="Video;%FrameCount%,%Duration/String4%" videoname.mp4

      输出将是这样的 - 63525,00:42:21:00

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-11
        • 2013-01-30
        • 1970-01-01
        • 2016-03-15
        • 2020-10-22
        • 2018-05-28
        • 1970-01-01
        • 2017-01-24
        相关资源
        最近更新 更多