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

下载

官网

windows 版本

在这里插入图片描述

添加环境变量

在这里插入图片描述

合并视频


    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);
    }

转码

    /**
     * 转码
     * @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 使用

猜你喜欢

转载自blog.csdn.net/qq_22823581/article/details/135390593