C # ffmpeg tool to convert video to SWF format

Source: Internet
Author: User

1. Download the FFmpeg tool

usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Xml.Linq;usingSystem.Diagnostics;usingSystem.IO;namespacewebthreadtest{ Public Partial classFfmpegTest:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            if(!IsPostBack) {                //the video will be converted to SWF format//FFmpeg Bin directory                stringFfmpegbinpath =@"C:\Users\Administrator\Desktop\ffmpeg\bin\"; //Video catalog that needs to be converted                stringConvertdirpath = Server.MapPath ("/resource/ffmpeg"); //Start Conversionallvideoconverttoswf (Convertdirpath,ffmpegbinpath); }        }        /// <summary>        ///Convert video to SWF format/// </summary>        /// <param name= "Ffmpegbinpath" >ffmpeg Tool Bin directory</param>        /// <param name= "Videosourcefilename" >Full Video Path</param>        /// <param name= "Targetswffilename" >full path to SWF file</param>        /// <returns></returns>        Private BOOLVIDEOCONVERTTOSWF (stringFfmpegbinpath,stringVideosourcefilename,stringtargetswffilename) {            Try{Process Process=NewProcess (); Process. Startinfo.filename="Cmd.exe";//determine the program name//"CD C:\Users\Administrator\"                stringStartcommandcontent =@"CD C:\Users\Administrator\"; stringScommand =startcommandcontent; Process. Startinfo.arguments= Scommand;//determine the program command lineProcess. Startinfo.useshellexecute =false;//use of the shellProcess. Startinfo.redirectstandardinput =true;//REDIRECT inputProcess. Startinfo.redirectstandardoutput =true;//REDIRECT outputProcess. Startinfo.redirectstandarderror =true;//REDIRECT output errorProcess. Startinfo.createnowindow =true;//Setting the display windowProcess. Start ();//xxProcess. Standardinput.writeline (Scommand);//You can also enter the command in the line in this way//"CD C:\Users\Administrator\Desktop\ffmpeg\bin\"                stringCommandcdffmpegbin =@"CD {0}"; Commandcdffmpegbin=string.                Format (Commandcdffmpegbin, @ffmpegBinPath); Process.                Standardinput.writeline (@commandCDFfmpegBin); //If the code rate is too much conversion error//@ "Ffmpeg-i C:\Users\Administrator\Desktop\ffmpeg\test.avi-to 00:30 C:\ttt.avi"; //Specify a certain number of code special rate//ffmpeg-i C:\Users\Administrator\Desktop\ffmpeg\test.avi-to 00:30-ar 22050-y C:\ccc.avi                stringCommandvideocontent =@"ffmpeg-i {0}-to 00:10 {1}"; Commandvideocontent=string.                Format (Commandvideocontent, @videoSourceFileName, @targetSwfFileName); Process.                Standardinput.writeline (@commandVideoContent); Process. Standardinput.writeline ("Exit");//add exit or the next line of code//string result = Process. Standardoutput.readtoend (); //output out stream get command line result//Response.Write (Result);                 return true; }            Catch(Exception ex) {Response.Write (@videoSourceFileName+"conversion to wsf file failed <br/>"); Response.Write (ex. Message+"<br/>"); return false; }        }        /// <summary>        ///lists the video files in the files in the directory below and in the deeper directories in which they have subdirectories and subdirectories for conversion/// </summary>        /// <param name= "Convertdirpath" >Video directory path that needs to be converted</param>        /// <param name= "Ffmpegbinpath" >Conversion Tool FFmpeg bin directory path</param>         Public voidALLVIDEOCONVERTTOSWF (stringConvertdirpath,stringFfmpegbinpath) {DirectoryInfo dir=NewDirectoryInfo (Convertdirpath); stringExts =". Avi,.mp3,.mp4,.rmvb,.rm,.wmv,.3gp,.amv,.mov"; //Locate the file in this directoryFileinfo[] fi =dir.            GetFiles (); foreach(FileInfo FinchFI) {                stringExtension =path.getextension (f.fullname); intExtenindex =f.fullname.lastindexof (extension); stringBeforename =F.fullname.remove (Extenindex); stringSwffilename = Beforename +". swf"; if(System.IO.File.Exists (swffilename)) {Continue; }                stringext =path.getextension (f.fullname).                ToLower (); if(exts. Contains (EXT)) {Try                    {                        BOOLIssuccess =videoconverttoswf (Ffmpegbinpath, F.fullname, swffilename); Response.Write ("Full path:"+ f.fullname.tostring () +"To generate the SWF file path:"+ Swffilename +"Build Status:"+ issuccess.tostring () +"<br>"); }                    Catch(Exception ex) {Response.Write ("Full path:"+ f.fullname.tostring () +"Build Error:"+ ex. Message +"<br>"); }                }            }            //Get subdirectoriesdirectoryinfo[] SubDir =dir.            GetDirectories (); foreach(varDinchsubdir)            {allvideoconverttoswf (d.fullname, Ffmpegbinpath); }        }    }}

C # ffmpeg tool to convert video to SWF format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.