简体   繁体   English

在C#中使用ffmpeg将两个mp4视频合并为单个视频不起作用

[英]merge two mp4 video as single video using ffmpeg in C# is not working

For the last 4 hours I've been trying to combine 2 .mp4 files into one using ffmpeg in C#. 在过去的4个小时中,我一直在尝试使用C#中的ffmpeg将2个.mp4文件合并为一个。

****My code is below:**** ****我的代码如下:****

   public void MergeFiles(string strFile)
    {
        string strParam;

        string Path_FFMPEG = Server.MapPath("~/Video_Clips/ffmpeg.exe");

        //Merging two videos               
        String video1 = Server.MapPath("~/Videos/fast1.mp4");
        String video2 = Server.MapPath("~/Videos/fast2.mp4");
        String file = Server.MapPath("~/Videos/input.txt");
        String strResult =   Server.MapPath("~/Videos/ConvertedFiles/Output.mp4");

        strParam = " -f concat -i " + file + " -c copy " + strResult;

        process(Path_FFMPEG, strParam);
    }

   public void process(string Path_FFMPEG, string strParam)
    {
        try
        {
            Process ffmpeg = new Process();
            ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, strParam);
            ffmpeg_StartInfo.UseShellExecute = false;
            ffmpeg_StartInfo.RedirectStandardError = true;
            ffmpeg_StartInfo.RedirectStandardOutput = true;
            ffmpeg.StartInfo = ffmpeg_StartInfo;
            ffmpeg_StartInfo.CreateNoWindow = true;
            ffmpeg.EnableRaisingEvents = true;
            ffmpeg.Start();
            ffmpeg.WaitForExit(30000);
            //ffmpeg.WaitForExit();
            ffmpeg.Close();
            ffmpeg.Dispose();
            ffmpeg = null;
        }
        catch (Exception ex)
        {

        }
    }

My input.txt file is below: 我的input.txt文件如下:

List of Files to Join (Comment) 要加入的文件列表(评论)

file 'D:/Kapil_WorkSpace/ExtraProjectSource/VideoDemo/VideoDemo/Videos/fast1.mp4' 文件'D:/Kapil_WorkSpace/ExtraProjectSource/VideoDemo/VideoDemo/Videos/fast1.mp4'

file 'D:/Kapil_WorkSpace/ExtraProjectSource/VideoDemo/VideoDemo/Videos/fast2.mp4' 文件'D:/Kapil_WorkSpace/ExtraProjectSource/VideoDemo/VideoDemo/Videos/fast2.mp4'

Please help. 请帮忙。 Thanks in advance. 提前致谢。

Finally, i found answer for my own question. 最后,我为自己的问题找到了答案。

I have used ffmpeg.exe file and there is for 32 bit system and i am using 64 bit. 我使用了ffmpeg.exe文件,并且使用的是32位系统,我使用的是64位。 So, problem is in ffmpeg build file. 因此,问题出在ffmpeg构建文件中。 I have download new 64 bit build for that. 我已经为此下载了新的64位版本。

And another issue is path of videos in input.txt file are wrong.So, made it correctly and it's work completely. 另一个问题是input.txt文件中的视频路径错误,因此正确地制作了视频就可以了。 But it take too much time for some video and some video is work faster. 但是某些视频花费太多时间,某些视频的运行速度更快。 I don't know what is reason for that. 我不知道是什么原因。

Thanks all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM