php-ffmpeg运用 合并视频,转码视频

下载

官网

windows 版本

添加环境变量

合并视频

php 复制代码
    public function test_that_true_is_true(): void
    {

        ini_set('memory_limit',-1); //没有内存限制
        set_time_limit(0);//不限制执行时间
        //ffmpeg配置
        $path = [
            'ffmpeg.binaries'  => 'D:\soft\ffmpeg\bin/ffmpeg.exe',
            'ffprobe.binaries' => 'D:\soft\ffmpeg\bin/ffprobe.exe',
            'timeout' => 3600,//基础进程的超时
            'ffmpeg.threads' => 12//FFMpeg应使用的线程数
        ];
        $video1Path = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/1out.mp4';
        $video2Path = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/2out.mp4';
        $outputPath = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/result.mp4';

// 创建FFMpeg对象
        $ffmpeg = FFMpeg::create($path);

// 打开第一个视频文件
        $video1 = $ffmpeg->open($video1Path);

// 打开第二个视频文件
//        $video2 = $ffmpeg->open($video2Path);

// 合并视频
        $video1->concat([$video2Path,$video2Path])
            ->saveFromSameCodecs($outputPath, TRUE);

//        $video1->save(new X264(),$outputPath);

        $this->assertTrue(true);
    }

转码

php 复制代码
    /**
     * 转码
     * @return void
     */
    public function testFormat(){
        $path = [
            'ffmpeg.binaries'  => 'D:\soft\ffmpeg\bin/ffmpeg.exe',
            'ffprobe.binaries' => 'D:\soft\ffmpeg\bin/ffprobe.exe',
            'timeout' => 3600,//基础进程的超时
            'ffmpeg.threads' => 12//FFMpeg应使用的线程数
        ];
        $video1Path = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/1.mp4';
        $video2Path = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/2.mp4';
        $outputPath = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/result.mp4';

// 创建FFMpeg对象
        $ffmpeg = FFMpeg::create($path);
// 输入视频文件路径
        $inputVideo = $ffmpeg->open($video2Path);

// 转码并设置输出路径和格式
        $outputVideo = 'C:\Users\DELL\Desktop\我的工作目录\猪獾\视频/2out.mp4';

        $inputVideo->save(new X264(), $outputVideo);

    }

命令的基本用法

cmd 封装成php

php-ffmpeg 使用

相关推荐
AC赳赳老秦11 小时前
DBA 专属方案:用 OpenClaw 实现 SQL 语句优化、慢查询分析、数据库备份巡检全自动化
服务器·前端·数据库·ffmpeg·自动化·deepseek·openclaw
小叮当⇔1 天前
M4A 转 MP3 桌面转换器(PyQt5 + FFmpeg)
开发语言·qt·ffmpeg
aovenus4 天前
FFmpeg 官网及文档
ffmpeg
aovenus4 天前
FFmpeg 工具介绍
ffmpeg
jr-create(•̀⌄•́)5 天前
简单视频编辑tools
python·ffmpeg
山栀shanzhi5 天前
在做直播时,I帧的间隔(GOP)一般是多少?
网络·c++·面试·ffmpeg
weixin_421607556 天前
SRT字幕驱动视频自动分镜切割:电影解说批量生成的工程实现思路
ffmpeg·srt字幕·ai剪辑·影视解说·ai电影解说·视频自动切割·字幕文件解析
相偎6 天前
arm平台编译mpp、ffmpeg和xfreerdp
arm开发·ffmpeg
LoyalToOrigin6 天前
iOS 26 libass字幕渲染问题兼容解决实践
ios·ffmpeg·objective-c
siv777 天前
影视解说视频智能生产全链路方案解析:从脚本生成到多平台分发
ffmpeg·srt字幕·ai剪辑·影视解说·ai电影解说·视频自动切割·字幕文件解析