Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to cut a frame from the video using .Net

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 293
    Comment on it

    "How to cut a frame from the video using .Net"

    In this article we will see, how we can cut the first frame of our video and save it as a jpg image using ffmpeg software. To download the ffmpeg software please go to the following link:

    Download

    Getting Started:

    Step 1: Create a .Net application.

    Step 2: Include the downloaded ffmpeg.exe file in your project.

    Step 3: Take the following controls in your aspx page:

    <asp:FileUpload ID="fileUpload" runat="server" />
    <asp:Button ID="btnSubmit" runat="server" Text="Upload" OnClick="btnSubmit&#95;Click"/>
    

    Note:-> To upload and submit the video.

    Step 4: Now we have to call the exec() method of the ffmpeg software. The exec() method takes the following parameters: "The url of the uploaded video","The path where the image has to be stored along with the image name" and "The resolution". Inorder to acheive this write the following code onclick of the Submit button in code behind as follows:

    protected void btnSubmit&#95;Click(object sender, EventArgs e)
            {
              if (fileUpload.HasFile)
              {
                exec("http://localhost:52137/" + fileUpload.FileName, Server.MapPath("~/Images/thumb.jpg") ,"640x480");
    
              }
            }
    

    Note:-> You can see that the parameters we have passed above in the code are the url of the uploaded video on the local server, The path where the image will be stored along with the image name and the resolution.

    Step 5: Now write the exec() method as follows:

    public void exec(string input, string output, string parametri)
    {
      ffmpeg = new Process();
      ffmpeg.StartInfo.Arguments = " -i " + input + (parametri != null ? " " + parametri : "") + " " + output;
      ffmpeg.StartInfo.FileName = Server.MapPath("~/ffmpeg.exe"); //Path to the ffmpeg.exe 
      ffmpeg.StartInfo.UseShellExecute = false;
      ffmpeg.StartInfo.RedirectStandardOutput = true;
      ffmpeg.StartInfo.RedirectStandardError = true;
      ffmpeg.StartInfo.CreateNoWindow = true;
      ffmpeg.Start();
      ffmpeg.WaitForExit();
      ffmpeg.Close();
    }
    

    Step 6: Now run the code, you will get the image of the first frame of the video in the given path.

    Hope it helps..... Happy Coding !

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: