15

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.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Ankush Roy
  • 1,621
  • 2
  • 15
  • 25

1 Answers1

12

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.

Community
  • 1
  • 1
Nimrod
  • 1,316
  • 9
  • 14
  • Could you please provide a sample code how to execute ffmpeg in c# – Ankush Roy Feb 19 '11 at 15:10
  • Hey is there anyway to jump the first 30 seconds before cropping the 4 minutes out? – ZoomVirus May 28 '15 at 09:48
  • Use the `-ss` parameter and specify an offset time in HH:MM:SS.ms format. For example: `ffmpeg -ss 00:00:50.0 -t 240 -sameq -i InputVideoFile.avi OutputVideoFile.avi` – Nimrod Jun 17 '15 at 18:34
  • I get the following error: Option 'sameq' was removed. If you are looking for an option to preserve the qua lity (which is not what -sameq was for), use -qscale 0 or an equivalent quality factor option. Failed to set value '1' for option 'sameq': Invalid argument Error parsing global options: Invalid argument – 123iamking Feb 18 '16 at 02:55