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

痴心易碎 提交于 2019-12-04 17:39:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5041910/how-to-cut-crop-trim-a-video-in-respect-with-time-or-percentage-and-save-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!