Code _ Practical tips for implementing FLV video conversion in asp.net

Source: Internet
Author: User
Tags time interval flv file
is actually used. NET to implement the process objects in the.
String str=@ "D:\test.avi d:\test_allen.flv";
Runffmpeg (str);



Running FFmpeg video decoding,
public void Runffmpeg (string strcmd)
{
Create and start a new process
Process P = new process ();
Set process startup Information property StartInfo, which is the ProcessStartInfo class, includes properties and methods:
p.StartInfo.FileName = "Ffmpeg.exe"; Program Name
p.startinfo.arguments = "I" + strcmd; Execution parameters
P.start ();
}

Run Cmd.exe Execute DOS command and return execution result
public string Runcmd (String command)
{
Create and start a pair of processes
Process P = new process ();

The process class has a StartInfo property, which is the ProcessStartInfo class, and includes properties and methods, such as:
p.StartInfo.FileName = "cmd.exe"; Program Name
P.startinfo.arguments = "/C" + command; Execution parameters
P.startinfo.useshellexecute = false; Turn off the use of the shell
P.startinfo.redirectstandardinput = true; REDIRECT Standard input
P.startinfo.redirectstandardoutput = true; REDIRECT Standard output
P.startinfo.redirectstandarderror = true; REDIRECT Error output
P.startinfo.createnowindow = true; Settings do not display windows

P.start ();
P.standardinput.writeline (command); You can also enter commands to execute in this way
P.standardinput.writeline ("Exit"); But remember to add exit or the next line of code

You must create code that ends the process after the automatic conversion completes
return P.standardoutput.readtoend (); From the output stream to get the results of the command.
}



------------------------------------
Another method: Convert video files to FLV using MEncoder

MEncoder Conversion Video Considerations


1. Download Mencoder.exe and Mplayer.exe
2, will mencoder.exe in the folder, add environment variable path inside, such as C:\mplayer
3, Microsoft key +r, input cmd, command line to enter the following syntax
MEncoder d:\test.avi-o d:\testflv.flv-of lavf-lavfopts I_CERTIFY_THAT_MY_VIDEO_STREAM_DOES_NOT_USE_B_FRAMES-OAC Mp3lame-lameopts ABR:BR=56-OVC lavc-lavcopts vcodec=flv:vbitrate=100:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4: CMP=6:VB_STRATEGY=1-VF Scale=512:-3-ofps 12-srate 22050

Syntax Description:
MEncoder d:\test.avi-o d:\testflv.flv//D:\test.avi output to d:\testflv.flv, parameter-o represents output path
-of LAVF//Parameter-of: Output file format, FLV file is in LAVF format
-lavfopts i_certify_that_my_video_stream_does_not_use_b_frames//LAVF format parameter settings, for converting FLV format, it is best to add this long sentence. It means no bframes.

-OAC mp3lame//output audio encoder, here with the Mp3lame
-lameopts abr:br=56//is set specifically for mp3lame parameter settings, abr:br=56, is to set the audio bit rate to 56

-OVC LAVC//Output Video Encoder



Video Encoder settings:
-lavcopts

VCODEC=FLV://Specifies that the video encoder is FLV
VBITRATE=500://Designated video bit rate is 500, low quality is 150kb/s, medium quality is 400kb/s, high quality is 700kb/s
mbd=2://Macro Module selection algorithm, the value is 0~2 defaults to 0, the greater the value of the conversion slower, but in terms of quality and file size benefits
Mv0://compile each macro module and choose the best one, when mbd=0 is invalid;
Trell://will slightly increase the quality, mbd>0 when the effect is more obvious;
V4MV://quantized grid search to find the optimal encoding for each 8x8block
CBP://Only one phase of the Trell can be used to evaluate the distorted image block encoding;
Last_pred=3://Compared to the previous frame of the mobile number forecast, the value of 0~99,1~3 more appropriate, more than 3 o'clock quality improvement is irrelevant, but it will reduce the speed;
Dia=4://Mobile search range, the value of -99~6, for fast conversion,-1 is a good value, if not very much attention to speed, you can consider 2~4;
Cmp=6://value is 1~2000, default is 0, set the comparison function for full pixel moving budget
Vb_strategy=1//is helpful to the scenes with great action, for some videos, setting vmax_b_frames will be detrimental to quality, plus vb_strategy=1 will be better.

Parameters of MEncoder
-VF scale=512:-3//-VF indicates that the video format scale is scaled, and the 512:-3 indicates that the width is set to 512, the height to 3 indicates the aspect ratio is maintained, or it can be set to-1 or-2,
-ofps 12/* Output video frame frequency, generally, for flash video frame frequency high no sense, but will increase the video file size, but if the Ofps settings are not appropriate,
For example, the source video frame rate is not a ofps integer multiple, may cause the converted video, audio, different steps,
It seems that this parameter could be changed to-noskip to solve the problem;

-srate 22050//Audio sampling rate is typically 22050 or 44100.



----------------------------------------------------------

MEncoder Chinese Reference manual address

http://www.mplayerhq.hu/DOCS/HTML/zh_CN/


----------------------------------------------------------

Parameter description:

-srate 32000://Sound sampling rate, 22050hz
-AF channels=2:2:1:0:1:1//Right Channel
-AF channels=2:2:0:0:0:1//left channel
-stereo 0//Stereo
-OAC mp3lame://Output audio using MP3 encoding
-lameopts mode=2:cbr:br=32://bit rate br=32 kbit
-OVC xvid-xvidencopts bitrate=200://XviD encoding, Code rate 200kbps (tested, currently DivX faster than XviD, in the use of VHQ function will slightly affect the speed)

-VF SCALE=480:-3-SWS 9://Transform to 480 pixel wide, height scaled proportionally

"C:\dance.avi"-O "C:\dance. Xvid.avi "//source file address-O to output file address

2> 2.txt://encoded Logging address




--------------------Parameter Selection Analysis------------------------

18fps: This is a number of previous tests, the General TV series and cartoon 15fps is enough. If the scene transformation is not very large, 13fps can guarantee smooth playback. Reduce the FPS value can make compression faster, for movies, especially action films, to ensure smooth without mosaic, we must improve FPS, the maximum 24 is enough

Choose 18fps enough to handle most of the cost-effective

Audio sample rate 32KHz: The inspiration from the recording device (the following quality illustration is the analogy, the previous parameter is original)

32khz-32kbps-mono is better than a phone tone.
44khz-64kbps-j-stereo Radio Quality
Standard quality of MP3 in 44khz-128kbps-j-stereo Pass
44khz-192kbps-stereo close to CD quality

After many tests (above is the interval range, oneself can choose according to need)
Press the most province space-use 32khz-32kbps-mono, can guarantee content;
Quality requirements are not high-available 32khz-128kbps-mono price ratio is relatively high;
High quality space-44khz-192kbps-stereo for large SD card users.

Video Sample rate bitrate=150:

80-Minimum space occupancy rate, the worst quality conversion speed slightly faster (with the lowest audio, size can be 1min=1m)
122-to the bottom of the machine to configure the small card users cost-effective (change the surface quickly back to have mosaic)
150-to meet the basic requirements of the bottom-configured machines (for the non-action film is more perfect)
248-The economical choice of the KCAL user (good quality)
350-kcal high configuration machine (economic embodiment of the machine advantage)
Higher-users try it on their own

In general, the size of the output file is significantly affected by the video sampling rate and the audio sampling rate, and the screen size and FPS value also affect the size. How to set the parameters depends on your personal actual needs with the machine configuration.

In addition, there are a lot of unknown parameters, please look for them.

For example: Pess2, PESS3, dynamic fps, screen interception, time interval settings, etc.


------------------------------------------------------------------

About volume adjustment:

Carlwang wrote: "Personal habits are not headphones, hot day with uncomfortable, so the sound I have always been large."
My experience if the chip source is DVDRip, generally in more than 5, if it is RMVB General 2 is enough, and then there will be a burst of sound.

-OAC mp3lame-lameopts mode=2:cbr:br=64:vol=2 Let's try it.


------------------------------------------------------------------------



At the end of the conversion, it is displayed
Pos:226.8s 297f (100%) 48fps trem:0min 5MB a-v:-0.009 [142:56]
Here the side of the content, the parentheses should be the progress of the conversion, the contents of the brackets is very important, 142 for the video bit rate, 56 for the audio bit rate (bit rate of the word is not known to use the right ...) )

At the end of the conversion, 2 lines of text are displayed:
Video stream:142.564 kbit/s (17820 b/s) size:4046677 bytes 227.080 secs 2700 Frames
Audio stream:56.938 kbit/s (7117 S/b) size:1616197 bytes 227.082 secs
These 2 lines of information I think we can all understand that I have been concerned about that 142.564kbit/s,

Flash8 with the conversion tool should know that there is an option in the advanced setting is the maximum data rate,
In the middle of the election medium quality, is 400kb/s, and the low-quality is also 150kb/s, that is, the command to convert the video, its quality is not as good, so, how about quality?


Take a look at the command:
MEncoder "D:\music.wmv"-o "D:\output.flv"-of lavf-oac mp3lame-lameopts ABR:BR=56-OVC lavc-lavcopts Vcodec=flv:vbitra Te=150:mbd=2:mv0:trell:v4mv:cbp:last_pred=3-srate 22050

Analysis:
-OVC > is probably the abbreviation for Output video codec, which is designed to encode and select the LAVC, what does it mean? Said to be using a LIBAVCODEC encoder;

-lavcopts > is the Options option setting for LAVC

To set the parameters of the video encoding!
codec=flv > said is the use of the FLV encoder, this we ignore;
vbitrate=150 > Video bit rate! Video Data Rate! That's it! The original I set is 150 Ah!

Change into vbitrate=1000, try again!
The result is exactly the same as the previous one ...

Calm down, go up and look at the official document, this parameter is the maximum data rate, the largest, you set up much the same ah, it seems not rely on it to control quality.

conclusion, there are 2 ways to set up quality:
1, set-lavcopts, see such a command:
-lavcopts Vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4:cmp=6:vb_strategy=1

Dia=4:cmp=6:vb_strategy=1 these 3 in-lavcopts.
The greater the quality of DIA, if the need for fast coding, set to 1, set to 4, has been very conducive to quality;
The higher the quality of CMP, the default value of 0, is the fastest, generally set to 3, set to 6 has only slightly improved quality, but the speed will be slow
Vb_strategy, probably 1 or 0, the default value may be 0, I set this to 1, will be helpful for coding, this parameter I have not much scrutiny, may not affect the quality ...

2, add-SWS option, look at the following command:
-sws 3
Just add a 3 in, the conversion effect and the previous method is roughly the same, video data rate is 422.5kb/s around, explain
-sws is used to set the quality, the default value is 2, so why not use this simple way? I personally think that using the previous method is conducive to finding a speed and quality of the balance, after all, the scope of change is relatively large.

Personal Opinion:
So the conversion of video format, it is best to use client conversion, converted to the service end, so need to do a client's video upload small software
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.