Automatic conversion of all media to FLV Asp.net online videos and screenshot debugging successful!

Source: Internet
Author: User

All media to FLV Asp.net online videos are automatically converted and debugged!



CodeAs follows:

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. Security;
Using system. IO;
Using system. collections;
Using system. Collections. Generic;
Using system. xml;
Using system. diagnostics;
Using system. messaging;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
// Using uploadcontrols;
/// <Summary>
/// Upload File events;
/// </Summary>
Public class upload: ihttphandler, irequiressessionstate
{
Public bool thumbnailcallback () {return false ;}
Public upload ()
{
}

# Region ihttphandler members

Public bool isreusable
{
Get {return true ;}
}

Public void processrequest (httpcontext context)
{
If (context. Request. Files. Count> 0)
{
String filepath = "/upload/MV/" + datetime. Now. tostring ("yyyymm") + "/";
Directoryinfo info = new directoryinfo (context. server. mappath (filepath ));

If (! Info. exists)
{
Info. Create ();
}
Random RO = new random ();
For (Int J = 0; j <context. Request. Files. Count; j ++)
{
Httppostedfile uploadfile = context. Request. Files [J];
If (uploadfile. contentlength> 0)
{
String STRO = Ro. Next (100,100 usd00). tostring (); // generate a random number for the newly named Image
String newname = datetime. Now. Minute. tostring () + datetime. Now. Second. tostring () + datetime. Now. millisecond. tostring () + STRO;
String extension = path. getextension (uploadfile. filename );
String filename = newname + extension. tostring ();
Uploadfile. saveas (path. Combine (context. server. mappath (filepath), filename ));
If (file. exists (context. Request. Files [J]. tostring ()))
{
Try
{
File. Delete (context. Request. Files [J]. tostring ());
}
Catch
{
}
}
String str10 = filepath + filename;
If (! Messagequeue. exists (@ ". \ private $ \ mvqueue "))
{
Messagequeue. Create (@ ". \ private $ \ mvqueue", true );
}
Messagequeue queue = new messagequeue (@ ". \ private $ \ mvqueue ");
Message message = new message ();
Message. Body = context. server. mappath (str10 );
Message. formatter = new xmlmessageformatter (New Type [] {typeof (string )});
Messagequeuetransaction transaction = new messagequeuetransaction ();
Transaction. Begin ();
Queue. Send (message, transaction );
Transaction. Commit ();
Bool flag = false;
String str12 = "ucfarflvconvert ";
Process [] processes = process. getprocesses ();
Foreach (Process in processes)
{
If (str12 = process. processname)
{
Flag = true;
Break;
}
}
If (! Flag)
{
Process process2 = new process ();
Process2.startinfo. workingdirectory = context. server. mappath ("/flvconvert /");
Process2.startinfo. filename = "ucfarflvconvert.exe ";
Process2.startinfo. Arguments = string. empty;
Process2.startinfo. windowstyle = processwindowstyle. hidden;
Process2.start ();
}
Continue;
}
}
GC. Collect ();

}

}

# Endregion

}
Conversion process daemon code:
Using system;
Using system. diagnostics;
Using system. IO;
Using system. messaging;
Using system. Threading;
Namespace ucfarflvconvert
{
Internal class Program
{
Private Static void converttoflv ()
{
Messagequeue queue = new messagequeue (@ ". \ private $ \ mvqueue ");
Queue. formatter = new xmlmessageformatter (New Type [] {typeof (string )});
While (true)
{
If (queue. Transactional)
{
Messagequeuetransaction transaction = new messagequeuetransaction ();
Transaction. Begin ();
String body = queue. Receive (transaction). Body as string;
Transaction. Commit ();
Toflv (body );
}
}
}

Private Static void main (string [] ARGs)
{
Thread [] threadarray = new thread [5];
For (INT I = 0; I <5; I ++)
{
Threadarray [I] = new thread (New threadstart (program. converttoflv ));
Threadarray [I]. isbackground = true;
Threadarray [I]. Start ();
}
Console. writeline ("START .");
Console. Readline ();
Console. writeline ("stop ");
For (Int J = 0; j <5; j ++)
{
Threadarray [J]. Abort ();
}
}

Private Static void runprocess (string inputfile, string imagefile, int imagewidth, int imageheight)
{
If (imagefile! = String. Empty)
{
Using (Process = new process ())
{
Process. startinfo. workingdirectory = environment. currentdirectory;
Process. startinfo. filename = "ffmpeg.exe ";
Process. startinfo. arguments = string. format (string. concat (new object [] {"-I \" {0} \ "-y-F image2-ss 1-T 0.001-s", imagewidth, "*", imageheight, "\" {1} \ ""}), inputfile, imagefile );
Process. startinfo. useshellexecute = true;
Process. startinfo. windowstyle = processwindowstyle. hidden;
Process. Start ();
}
}
}

Private Static void runprocess (INT quality, string inputfile, string outputfile, string imagefile, int moviewidth, int imagewidth, int imageheight)
{
Using (Process = new process ())
{
Process. startinfo. workingdirectory = environment. currentdirectory;
Process. startinfo. filename = "mencoder.exe ";
Process. startinfo. arguments = string. format (string. concat (new object [] {"-VF scale =", moviewidth, ":-3-ffourcc flv1-of lavf-lavfopts implements-OVC lavc-lavcopts vcodec = FLV: vbitrate = ", quality,"-srate 22050-OAC mp3lame-lameopts mode = 2: ABR: Br = 56: vol = 5 \ "{0} \"-O \ "{1} \"}), inputfile, outputfile );
Process. startinfo. useshellexecute = true;
Process. startinfo. windowstyle = processwindowstyle. hidden;
Process. Start ();
Process. waitforexit ();
}
Using (process process2 = new process ())
{
Process2.startinfo. workingdirectory = environment. currentdirectory;
Process2.startinfo. filename = "flvmdi.exe ";
Process2.startinfo. Arguments = string. Format ("\" {0} \ "/K", outputfile );
Process2.startinfo. useshellexecute = true;
Process2.startinfo. windowstyle = processwindowstyle. hidden;
Process2.start ();
}
If (imagefile! = String. Empty)
{
Using (process process3 = new process ())
{
Process3.startinfo. workingdirectory = environment. currentdirectory;
Process3.startinfo. filename = "ffmpeg.exe ";
Process3.startinfo. arguments = string. format (string. concat (new object [] {"-I \" {0} \ "-y-F image2-ss 1-T 0.001-s", imagewidth, "*", imageheight, "\" {1} \ ""}), outputfile, imagefile );
Process3.startinfo. useshellexecute = true;
Process3.startinfo. windowstyle = processwindowstyle. hidden;
Process3.start ();
}
}
}

Private Static void toflv (string filename)
{
Int Quality = 700;
String Path = filename;
String outputfile = filename. substring (0, filename. lastindexof ('.') + ". FLV ";
String imagefile = filename. substring (0, filename. lastindexof ('.') + ". jpg ";
Int moviewidth = 0x177;
Int imagewidth = 300;
Int imageheight = 200;
If (path. getextension (PATH) = ". FLV ")
{
Runprocess (path, imagefile, imagewidth, imageheight );
}
Else
{
Runprocess (quality, path, outputfile, imagefile, moviewidth, imagewidth, imageheight );
}
Try
{
File. Delete (filename );
}
Catch
{
}
}
}
}

Related Article

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.