apefood / simplevc
将视频/音频文件转换为网页友好格式
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-28 18:53:17 UTC
README
这是什么?
SimpleVC 是一个 PHP 音频和视频转换器
为什么?
这里的想法是提供一个简单的方式来处理不同浏览器对不同音频和视频格式的支持。不幸的是,由于不同的原因,不同的网络浏览器往往支持不同的音频和视频格式。这意味着为了确保您的音频/视频对每个人都是可访问的,您必须提供回退选项,然后不同的浏览器可以以对它们友好的任何格式显示它。如果您可以只提供您拥有的任何格式的音频/视频文件,而不必担心它是否会在Firefox或Chrome或其他浏览器上播放,那就太好了。这就是SimpleVC的核心所在。只需提供您拥有的任何格式的音频/视频文件,让SimpleVC为您创建和渲染回退选项。
如何?
SimpleVC 通过优秀的 [FFmpeg] (https://ffmpeg.net.cn/ffmpeg.html) 库来完成所有操作。
要求
- PHP 5.4+
- FFmpeg(版本:N-71455-gfbdaebb)
快速指南
您需要做的第一件事是将SimpleVC添加为项目的依赖项。
- 使用 [Composer] (https://composer.php.ac.cn) 安装:
composer require apefood/simplevc
现在您可以使用SimpleVC的方法和类,例如
示例 1:视频转换
// file to convert * $filename = /path/to/video/file/; // instantiate video object * $video = new Video($filename); // instantiate video converter object * $video_converter = new VideoConverter($video); // get the ffmpeg conversion command * $command = $video_converter->convert();
convert() 方法返回ffmpeg命令作为字符串,这意味着最终您将决定如何使用它。转换过程较慢,因此您可能希望将此命令作为作业/任务进行调度,而不是立即在命令上运行exec()。
// get html5 video's <source> tags for the video file & it's associated fall-back options. $html = new HtmlFactory($video); $source = $html->render();
由于exec()命令将被延迟执行,因此不会立即运行,这意味着$source变量现在至少指向2个不存在的文件。因此,您还可以将视频在网页上的发布推迟到转换任务完成。
提取视频帧
此命令可以帮助您提取视频帧并将它们保存为图像。然后您可以使用这些图像作为视频的预览内容。
// Time on the video where you want to start extracting the frames. // Defaults to null, in which case FFmpeg will start the extraction from beginning of the video. $start = "01:00"; // from minute 1 [hh]:mm:ss // Stop the extraction after t = $end. Note that if you don't provide the $start argument, it's pointless // to specify an $end parameter since the VideoConverter class will just override it to null. $end = "03:00"; // stop after 3 minutes // How many frames per minute would you like to extract? $frames = 2; // Your preferred image format. Defaults to JPEG. $format = "jpeg"; $video_frames = $video_converter->extractFrames($start, $end, $frames, $format);
同样,这只会返回完成此任务所需的FFmpeg命令 [字符串]。您需要自己决定何时以及如何实际在shell上执行此命令(即$ php exec($video_frames);)。
示例 2:音频转换
没有示例 2,因为它基本上与示例 1相同,但使用音频文件。基本上将每个“视频”实例替换为“音频”即可。
##警告!
禁止使用3GP文件!
当我尝试将3GP文件转换为MP4时失败了,多次尝试都是如此。因此,不要使用此包与3GP文件一起使用。实际上,我建议您坚持使用流行的媒体格式(例如MP3/4、MKV、WAV等),以确保安全。2016年,为什么您还会有3GP文件呢?