Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cut/crop/trim a video in respect with time or percentage and save output in different file

Is there any tutorial or a c# library which which help me to accomplish the following

  1. Chose a file to edit
  2. Ask user to select cut/crop/trim method :- by time or by percentage
  3. cut/crop/trim the video by time or percentage as chosen ( say I wish to reduce a 5 minute video to 4 minute video, or reduce the video by 80%)
  4. Save the video as requested in required path

now steps 1) and 4) I have implemented but could not find a good c# library to accomplish 3) and 4)

I looked up the ffmpeg library but could not find a good C# wrapper to accomplish the requirements.

like image 217
Ankush Roy Avatar asked Feb 18 '11 13:02

Ankush Roy


People also ask

What's the difference between trim and cut video?

Cutting is often confused with trimming because both of them are about deleting some parts from the video. However, when you trim a video clip, you delete its beginning and /or end while cutting means cutting a piece out of your video file somewhere else.


1 Answers

ffmpeg is a very powerful application and I have used it many times, even from C#. You don't need a C# wrapper library. All you have to do is execute the ffmpeg commands from C# using:

System.Diagnostics.Process.Start(string fileName, string arguments);

Or use System.Diagnostics.ProcessStartInfo to redirect standard output if you need to.

This article explains how to use System.Diagnostics to execute synchronous and asynchronous commands, etc.
http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx

Here's a simple example of how to cut a video file down to its first 4 minutes using ffmpeg from C#.

using System.Diagnostics
Process.Start("ffmpeg.exe",
              "-sameq -t 240 -i InputVideoFile.avi OutputVideoFile.avi");

Here's a SO example of how to use System.Diagnostics.ProcessStartInfo
C# and FFmpeg preferably without shell commands?

There are lots of online resources that explain all of ffmpeg's features and how to use them, just search.

like image 162
Nimrod Avatar answered Oct 19 '22 07:10

Nimrod