Application of video transcoding in real project

Source: Internet
Author: User

Application of video transcoding in real project

Thefollowing is the use of the Ffmpeg.exe as transcoding tool, as it was previously encountered in the project to convert . flv file video to . mp4.

1: Next need to prepare tools;http://ffmpeg.org/ Download the corresponding version of Ffmpeg.exe ( +32 bit )

2: Implementation code, the following is just one way to implement:

Using System;

Using System.Collections.Generic;

Using System.Diagnostics;

Using System.Linq;

Using System.Web;

Namespace Videoconvert.models

{

public class Ffmpeghelper

{

<summary>

32 Guests

</summary>

private static string FfmpegPath32 = AppDomain.CurrentDomain.BaseDirectory + @ "Ffmpeg\32\ffmpeg.exe";

<summary>

64 guests

</summary>

private static string ffmpegPath64 = AppDomain.CurrentDomain.BaseDirectory + @ "Ffmpeg\64\ffmpeg.exe";

<summary>

Actual version

</summary>

private static string path;

private static Process p = null;

<summary>

Transcode FLV to MP4

</summary>

<param name= "OldPath" >....flv</param>

<param name= "NewPath" >.....mp4</param>

public void VideoConvert (String oldpath,string newpath)

{

using (p = new Process ())

{

For more transcoding methods, you can view official documents, which are just one of the following:

string arg = "-I" + OldPath + "-c:v libx264-crf 23-c:a libfaac-q:a" + NewPath;

To determine the system version:

Is32or64 ();

p.startinfo.arguments = arg;

p.StartInfo.FileName = path;

P.startinfo.redirectstandarderror = true;

P.startinfo.redirectstandardinput = true;

P.startinfo.redirectstandardoutput = true;

Indicates that the transcoding window is not displayed

P.startinfo.createnowindow = true;

P.startinfo.useshellexecute = false;

Sets the event to be triggered when the process terminates;

p.EnableRaisingEvents = true;

p.exited + = new EventHandler (p_exited);

P.outputdatareceived +=new Datareceivedeventhandler (p_outputdatareceived);

P.errordatareceived +=new Datareceivedeventhandler (p_errordatareceived);

P.start ();

Read output;

P.beginoutputreadline ();

P.beginerrorreadline ();

Set the wait process to trigger the P_exited event and proceed down;

p.WaitForExit ();

}

}

void P_errordatareceived (object sender, Datareceivedeventargs e)

{

Logging output logs

}

void P_outputdatareceived (object sender, Datareceivedeventargs e)

{

Logging output logs

}

void P_exited (object sender, EventArgs e)

{

The process exits triggering the event, which can be used to perform other operations or to determine

}

public void Is32or64 ()

{

if (Environment.is64bitoperatingsystem)

{

Path = ffmpegPath64;

}

else {

Path = FfmpegPath32;

}

}

}

}

Application of video transcoding in real project

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.