FFmpeg 实现视频合并,转码,拼接

1.下载ffmpeg,地址:http://www.ffmpeg.org/download.html

2.配置 ffmpeg 环境,我的路劲如下图,如果你的path有参数则在后面追加ffmpeg.exe 的路径     ;d:\ffmpeg\bin 

3.代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

    static string FFmpegPath = @"D:\ffmpeg\bin\ffmpeg.exe";
    // Use this for initialization
    void Start () {

        //视频转码
        //string para = string.Format("-i {0} -b 1024k -acodec copy -f mp4 {1}", videoUrl, targetUrl);
        // RunMyProcess(para);

        // 视频拼接
        //string para = string.Format(" -f concat -safe 0 -i {0} -c copy {1}", @"F:\Videos\filelist.txt", @"F:\Videos\c.mp4");
        //RunMyProcess(para);

        // 同时显示
        string para = "-i D:\\ffmpeg\\1.mp4 -i D:\\ffmpeg\\2.mp4 -i D:\\ffmpeg\\3.mp4 -i D:\\ffmpeg\\4.mp4 -filter_complex \"[0:v]pad=iw*2:ih*2[a];[a][1:v]overlay=w[b];[b][2:v]overlay=0:h[c];[c][3:v]overlay=w:h\" D:\\ffmpeg\\combineOut.mp4";
        RunMyProcess(para);

    }
    
    static void RunMyProcess(string Parameters)
    {
        var p = new System.Diagnostics.Process();
        p.StartInfo.FileName = FFmpegPath;
        p.StartInfo.Arguments = Parameters;
        //是否使用操作系统shell启动
        p.StartInfo.UseShellExecute = true;
        //不显示程序窗口
        p.StartInfo.CreateNoWindow = false;
        p.Start();
        Debug.Log("\n开始转码...\n");
        p.WaitForExit();
        p.Close();
        Debug.Log("\n转码完毕...\n");
    }
}

特别注意的是视频拼接 F:\Videos\filelist.txt  这个文件为下图:

猜你喜欢

转载自blog.csdn.net/qq_39097425/article/details/82053204