It is actually implemented using the Process object in. Net.
String str = @ "d: \ test. avi d: \ test_allen.flv ";
RunFFMpeg (str );
// Decode the video that runs FFMpeg,
Public void RunFFMpeg (string strCmd)
{
// Create and start a new process
Process p = new Process ();
// Set the process startup information attribute StartInfo, which is the ProcessStartInfo class, including some attributes and methods:
P. StartInfo. FileName = "ffmpeg.exe"; // program name
P. StartInfo. Arguments = "-I" + strCmd; // execution Parameters
P. Start ();
}
// Run cmd.exe to execute the Dos command and return the execution result
Public string RunCmd (string command)
{
// Create and start a peer process
Process p = new Process ();
// The Process class has a StartInfo attribute, which is the ProcessStartInfo class, including some attributes and methods, such:
P. StartInfo. FileName = "cmd.exe"; // program name
P. StartInfo. Arguments = "/c" + command; // execution Parameters
P. StartInfo. UseShellExecute = false; // close Shell usage
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; // you can specify not to display a window.
P. Start ();
// P. StandardInput. WriteLine (command); // you can also use this method to export the command to be executed.
// P. StandardInput. WriteLine ("exit"); // you must remember to add Exit. Otherwise, the next line of program will become available.
// You must create the code that ends the process after the automatic conversion is completed.
Return p. StandardOutput. ReadToEnd (); // get the result of the command response line from the extract stream
}
------------------------------------
Another method: Use MEncoder to convert the video file to Flv
Considerations for converting mencoder videos
1. Download mencoder.exe and mplayer.exe
2. Add the mencoder.exe folder to the environment variable Path, for example, C: \ mplayer.
3. Press Microsoft key + R, Enter cmd, and run the following syntax on the command line:
Mencoder d: \ test. avi-o d: \ testflv. flv-of lavf-lavfopts audio-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 // Output D: \ test. avi to d: \ testflv. flv. The parameter-o indicates the output path.
-Of lavf // parameter-of: output file format. flv files belong to lavf format.
-Set parameters in lavfopts I _certify_that_my_video_stream_does_not_use_ B _frames // lavf format. It is best to add this long sentence to convert the flv format. This means no bframes is required.
-Oac mp3lame // Output Audio Encoder. The mp3lame is used here.
-Lameopts abr: br = 56 // It is the parameter setting specifically for mp3lame. abr: br = 56 indicates that the audio bit rate is set to 56.
-Ovc lavc // output Video Encoder
// Video Encoder settings:
-Lavcopts
Vcodec = flv: // specify the video encoder as flv.
Vbitrate = 500: // specify the video bit rate as 500, the low quality as kb/s, the medium quality as kb/s, and the high quality as kb/s
Mbd = 2: // select an algorithm for the macro module. The value ranges from 0 ~ 2 The default value is 0. The larger the value, the slower the conversion, but it is advantageous in terms of quality and file size.
Mv0: // compile each macro module and select the best one. It is invalid when mbd is set to 0;
Trell: // It will slightly increase the quality, and the effect of mbd> 0 is more obvious;
V4mv: // quantum mesh search to find the optimal code for every 8x8 blocks
Cbp: // can only be used with trell phase I to evaluate distorted image block encoding;
Last_pred = 3: // prediction of the number of moves compared to the previous frame. The value ranges from 0 ~ 99,1 ~ 3 is more suitable. When it is greater than 3, it does not matter the quality improvement, but it will reduce the speed;
Dia = 4: // move the search range. The value ranges from-99 ~ 6. For fast conversion,-1 is a good value. If you do not pay much attention to speed, you can consider 2 ~ 4;
Cmp = 6: // The value is 1 ~ 2000. The default value is 0. Set the comparison function for moving the budget of all pixels.
Vb_strategy = 1 // It is helpful for scenarios with large movements. For some videos, setting vmax_ B _frames will damage the quality, and adding vb_strategy = 1 will be better.
// Mencoder Parameters
-Vf scale = 512:-3 //-vf indicates that the video format scale is scaled, 512:-3 indicates that the width is set to 512, and the height is written to-3 to maintain the aspect ratio, you can also set it to-1 or-2,
-Ofps 12/* specifies the Frame Rate of the output video. Generally, it is meaningless to increase the video file size when the frame rate is high for flash playback. However, if ofps is not set properly,
For example, if the frame rate of the source video is not an integer multiple of ofps, the converted video and audio may not be synchronized,
It seems that this parameter can be changed to-noskip to solve this problem ;*/
-Srate 22050 // The audio sampling rate is generally 22050 or 44100.
----------------------------------------------------------
Mencoder Chinese Reference Manual address
Http://www.mplayerhq.hu/DOCS/HTML/zh_CN/
----------------------------------------------------------
Parameter description:
-Srate 32000: // audio sampling rate, 22050 hz
-Af channels = 2: 2: 1: 0: 1: 1 // right channel
-Af channels = 2: 2: 0: 0: 1 // left audio channel
-Stereo 0 // stereo
-Oac mp3lame: // The Output Audio is mp3 encoded.
-Lameopts mode = 2: cbr: br = 32: // bit rate br = 32 kbit
-Ovc xvid-xvidencopts bitrate = 200: // It is encoded in xvid mode and the bit rate is 200 kbps. (according to the experiment, divx is faster than xvid, and the speed is slightly affected when vhq is used)
-Vf scale = 480:-3-sws 9: // converts the height to 480 pixels in width and scales proportionally.
"C: \ dance. avi"-o "C: \ dance. XviD. avi" // source file address-o to output file address
2> 2.txt: // encoding the log record address
-------------------- Parameter Selection analysis ------------------------
18fps: This was obtained through multiple tests. Generally, 15fps is enough for TV series and cartoons. If the scenario change is not very large, 13 FPS can ensure smooth playback. Reducing the fps value can make compression faster. For movies, especially action movies, to ensure smoothness and no mosaic, you must increase the fps. A maximum of 24 is enough.
Choosing 18fps is sufficient for most scenarios and cost-effective
Audio sampling rate 32 KHz: inspired by the recording equipment (the following quality descriptions are used as an example when the preceding parameters are used)
32 KHz-32 Kbps-mono is better than phone call
44 KHz-64 Kbps-J-Stereo radio quality
44 KHz-128 Kbps-J-Stereo standard MP3 Quality
44 KHz-192 Kbps-Stereo close to CD quality
After multiple tests (the above is the interval range, you can choose as needed)
The most space-Use 32 KHz-32 Kbps-mono to ensure content;
Low Quality Requirements-available 32 KHz-128 Kbps-mono cost-effective;
Large Space high quality-44 KHz-192 Kbps-Stereo for large SD card users.
Video sampling rate bitrate = 150:
80-minimum space usage, minimum conversion speed of quality (with the lowest audio, the size can be 1 min = 1 M)
122-cost-effective for low-end card users who configure machines (face-to-face changes quickly return to mosaic)
150-meets the basic image quality requirements of the underlying configuration machine (perfect for non-action movies)
248-economic choice of big card users (good quality)
350-High-configuration machines with big cards (economic advantages of machines)
Higher-try it by yourself
In general, the size of the output file is significantly affected by the video sampling rate and audio sampling rate, as well as the image size and fps value. How to set parameters depends on your individual needs and machine configurations.
In addition, there are many unknown parameters. Please refer to them.
For example, pess2, pess3, dynamic FPS, screen capture, and Time Interval Settings
------------------------------------------------------------------
About volume adjustment:
Carlwang wrote: I used to use headphones, but I was always too loud when I was not feeling well.
In my experience, if the source is DVDrip, it is generally above 5. If it is rmvb, generally 2 is enough. If it is large, there will be a burst of music.
-Oac mp3lame-lameopts mode = 2: cbr: br = 64: vol = 2. Let's try it.
------------------------------------------------------------------------
The conversion ends.
Pos: 226.8 s 297f (100%) 48fps Trem: 0 min 5 mb a-v:-0.009 [142: 56]
The content in the parentheses should be the conversion progress. The content in the brackets is very important. 142 indicates the video bit rate, 56 indicates the audio bit rate (bit rate is not known, right ......)
The conversion ends. Two 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 B/s) size: 1616197 bytes 227.082 secs
I think everyone can understand these two lines of information. Among them, I have always been concerned with the 142.564 kbit/s,
If you have used the flash 8 built-in conversion tool, you should know that the option in the advanced settings is the maximum data rate,
In the middle of the election, the image quality was kb/s, while the low quality was kb/s. That is to say, videos converted using that command have poor image quality, what about the 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: vbitrate = 150: mbd = 2: mv0: trell: v4mv: cbp: last_pred = 3-srate 22050
Analysis:
-Ovc> This is probably the abbreviation of output video codec. It is used to develop the output video encoding. What does lavc mean? Libavcodec encoder is used;
-Lavcopts> is the options setting of lavc.
You have set video encoding parameters!
Codec = flv> the flv encoder is used;
Vbitrate = 150> video bit rate! Video data rate! That's it! I used to set 150!
Change to vbitrate = 1000 and try again!
The result is exactly the same as the previous one ......
Calm down and go up and read the official documentation. this parameter is the maximum data rate and the maximum value. It seems that most of your settings are the same. It doesn't seem to rely on it to control quality.
Conclusion There are two ways to set quality:
1. Set-lavcopts and read the following command:
-Lavcopts vcodec = flv: vbitrate = 500: mbd = 2: mv0: trell: v4mv: White: last_pred = 3: dia = 4: cmp = 6: vb_strategy = 1
In-lavcopts, dia = 4: cmp = 6: vb_strategy = 1.
The larger the dia, the higher the quality. If fast encoding is required, set it to-1 and set it to 4, which is very beneficial to the quality;
The larger the cmp, the higher the quality. The default value is 0, which is the fastest. Generally, setting it to 3 and 6 will only slightly improve the quality, but the speed will be slow.
Vb_strategy, probably 1 or 0. The default value may be 0. I set it to 1 here, which will be helpful for encoding. I did not elaborate on this parameter too much, quality may not be affected ......
2. Add the-sws option and check the following command:
-Sws 3
Simply add 3. The effect after conversion is roughly the same as that of the previous method. The video data rate is about 422.5kb/s.
-Sws is used to set the quality. The default value is 2. Why not use this simple method? I personally think that using the previous method is helpful to finding a balance between speed and quality. After all, the scope of change is relatively large.
Personal Opinion:
It is best to use the client to convert the video format and transfer it to the server after the conversion. Therefore, you need to use a small video upload software on the client.