123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace app\admin\model;
- use FFMpeg\Coordinate\Dimension;
- use FFMpeg\Coordinate\FrameRate;
- use FFMpeg\Coordinate\TimeCode;
- use FFMpeg\FFMpeg;
- use FFMpeg\FFProbe;
- use FFMpeg\Format\Audio\Flac;
- use FFMpeg\Format\Video\WMV;
- use FFMpeg\Format\Video\X264;
- class Video
- {
- private static $ffmpeg = app_paths."ffmpeg/bin/ffmpeg.exe";
- private static $ffprobe = app_paths."ffmpeg/bin/ffprobe.exe";
- private static $file_img=Pah."/storage/videoimg/";
- public static function ffmpeg_getTime($file)
- {
- $ffmpeg = FFMpeg::create([
- 'ffmpeg.binaries' => self::$ffmpeg ,
- 'ffprobe.binaries' => self::$ffprobe,
- ]);
- $video = $ffmpeg ->open($file);
- $frame = $video->frame(TimeCode::fromSeconds(2));
- $time=time();
- $file_name=self::$file_img.$time.".png";
- $frame->save($file_name);
- $data["img"]="/storage/videoimg/".$time.".png";
- $dimension=self::video_time($file);
- $data["seconds"]=$dimension;
- return $data;
- }
- public static function video_time($file) {
- define('FFMPEG_PATH', self::$ffmpeg.' -i "%s" 2>&1');
- ob_start();
- passthru(sprintf(FFMPEG_PATH, $file));
- $info = ob_get_contents();
- ob_end_clean();
-
- $ret = array();
-
- if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {
- $arr_dian = explode('.', $match[1]);
- $arr_duration = explode(':', $arr_dian[0]);
- $seconds = $arr_duration[0] * 3600 + $arr_duration[1] * 60 + $arr_duration[2];
- return $seconds;
- }
- return 0;
- }
-
- public static function getVideoInfo($file) {
- define('FFMPEG_PATH', self::$ffmpeg.' -i "%s" 2>&1');
- $command = sprintf(FFMPEG_PATH, $file);
- ob_start();
- passthru($command);
- $info = ob_get_contents();
- ob_end_clean();
- $data = array();
- if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {
- $data['duration'] = $match[1];
- $arr_duration = explode(':', $match[1]);
- $data['seconds'] = $arr_duration[0] * 3600 + $arr_duration[1] * 60 + $arr_duration[2];
- $data['start'] = $match[2];
- $data['bitrate'] = $match[3];
- }
- if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $info, $match)) {
- $data['vcodec'] = $match[1];
- $data['vformat'] = $match[2];
- $data['resolution'] = $match[3];
- $arr_resolution = explode('x', $match[3]);
- $data['width'] = $arr_resolution[0];
- $data['height'] = $arr_resolution[1];
- }
- if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) {
- $data['acodec'] = $match[1];
- $data['asamplerate'] = $match[2];
- }
- if (isset($data['seconds']) && isset($data['start'])) {
- $data['play_time'] = $data['seconds'] + $data['start'];
- }
- return $data;
- }
-
- public function file_con($file)
- {
- $ffmpeg = FFMpeg::create([
- 'ffmpeg.binaries' => self::$ffmpeg ,
- 'ffprobe.binaries' => self::$ffprobe,
- "timeout"=>3600,
- "ffmpeg.threads"=>12,
- ]);
- $video=$ffmpeg->open(Pah.$file);
- $this->video_size($ffmpeg,$video);
- }
-
- public function video_size($ffmpeg,$video)
- {
- $saves=Pah."storage/zhuan/text26.mp4";
- $video->filters()->resize(new Dimension(750, 400),"inset");
- $video->save(new X264("aac"),$saves);
- }
-
- public static function mp4_video($file)
- {
- $saves=Pah."storage/zhuan/texts11.mkv";
- $ffmpeg = FFMpeg::create([
- 'ffmpeg.binaries' => self::$ffmpeg ,
- 'ffprobe.binaries' => self::$ffprobe,
- "timeout"=>3600,
- "ffmpeg.threads"=>12,
- ]);
- $video=$ffmpeg->open(Pah.$file);
- $video->filters()->resize(new Dimension(750, 400),"inset")->framerate(new FrameRate(10),1)->synchronize();
- $video->save(new X264("aac"),$saves);
- dump(1212);
- }
-
- }
|