FFMPEG 비디오 변환을 위한 PHP 클래스
<?php class local_video { public $options; public $ffmpeg; public $phpcms_path; public $backup; function __construct($options,$ffmpeg,$backup=true) { $this->opti $this->options = array_filter($options) + $this->options; $this->ffmpeg=$ffmpeg; //ffmpeg路径 $this->backup=$backup; } //获取视频信息 function video_info($file) { ob_start(); passthru(sprintf($this->ffmpeg . ' -i "%s" 2>&1', $file));//ffmpeg -i test.avi 2>&1 $info = ob_get_contents(); ob_end_clean(); // 通过使用输出缓冲,获取到ffmpeg所有输出的内容。 $ret = array(); // Duration: 01:24:12.73, start: 0.000000, bitrate: 456 kb/s if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/",$info, $match)) { $ret['duration'] = $match[1]; // 提取出播放时间 $da = explode(':', $match[1]); $ret['seconds'] = $da[0] * 3600 + $da[1] * 60 + $da[2]; // 转换为秒 $ret['start'] = $match[2]; // 开始时间 $ret['bitrate'] = $match[3]; // bitrate 码率 单位 kb } // Stream #0.1: Video: rv40, yuv420p, 512x384, 355 kb/s, 12.05 fps, 12 tbr, 1k tbn, 12 tbc if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $info, $match)) { $ret['vcodec'] = $match[1]; // 编码格式 $ret['vformat'] = $match[2]; // 视频格式 $ret['resolution'] = $match[3]; // 分辨率 $a = explode('x', $match[3]); $ret['width'] = $a[0]; $ret['height'] = $a[1]; } // Stream #0.0: Audio: cook, 44100 Hz, stereo, s16, 96 kb/s if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) { $ret['acodec'] = $match[1]; // 音频编码 $ret['asamplerate'] = $match[2]; // 音频采样频率 } if (isset($ret['seconds']) && isset($ret['start'])) { $ret['play_time'] = $ret['seconds'] + $ret['start']; // 实际播放时间 } $ret['size'] = filesize($file); // 文件大小 return $ret; } function convert() { $verifyToken = md5('unique_salt' . $this->options['timestamp']); if ($verifyToken == $this->options['token']) { $orgFile = $this->options['org_path'] . $this->options['org']; $setting=' '; if(isset($this->options['video_size'])) $setting=$setting.'-vf scale="'.$this->options['video_size'].'"'; $mp4 = $this->ffmpeg . ' -i ' . $orgFile . ' -ss 00:01:02 -vcodec libx264 -strict -2 '.$setting.' ' . $this->options['mp4_path_temp'] . $this->options['org'] . ''; //转换视频 exec($mp4); if(isset($this->options['watermark'])){ $watermark=' "'.$this->options['watermark'].'" '; $mp4 = $this->ffmpeg.' -i '.$this->options['mp4_path_temp'] . $this->options['org'] . ''.' -vf '.$watermark.' '.$this->options['mp4_path'] . $this->options['org'] . ''; //增加水印 exec($mp4); @unlink($this->options['mp4_path_temp'] . $this->options['org'] . ''); } $duration = $this->video_info($orgFile); $seconds = intval($duration['seconds']); $offset = intval($seconds / 21); //截图间隔 秒 $thumbs = explode(',', $this->options['thumb_size']); for ($i = 0; $i <= count($thumbs); $i++) { $targetPath = $this->options['thumb_path'] . $this->options['org'] . '/'; if (!file_exists($targetPath)) @mkdir(rtrim($targetPath, '/'), 0777); if ($i == 0) { $time = 1; $name = $i == 0 ? 'default.jpg' : $i . '.jpg'; $img_size = $this->options['main_size']; } else { $time = $i * $offset; $name = $i . '.jpg'; $img_size = $thumbs[$i-1]; } $jpg = $this->ffmpeg . ' -i ' . $orgFile . ' -f image2 -ss ' . $time . ' -vframes 1 -s ' . $img_size . ' ' . $targetPath . $name; //截图 @exec($jpg); } //复制文件到对应的FTP服务器 $ftp_server = pc_base::load_config('ftp_server'); $remote_server = $_POST['remote_server']; $ftp_server = $ftp_server[$remote_server]; if($ftp_server['ftp_server']) pc_base::ftp_upload($orgFile, $ftp_server['ftp_server'], $ftp_server['ftp_user_name'], $ftp_server['ftp_user_pass']); //备份到所有FTP服务器 if($this->backup){ $ftp_backup = pc_base::load_config('ftp_backup'); foreach ($ftp_backup as $v) { pc_base::ftp_upload( $orgFile, $ftp_backup['ftp_server'], $ftp_backup['ftp_user_name'], $ftp_backup['ftp_user_pass']); } } $result['url']=$ftp_server['ftp_server']['http_address']. $this->options['mp4_path'] . $this->options['uniqid'] . '.mp4';//记录视频播放地址 $result['uniqid']=$this->options['uniqid']; $result['videoTime'] = $this->video_info($orgFile); $result['videoTime'] = $result['videoTime']['seconds']; return $result;//返回处理结果 } else die('验证失败!'); } } ?>
참고
http://www.fieryrain.com/blog/FFMPEG_VIDEO_TIME
http://keren. iteye.com/blog/1773536
http://www.cnblogs.com/dwdxdy/p/3240167.html
http://www.cnblogs. com/chen1987lei/archive/2010/12/03/1895242.html
위 내용은 다양한 측면을 포함하여 FFMPEG 비디오 변환을 위한 PHP 클래스를 소개하고 있어 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











1. nginx 설치 2. vsftpd 설치 3. nginx 구성 파일 nginx.conf 수정 3.1 첫 번째 줄에 ftp 사용자 userftpuser 추가 3.2 관련 경로 서버 구성{ Listen80; #ftp 서버 주소 위치; Images{ root /home/ftpuser; #프록시 FTP 서버 폴더의 절대 경로 indexftpuser #환영 페이지 설정

인터넷의 급속한 발전과 함께 파일 전송 프로토콜(FTP)은 항상 중요한 파일 전송 방법이었습니다. Go 언어에서는 FTP를 사용하여 파일을 전송하는 것이 많은 개발자에게 필요할 수 있습니다. 하지만 Go 언어에서 FTP를 사용하는 방법을 모르는 사람들이 많을 수도 있습니다. 이번 글에서는 FTP 서버 연결부터 파일 전송까지 Go 언어로 FTP를 사용하는 방법과 오류 및 예외 처리 방법을 살펴보겠습니다. FTP 연결 생성 Go 언어에서는 표준 "net" 패키지를 사용하여 FTP에 연결할 수 있습니다.

Linux의 ftp 명령에는 1. ftp 명령, 3. 연결 끊기 명령, 5. 계정 명령, 8. 종료 명령, 명령 ;10. rhelp 명령; 11. ASCII 명령 13. 벨 명령 등

PHP 및 FTP: 웹 사이트 개발 시 여러 부서 간에 파일 공유를 달성합니다. 인터넷이 발전하면서 점점 더 많은 회사가 정보 공개 및 비즈니스 홍보를 위해 웹 사이트 플랫폼을 사용하기 시작했습니다. 그러나 발생하는 문제는 여러 부서 간의 파일 공유 및 협업을 어떻게 달성할 수 있느냐는 것입니다. 이 경우 PHP와 FTP는 가장 일반적으로 사용되는 솔루션 중 하나가 됩니다. 이 기사에서는 PHP와 FTP를 사용하여 웹 사이트 개발 시 여러 부서 간에 파일을 공유하는 방법을 소개합니다. 1. FTP 소개 FTP(FileTransferPr

PHP를 통해 FTP 서버의 디렉터리와 파일을 비교하는 방법 웹 개발에서 때로는 로컬 파일과 FTP 서버의 파일을 비교하여 둘 사이의 일관성을 확인해야 할 때가 있습니다. PHP는 이 기능을 구현하기 위한 몇 가지 함수와 클래스를 제공합니다. 이 기사에서는 PHP를 사용하여 FTP 서버의 디렉터리와 파일을 비교하는 방법을 소개하고 관련 코드 예제를 제공합니다. 먼저 FTP 서버에 연결해야 합니다. PHP는 FTP 서버를 구축하기 위해 ftp_connect() 함수를 제공합니다.

WindowsServerBackup은 WindowsServer 운영 체제와 함께 제공되는 기능으로, 사용자가 중요한 데이터 및 시스템 구성을 보호하고 중소기업 및 대기업 수준의 기업에 완벽한 백업 및 복구 솔루션을 제공하도록 설계되었습니다. Server2022 이상을 실행하는 사용자만 이 기능을 사용할 수 있습니다. 이 문서에서는 WindowsServerBackup을 설치, 제거 또는 재설정하는 방법을 설명합니다. Windows Server 백업을 재설정하는 방법 서버 백업에 문제가 있거나 백업에 너무 오랜 시간이 걸리거나 저장된 파일에 액세스할 수 없는 경우 Windows Server 백업 설정을 재설정하는 것을 고려할 수 있습니다. Windows를 재설정하려면

linux ftp530은 linux ftp 로그인 오류 530을 의미합니다. 해결 방법은 다음과 같습니다. 1. "cat /etc/shells"를 확인하여 사용자의 홈 디렉터리와 로그인 셸이 있는지 확인합니다. 그렇지 않으면 이를 추가합니다. 2. "/var /log"를 확인합니다. /secure" 파일을 삭제하고 비밀번호 만료 시간을 재설정하세요.

FTP 소개 FTP는 파일 전송 프로토콜(FileTransferProtocol)로, 네트워크에서의 파일 전송을 위한 표준 프로토콜입니다. FTP 클라이언트는 로컬에서 서버로 파일을 업로드하거나 서버에서 로컬로 다운로드할 수 있습니다. ftplib 모듈 Python은 Python에서 FTP 클라이언트 기능을 구현하기 위한 표준 라이브러리 ftplib를 제공합니다. ftplib를 사용하면 FTP 서버에 연결하여 파일 업로드, 다운로드 등 다양한 FTP 작업을 수행할 수 있습니다. 코드 설명 다음은 Python을 사용하여 FTP를 통해 파일을 업로드하는 샘플 코드입니다. fromftplibimportFTPimportargparsed
