是否有Python库可以提取视频元数据,例如[标题、描述、说明文字/副标题]?

发布于 2025-01-15 02:15:33 字数 857 浏览 3 评论 0原文

我目前正在尝试寻找可以帮助我从视频文件(例如 [mp4、Mkv、Avi、WebM、mpg] 格式)中提取元数据或信息的 python 库。

我重点从视频文件中提取的主要数据主要是[标题、描述、评论、字幕/副标题]。

我尝试按照本指南使用 FFmpeg-python: https:// www.thepythoncode.com/article/extract-media-metadata-in-python

和 Tinytag,https:// /www.geeksforgeeks.org/access-metadata-of-various-audio-and-video-file-formats-using-python-tinytag-library/

来自我的据了解,FFmpeg-python 从 probe() 函数提供了最多的数据,但输出不包含 [Title, Description, Comment] 和 lined_captions > 只是“0”,我认为这是源轨道。

感谢您提供的任何帮助。

I'm currently trying to find python libraries that can assist me in extracting metadata or information from video files such as [mp4, Mkv, Avi, WebM, mpg] formats for example.

The main data that I'm focusing on extracting from the video files are mostly the [Title, Description, Comment, Captions/Subtitles].

I've tried using FFmpeg-python following this guide: https://www.thepythoncode.com/article/extract-media-metadata-in-python

and Tinytag, https://www.geeksforgeeks.org/access-metadata-of-various-audio-and-video-file-formats-using-python-tinytag-library/

From my understanding, FFmpeg-python provided the most data from the probe() function but the output does not contain [Title, Description, Comment] and closed_captions is simply '0' which I assume is the source track.

Thank you for any help provided.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事随风而去 2025-01-22 02:15:33

您可以使用 ffprobe 来获取元数据:

import subprocess as sp
import json
import pprint

out = sp.run(['ffprobe','-of','json','-show_entries', 'format:stream', videofile],\
             stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True)
results = json.loads(out.stdout)
metadata_format = results['format']['tags']
metadata_streams = [res['tags'] for res in results['streams']]

pprint(metadata_format) # "main" metadata: Title & Description found here
pprint(metadata_streams) # per-stream metadata

对于字幕/隐藏式字幕,您需要使用 ffmpeg 读取字幕流:

# get subtitle in webvtt format
out = sp.run(['ffmpeg','-i',videofile, '-map', 's:0', '-f','webvtt','-'],\
             stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True)
subtitle = out.stdout

然后您可以使用像 webvtt-py 解析字幕数据。 (我没有第一手经验,所以自己尝试一下。)

不过有一点需要注意。如果您的视频是 DVD rip,则其字幕流 (dvd_subtitle) 是位图而不是文本,并且 FFmpeg 无法将其转换为文本数据。

You can use ffprobe to get the metadata:

import subprocess as sp
import json
import pprint

out = sp.run(['ffprobe','-of','json','-show_entries', 'format:stream', videofile],\
             stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True)
results = json.loads(out.stdout)
metadata_format = results['format']['tags']
metadata_streams = [res['tags'] for res in results['streams']]

pprint(metadata_format) # "main" metadata: Title & Description found here
pprint(metadata_streams) # per-stream metadata

For the substitles/closed-captions, you need to read the subtitle streams with ffmpeg:

# get subtitle in webvtt format
out = sp.run(['ffmpeg','-i',videofile, '-map', 's:0', '-f','webvtt','-'],\
             stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True)
subtitle = out.stdout

Then you can use a library like webvtt-py to parse the subtitle data. (I don't have firsthand experience, so try it yourself.)

One caveat though. If your video is a DVD rip, then its subtitle streams (dvd_subtitle) are bitmaps and not text, and FFmpeg cannot convert it to a text data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文