查找远程媒体文件的视频分辨率和视频持续时间

发布于 2024-12-28 05:14:33 字数 590 浏览 3 评论 0原文

我想编写一个程序,可以找到媒体文件的一些元信息。我对流行的视频格式感兴趣,例如 avi、mkv、mp4、mov(也可能是其他流行的)。我基本上想得到:

  • 视频大小(720、1080、360 等)
  • 视频的总运行时间(可能不是很准确)
  • 音频流的数量
  • 视频编解码器的名称 音频
  • 编解码器的名称

已经有 mediainfo,但在我的程序中我想获取有关远程文件的信息,可以通过ftp、http、samba访问该文件;甚至 torrent(有一些 torrent 解决方案,允许读取尚未下载的文件)。

MediaInfo 库不支持 samba (smb://) 和 mkv 格式(用于运行时)。

另外,我想知道,需要下载多少数据才能获取此信息。我不想下载完整的视频文件,因为我没有足够的磁盘空间。

此信息是否位于文件的前 1 或 10 或 100 KB 中?如果我知道容器名称和总文件大小,它的偏移量是否可以预测?

PS:平台是Linux,语言是C/C++

I want to write an program which can find some metainformation of mediafile. I'm interested in popular video formats, such as avi, mkv, mp4, mov (may be other popular too). I want basically to get:

  • Video size (720, 1080, 360 etc)
  • Total runtime of video (may be not very exact)
  • Number of audio streams
  • Name of video codec
  • Name of audio codec

There is already the mediainfo, but in my program I want to get information about remote file, which may be accessed via ftp, http, samba; or even torrent (there are some torrent solutions, which allows to read not-yet downloaded file).

MediaInfo library have no support of samba (smb://) and mkv format (for runtime).

Also, I want to know, how much data should be downloaded to get this information. I want not to download full videofile because I have no enough disk space.

Is this information in the first 1 or 10 or 100 KiloBytes of the file? Is it at predictable offset if I know the container name and total file size?

PS: Platform is Linux, Language is C/C++

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

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

发布评论

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

评论(3

岁月染过的梦 2025-01-04 05:14:33

不,您无法从文件的“前 X 字节”中预见性地找到您要查找的信息(对于小于媒体文件完整大小的任何已知 X 值)。有些容器在标头中列出了所有这些信息。有些(如 QuickTime)将元数据放在文件末尾,元数据偏移量放在文件头中。有些(如 AVI)会在标头中列出流偏移量,并在每个流的标头中列出特定的流信息(即分散在整个文件中)。有些根据编码方法使用不同的样式(例如,快速流式传输与即时编码)。

也就是说,通过请求适当的字节范围,理论上可以完成您正在寻找的事情。例如,请求前 10K 左右,并根据容器类型,解析出您需要读取/解析的其他字节范围以查找元数据。但这将是一个相当大的项目。

No, you can't predictably find the information you're looking for from the "first X bytes" of the file (for any known value of X less than the full size of the media file). Some containers list all of that info in the header. Some (like QuickTime) have that metadata at the end of the file with the metadata offset in the header. Some (like AVI) list stream offsets in the header, with specific stream info in each stream's header (i.e., scattered throughout the file). And some use different styles depending on the encoding method (e.g., quick streaming vs. on-the-fly encoding).

That said, it's theoretically possible to do what you're looking for, by requesting the appropriate byte ranges. For example, request the first 10K or so, and based on the container type, parse out which other byte ranges you'd need to read/parse in order to find the metadata. But it would be a pretty big project.

好多鱼好多余 2025-01-04 05:14:33

这取决于容器格式,avi / mp4 / mkv

查看源代码 http://mediainfo.sourceforge。网/en

It depends on the container format, avi / mp4 / mkv

Take a look at the source to http://mediainfo.sourceforge.net/en

亢潮 2025-01-04 05:14:33

一般情况下根本无法判断。这一切都取决于远程文件的容器格式,即使如此,您可能也需要跳过很多麻烦才能从 50% 的文件中获取所有元数据。将自己限制在 ISO 媒体(QuickTime、MPEG-4、3GPP 等)上,您可以获得更高的点击率,但即便如此,它也不是显而易见的。

There's simply no way to tell in the general case. It all depends on the container format of the remote file, and even then, you'll probably need to jump through a lot of hoops to get all of that metadata from even 50% of files. Restrict yourself to ISO media (QuickTime, MPEG-4, 3GPP &c.) and you can get that hit rate up higher, but even then it's non-obvious.

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