最后我可以解决视频旋转(90度) 的 FFmpeg的 强> 图书馆。下载最新版本 的 FFmpeg的 强> 拉链窗户,提取和保持 的 FFmpeg的 强> 驱动器C上的库文件夹[NB:可以选择任何驱动器或路径]。
定义一个需要的函数 string 参数命名 command
string
command
/// <summary> /// Execute the command and output the result /// </summary> private String Command(string command) { int time_out = 6; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); psi.FileName = @"C:\ffmpeg\bin\ffmpeg.exe"; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.UseShellExecute = false; //Do not display windows psi.CreateNoWindow = true; //Specify command line psi.Arguments = command; //Start-up Process p = Process.Start(psi); //Read output string results = p.StandardOutput.ReadToEnd(); //WaitForExit needs to be after ReadToEnd //(To prevent blocking by parent process and child process) p.WaitForExit(time_out * 1000); //Wait maximum specified milliseconds until process terminates if (!p.HasExited) p.Close(); //Display output result return results; }
然后像这样调用传递cmdArgs的函数
string inputPath = @"C:\SampleVideo.mp4"; string outputFile = @"C:\SampleVideoOutput.mp4"; string cmdArgs = string.Empty; cmdArgs = " -i \"" + inputPath + "\" -vf \"transpose=1\" \"" + outputFile + "\""; Command(cmdArgs);
简单的命令行命令如下 -
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
transpose = 1表示旋转90度。
可以使用以下转置参数:
0 = 90CounterCLockwise and Vertical Flip (default) 1 = 90Clockwise 2 = 90CounterClockwise 3 = 90Clockwise and Vertical Flip Use -vf "transpose=2,transpose=2" for 180 degrees.