C#でffmpegを使う
ffmpegの場所を教えて、コマンドラインで扱ってやるだけ。
ラップしたサンプル
staticvoidMain(string[]args){EncodeClassprofile=newEncodeClass(@"C:\Users\ffmpeg.exe");profile.inputVideoPath=@"C:\Users\in.mp4";profile.outputVideoPath=@"C:\Users\out.mp4";profile.EncodeVideo();}publicclassEncodeClass{publicEncodeClass(stringprocessPath){this.processPath=processPath;this.outputType="mpeg4";this.resolution=720;this.quality=1;this.framerate=30;}publicstringprocessPath{get;set;}publicstringinputVideoPath{get;set;}publicstringoutputVideoPath{get;set;}publicstringoutputType{get;set;}publicintframerate{get;set;}publicintresolution{get;set;}publicintquality{get;set;}publicvoidEncodeVideo(){varreso=GetResolution().Split(',');//元動画の解像度取得varheight=int.Parse(reso[0].ToString());varwidth=int.Parse(reso[1].ToString());System.Diagnostics.Processpro=newSystem.Diagnostics.Process();pro.StartInfo.FileName=this.processPath;//ffmpegの場所stringcommand="";command+=@" -i "+this.inputVideoPath;//アス比調整if(width<height){command+=@" -y -vf scale=-1:"+this.resolution;}else{command+=@" -y -vf scale="+this.resolution+":-1";}command+=@" -r "+this.framerate;command+=@" -c:v "+this.outputType;command+=@" -q:v "+this.quality;command+=@" "+this.outputVideoPath;pro.StartInfo.Arguments=command;pro.StartInfo.CreateNoWindow=true;pro.StartInfo.UseShellExecute=false;pro.StartInfo.RedirectStandardOutput=true;pro.Start();pro.WaitForExit();}//解像度取得privatestringGetResolution(){System.Diagnostics.Processpro=newSystem.Diagnostics.Process();stringcommand="";command+=@" -i "+this.inputVideoPath;pro.StartInfo.FileName=this.processPath;//ffmpegの場所pro.StartInfo.Arguments=command;pro.StartInfo.CreateNoWindow=true;pro.StartInfo.UseShellExecute=false;pro.StartInfo.RedirectStandardError=true;pro.Start();stringoutput=pro.StandardError.ReadToEnd().Replace("\r\r\n","\n");List<string>vlist=newList<string>(output.Split("\n"));/*出力から解像度だけ抽出する*/varfindIndex=vlist.FindIndex(s=>s.Contains("Stream"));varsplitSpace=newList<string>(vlist[findIndex].Split(' '));varfindResoNext=splitSpace.IndexOf("[SAR");varfindReso=splitSpace[findResoNext-1];varwidth=int.Parse(findReso.Split('x')[0]);varheight=int.Parse(findReso.Split('x')[1]);pro.WaitForExit();//解像度を返すreturnwidth+","+height;}}補足
https://www.home-movie.biz/free_movie.html
こちらの動画でエンコードできるのを確認しましたが、自前のものはできませんでした。
解像度を取得する際に解析するテキストの構造が違うみたいで、解像度を取得できませんでした。