1

This is how i'm doing it in the command prompt:

ffmpeg -f gdigrab -framerate 24 -i desktop -preset ultrafast -pix_fmt yuv420p out.mp4

And in csharp code:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.IO;  
using System.Diagnostics;  

namespace Ffmpeg_App  
{  
    class Ffmpeg  
    {  
        Process process;  

        public void Start(string FileName, int Framerate)  
        {  
            process = new System.Diagnostics.Process();  
            process.StartInfo.FileName = @"D:\ffmpegx86\ffmpeg.exe"; // Change the directory where ffmpeg.exe is.  
            process.EnableRaisingEvents = false;  
            process.StartInfo.WorkingDirectory = @"D:\ffmpegx86"; // The output directory  
            process.StartInfo.Arguments = @"-f gdigrab -framerate " + Framerate + " -i desktop -preset ultrafast -                                                                     pix_fmt yuv420p " + FileName;  
            process.Start();  
            process.StartInfo.UseShellExecute = false;  
            process.StartInfo.CreateNoWindow = false;  
            Close();  
        }  

        public void Close()  
        {  
            process.Close();  
        }  
    }  
}  

In form1 top:

Ffmpeg fpeg = new Ffmpeg();

Start button:

private void Start_Click(object sender, EventArgs e)  
        {  
            fpeg.Start("test.mp4", 24);  
        }  

Stop button:

private void Stop_Click(object sender, EventArgs e)  
        {  
            fpeg.Close();  
        } 

The problem is when i start recording it also recording first few seconds the console window of the ffmpeg too same when i stop the recording.

How can i make in both cases using only command prompt or using with csharp that it will not show the console window of the ffmpeg ?

Ffmpeg console window

1 Answers1

1

Change these 3 lines:

process.Start(); 
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;

To:

process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start(); 

Make sure you set the StartInfo properties before you call Start. Use CreateNoWindow so no window is shown.

Mike
  • 562
  • 3
  • 15
  • This is working but hwy when it's getting to the Close method to the line process.Close(); it's closing also the ffmpeg.exe application ? It keep working and it's not saving the video file on the hard disk. It's doing the line process.Close(); but i see in task manager that ffmpeg.exe is still working and then if i shut down the ffmpeg.exe from the task manager the video file on the hard disk is unreadable can't play it. – Simonicop cooper Nov 01 '17 at 19:02
  • If you use the taskmanager to kill the process, ffmpeg will not finish writing necessary header/trailer info for file. Also, process.Close will not accomplish what you are looking for. I think this answer covers what you are looking for: https://stackoverflow.com/a/32505963/6347620 – Mike Nov 01 '17 at 20:28