编程语言
首页 > 编程语言> > php FFmpeg插件dome

php FFmpeg插件dome

作者:互联网

前端使用vue 该文件改于 https://juejin.im/post/5b6960d8e51d4519115d5d2f 提供的vue页面

修改后的 地址 https://github.com/August-the-feel/FFmpeg.git

修改内容 : 进行 http 请求页面 使用php-FFmpeg插件进行裁剪 截图

 

裁剪

 1 public function actionShearedit()
 2 {
 3     $ffmpeg = FFMpeg::create(array(
 4         'ffmpeg.binaries' => '/www/ffmpeg/bin/ffmpeg', //ffmpeg插件在服务器的位置
 5         'ffprobe.binaries' => '/www/ffmpeg/bin/ffprobe', //ffprobe插件在服务器的位置
 6         'timeout' => 3600, // The timeout for the underlying process
 7         'ffmpeg.threads' => 12,   // The number of threads that FFMpeg should use
 8     ), $logger);
 9     $video_file = $model->base_url;
10     $ffprobe_prep = FFProbe::create([
11         'ffmpeg.binaries' => '/www/ffmpeg/bin/ffmpeg', //ffmpeg插件在服务器的位置
12         'ffprobe.binaries' => '/www/ffmpeg/bin/ffprobe', //ffprobe插件在服务器的位置
13     ]);
14     $first = $ffprobe_prep->streams($video_file)->videos()->first();
15     $start = Yii::$app->request->get('startTime', null);//开始时间
16     $end = Yii::$app->request->get('endTime', null);//结束时间
17     $start_time = gmstrftime('%H:%M:%S', $start);//开始时间
18     $process_time = $end - $start;//持续时间
19     $hosturl = ($this->isHTTPS() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];
20     $fileurl = '/attachment/ffmpeg_videos/'.substr($video_file,strrpos($video_file, '/')+1);
21     $shell = 'ffmpeg -ss  ' . $start_time . ' -i ' . $video_file . ' -to ' . $process_time . ' -c copy '.$_SERVER['DOCUMENT_ROOT'].$fileurl;
22     // dd($shell);
23     shell_exec($shell);
24     $attachment = new Attachment;
25     $attachment->base_url=$hosturl.$fileurl;
26     $attachment->merchant_id=$model->merchant_id;
27     $attachment->drive=$model->drive;
28     $attachment->upload_type=$model->upload_type;
29     $attachment->specific_type=$model->specific_type;
30     $attachment->path=$model->path;
31     $attachment->name=$model->name;
32     $attachment->type=$model->type;
33     $attachment->reporter_id=$model->reporter_id;
34     $attachment->extension=$model->extension;
35     $attachment->year=date('Y');
36     $attachment->month=date('m');
37     $attachment->day=date('d');
38     $attachment->width=$model->width;
39     $attachment->height=$model->height;
40     $attachment->upload_ip=$model->upload_ip;
41     $attachment->status=$model->status;
42     $attachment->created_at=$model->created_at;
43     $attachment->updated_at=$model->updated_at;
44     $attachment->size=filesize($_SERVER['DOCUMENT_ROOT'].$fileurl);
45     // dd($attachment);
46     $sign=$attachment->save();
47     if($sign){
48         return 2;
49     }else{
50         return 1;
51     }
52 }
53 private function isHTTPS()
54 {
55     if (defined('HTTPS') && HTTPS) return true;
56     if (!isset($_SERVER)) return FALSE;
57     if (!isset($_SERVER['HTTPS'])) return FALSE;
58     if ($_SERVER['HTTPS'] === 1) {  //Apache
59         return TRUE;
60     } elseif ($_SERVER['HTTPS'] === 'on') { //IIS
61         return TRUE;
62     } elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
63         return TRUE;
64     }
65     return FALSE;
66 }

截图(截图某一秒)

 1 /**
 2      * description: 返回视频裁剪 选择秒的画面
 3      * create by: 八月情
 4      * create time: 2021-01-15 15:30
 5      * environment: localhost
 6      */
 7     public function actionLookoppic()
 8     {12         $ffmpeg = FFMpeg::create(array(
13             'ffmpeg.binaries' => '/usr/bin/ffmpeg',//linux 安装ffmpeg的位置 可以通过 which ffmpeg 进行查看
14             'ffprobe.binaries' => '/usr//bin/ffprobe',//linux 安装ffprobe的位置 可以通过 which ffprobe 进行查看
15             'timeout' => 3600, // The timeout for the underlying process
16             'ffmpeg.threads' => 12,   // The number of threads that FFMpeg should use
17         ), $logger);
18 
19         $video = $ffmpeg->open('文件路径');
20 
21         $video_file = $model->base_url;
22         $ffprobe_prep = FFProbe::create([
23             'ffmpeg.binaries' => '/usr/bin/ffmpeg',//linux 安装ffmpeg的位置 可以通过 which ffmpeg 进行查看
24             'ffprobe.binaries' => '/usr//bin/ffprobe',//linux 安装ffprobe的位置 可以通过 which ffprobe 进行查看
25             ]);
26         $first = $ffprobe_prep->streams($video_file)->videos()->first();
27         $time = $first->get('duration', null);//获取视频长度
28         $start = $first->get('start', null);//接受视频的时间
29         $start_time = gmstrftime('%H:%M:%S', $start);//将长度转换为秒数
30         $frame = $video->frame(TimeCode::fromSeconds($start_time)); //提取第几秒的图像37     }

 

实测可以用 具体内容根据自己的需求修改 该文章仅提供参考  

Linux安装FFmpeg插件 查看 https://www.cnblogs.com/ForAll-I-Care/p/14428358.html

php-ffmpeg/php-ffmpeg 地址 composer require php-ffmpeg/php-ffmpeg

 

 

标签:插件,return,FFmpeg,ffprobe,start,attachment,model,php,ffmpeg
来源: https://www.cnblogs.com/ForAll-I-Care/p/14452956.html