悉野小楼

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

ffmpeg合并视频

先下载个ffmpeg

命令行:

ffmpeg -f concat -i filelist.txt -c copy out\new.mp4

filelis.txt与ffmpeg.exe同一目录, 内容如下:

1
2
3
4
5
6
file 'F:\Download\【日剧_11集全】\1.EP01-1_Av438702220_P1_.mp4'
file 'F:\Download\【日剧_11集全】\2.EP01-2_Av438702220_P2_.mp4'
file 'F:\Download\【日剧_11集全】\3.EP01-3_Av438702220_P3_.mp4'
file 'F:\Download\【日剧_11集全】\4.EP01-4_Av438702220_P4_.mp4'
file 'F:\Download\【日剧_11集全】\5.EP01-5_Av438702220_P5_.mp4'
file 'F:\Download\【日剧_11集全】\6.EP01-6_Av438702220_P6_.mp4'

如果想创建的视频在out目录下, out目录要自己先创建, ffmpeg不能创建目录. 上面也可以用new.mp4, 拼合的新视频在当前目录.

filelist.txt中的文件名可以用相对路径,  名字或路径中不能包含,(), 即逗号,左括号, 右括号, 不然提示警告拼接不了.

ffmpeg最后输出的路径只能用相对路径, 已试过用绝对路径的, 执行不了.

 

使用C#代码调用ffmpeg, 例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/// <summary>
        /// 拼接视频
        /// </summary>
        /// <param name="files">有序的文件列表</param>
        /// <param name="destName">拼接后的名字如out\abc.mp4</param>
        private void ConcatVideo(List<string> files, string destName)
        {
            string dir = Path.GetDirectoryName(files[0]);
            if (!Directory.Exists(dir + "\\out"))
            {
                Directory.CreateDirectory(dir + "\\out");
            }
            if (!Directory.Exists(dir + "\\源"))
            {
                Directory.CreateDirectory(dir + "\\源");
            }
            try
            {
                StringBuilder sb = new StringBuilder();
                foreach (string file in files)
                {
                    sb.Append($"file '{Path.GetFileName(file)}'\r\n");
                }
                File.WriteAllText(dir + "\\filelist.txt", sb.ToString());
                string paras = $"-f concat -i filelist.txt -c copy {destName}";
                string destExe = dir + "\\ffmpeg.exe";
                if(!File.Exists(destExe))
                {
                    string exePath = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe";
                    File.Copy(exePath, destExe, true);
                }
               
                ProcessStartInfo processStartInfo = new ProcessStartInfo();
                processStartInfo.WorkingDirectory = dir;
                processStartInfo.FileName = destExe;
                processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
                processStartInfo.Arguments = paras;
                processStartInfo.UseShellExecute = true;
                Process? p = Process.Start(processStartInfo);
                p?.WaitForExit();
                //处理完整的源文件切到新目录
                foreach(string file in files)
                {
                    FileInfo fileInfo= new FileInfo(file);
                    fileInfo.MoveTo(dir + "\\源\\" + Path.GetFileName(file), true);
                }
            }
            catch(Exception ex)
            {
                WriteLog(ex.Message);
            }
        }

  下载

posted on   悉野  阅读(86)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示