使用FFMpeg确定视频类型,然后进行转换?

发布于 2024-09-28 06:55:33 字数 1124 浏览 6 评论 0原文

我正在尝试以编程方式确定文件的真实类型。看来我必须使用 FFMPeg 来实现这一点。

我想确定上传的文件实际上是否是 MP4 或 FLV(对于 Flash 视频)[或 WebM(对于 HTML5)]。我知道 FFMPeg 中的 -i 运算符,但我不知道要检查什么。

例如:

Input #0, flv, from 'c:\www\data.aspbooru\image\0\40c24ba424d1334ef81c88c416ce794e.flv':

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'c:\www\data.aspbooru\image\0\8c1a747b5188349d92cca17a502d2d57.mp4':

这些是 FFMPeg 输出。这就是我在过滤 Flash 视频时需要检查的全部内容吗?

所以,如果这些都不适用。如何检查 swf 文件?

Input #0, swf, from 'c:\www\data.aspbooru\image\0\90447bd30d30ccb1474c0433e948d438.swf':
Duration: 00:07:16.08, start: 0.000000, bitrate: 63 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, 2 channels, s16, 64 kb/s
Stream #0.1: Video: flv, yuv420p, 320x240, 25 fps, 25 tbr, 25 tbn, 25 tbc

检查 Input #0, swf, 是否足够?它提取了我不想要的包含的 flv。

现在我还需要检查完全不是视频的文件类型和视频文件类型,但可以使用 h.264(或 Webm?)转换为 mp4 我完全不知道如何做到这一点。

转换的事情是可以管理的,但是有关这方面的提示也非常酷(转换 h.264 和 webm?)。

我输入一个随机文件。是这个吗? c:\web.config:处理输入时发现无效数据

编辑:未指定编程语言,因为它独立于任何编程语言。但我会很感激特定于语言的输入:VB.NET。您可以假设我已经有了流程逻辑,并且输出以字符串形式存在!正则表达式也很酷:)

I'm trying to determine the real type of a file programmatically. It seems I have to use for example FFMPeg for that.

I want to determine if an uploaded file is in fact a MP4 or FLV (for flash videos) [or WebM (for HTML5)]. I know the -i operator in FFMPeg but I don't know what to check for.

For example:

Input #0, flv, from 'c:\www\data.aspbooru\image\0\40c24ba424d1334ef81c88c416ce794e.flv':

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'c:\www\data.aspbooru\image\0\8c1a747b5188349d92cca17a502d2d57.mp4':

Those are FFMPeg outputs. Is this all I have to check for when filtering videos for flash?

So, if none of those apply. How do I check for a swf file?

Input #0, swf, from 'c:\www\data.aspbooru\image\0\90447bd30d30ccb1474c0433e948d438.swf':
Duration: 00:07:16.08, start: 0.000000, bitrate: 63 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, 2 channels, s16, 64 kb/s
Stream #0.1: Video: flv, yuv420p, 320x240, 25 fps, 25 tbr, 25 tbn, 25 tbc

Is checking for Input #0, swf, enough? It extracts an included flv which I dont want.

Now I also need to check for file types which are completely NOT videos and filetypes which are videos, but could be converted to a mp4 with h.264 (Or Webm?)
I have completely no clue how to do this.

The conversion thing can be managed, but hints on that would be very cool too (converting h.264 and webm?).

I input a random file. Is this it?
c:\web.config: Invalid data found when processing input

EDIT: No programming language specified because it is independent of any programming language. But I would be grateful for language specific input: VB.NET. You can assume I already have the process logic and the output is there as a string! Regex would be cool too :)

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

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

发布评论

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

评论(2

合约呢 2024-10-05 06:55:33

确定类型

MediaInfo 可能会带来更好的运气。

获取命令行版本并按如下方式使用它:

mediainfo --full --language=raw --output=xml

这会提供 XML 输出,然后您可以使用 XPath 获取 Codec 字段。
或者,如果您不喜欢 XML,请删除“--output=xml”,然后编写正则表达式来解析文本输出。

对于无法识别的文件,它看起来会提供一些输出,但肯定不会有“编解码器”字段。

转换视频

对于实际转换视频,FFmpeg 是视频编码领域的瑞士军刀,可能是您的最佳选择。

您不需要真正了解输入,只要知道您想要什么输出编解码器即可。

像这样的东西可以帮助您开始:

ffmpeg -i input.mov -vcodec libx264 -acodec libfaac -f mov out.mp4

这将为您提供带有 H.264 视频和 AAC 音频的 MPEG-4。
尽管有很多选项可以调整它以获得您想要的结果。

此网站对于调整 H.264 选项非常有用。

祝你好运!

Determining Types

You might have better luck with MediaInfo.

Grab the command line version and use it like this:

mediainfo --full --language=raw --output=xml

This gives XML output, you can then use XPath to grab the Codec field.
Or if XML is not your thing drop the '--output=xml' then write a regex to parse the text output.

For non recognised files it looks like it gives some output but certainly won't have a Codec field.

Converting videos

For actually converting videos FFmpeg is the Swiss Army Knife of video encoding and is probably your best option.

You don't need to know the input really as long as you know what output codecs you want.

Something like this can get you started:

ffmpeg -i input.mov -vcodec libx264 -acodec libfaac -f mov out.mp4

That will give you a MPEG-4 with H.264 video and AAC audio.
Although there are many options available to tune this to get what you want.

This site is useful for tuning H.264 options.

Good luck!

情感失落者 2024-10-05 06:55:33

我会尝试一些库,因为您将获得比正则表达式更好的结果并自己确定:

C#/.NET 的实体 FFmpeg 包装器

I would give some libraries a try as you're going to get better results than Regex and determining such for yourself:

Solid FFmpeg wrapper for C#/.NET

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