0
     string strParam;          
        string Path_FFMPEG = @"C:\Windows\system32\cmd.exe";
        string WorkingDirectory = @"C:\Users\Braintech\documents\visual studio 2013\Projects\convertVideo\convertVideo";            
        string command1 = "ffmpeg -i video1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts";
        string command2 = "ffmpeg -i video2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts";
        string command3 = "ffmpeg -i" + "concat:intermediate1.ts|intermediate2.ts" + " -c copy -bsf:a aac_adtstoasc Output.mp4";
        string Command = @"" + command1 + " & " + command2 + " & " + command3 + " ";      

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

        process(Path_FFMPEG, Command, WorkingDirectory);
   public static void process(string Path_FFMPEG, string Command, string WorkingDirectory)
    {
        try
        {           

            Process ffmpeg = new Process();
            ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, Command);
            ffmpeg_StartInfo.WorkingDirectory = WorkingDirectory;              
            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.Close();
            ffmpeg.Dispose();
            ffmpeg = null;
        }
        catch (Exception ex)
        {

        }
    }

I m trying to merge two video using ffmpeg. But it is working manually but not able to execute using c# code.it works when i run the command on cmd manually. But when i am trying to run using c# it not works.Please help someone. Thanks in advance.

3 Answers3

1

Basically, don't try to load it into an array. For large files, you should have a range of overloads of the File() method that take a path or Stream, and know what to do. For example:

return File("/TestVideo/Wildlife.wmv", "video/x-ms-wmv");

or:

return File(videoPath, "video/x-ms-wmv");

However, video is really a special case and may benefit from more specialized handling.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I have to return it for playing video in android app without hitting the video url. So i want to send byte array in api and convert at client side in video and play. – Sunil Kumar Oct 03 '16 at 11:09
  • @SunilKumar loading video into a byte array is a terrible idea and is never going to work; that isn't how you should process large files. So either you need a streaming API (`FileResult` knows what to do here), or you need multiple small requests (horrid). – Marc Gravell Oct 03 '16 at 11:10
  • File Result is not sported in api controller – Sunil Kumar Oct 03 '16 at 12:08
  • @SunilKumar then you need to do it a different way; is `Stream` supported as a return value? – Marc Gravell Oct 03 '16 at 12:27
  • for large video stream is very large for a request and it not works.It stops the request. – Sunil Kumar Oct 03 '16 at 12:31
0

Returning the byte array is really a NO-go.
So, instead of returning the whole video as a byte array, why not saving it somewhere (ex. your Web API), if it's not already saved as a file, and send the video URI back as the response?

The video player you are going to use will for sure know how to handle that URI.

Another option is to enable 206 PARTIAL CONTENT support in your Web API and use the URI of your Web API in your video player.

See here https://stackoverflow.com/a/33634614/2528907

Community
  • 1
  • 1
George Chondrompilas
  • 3,167
  • 27
  • 35
  • actually I don't want to send the video url in the Response for security reasons . I just want to send the byte array or any other suitable solution by which i can send the who;e video in the response and it will play using android app without hitting the server video url. – Sunil Kumar Oct 03 '16 at 12:05
  • Well, actually your users could also find out the endpoint from which the byte arrays are being sent if that's your issue. What about the `PARTIAL CONTENT` option? – George Chondrompilas Oct 03 '16 at 12:13
  • I am using partial content but for large video it also not works and it crash the request. – Sunil Kumar Oct 03 '16 at 12:27
0

issue is with the path. you should give file path in your Commands

may be the below code will help

in which the mylist.txt file contain

file '01.mp4' file '04.mp4'

Dim _ffmpeg As String = "D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\Videos\ffmpeg.exe"
 Dim   params = "-f concat -i D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\Videos\mylist2.txt -c copy D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\Videos\0104.mp4"
    Dim _FFmpegProcessPropertys As New ProcessStartInfo
    _FFmpegProcessPropertys.FileName = _ffmpeg

    _FFmpegProcessPropertys.Arguments = params
    _FFmpegProcessPropertys.UseShellExecute = False
    _FFmpegProcessPropertys.RedirectStandardOutput = True
    _FFmpegProcessPropertys.RedirectStandardError = True
    _FFmpegProcessPropertys.CreateNoWindow = True
    Dim FFmpegProcess = Process.Start(_FFmpegProcessPropertys)