Ffmpeg: records the bit rate and time loss in a recording file ., Ffmpeg Bit Rate

Source: Internet
Author: User

Ffmpeg: records the bit rate and time loss in a recording file ., Ffmpeg Bit Rate

1. Cause

An error occurred while loading the MP3 file generated by calling the recording control in some browsers. A dialog box is displayed.

  

After comparison, I found that this problem occurs when the bit rate in the file attribute is 0 kbps and the length is null. And find a solution. After using ffmpeg for one transcoding, the bit rate and duration will appear, and the browser can load normally.

Ffmpeg.exe-I output-b: a 128 k-y-acodec libmp 3lame out2.mp3 // execute the conversion command in cmd

Exception: normal

2. Cause

As you can see above, mp3 files are caused by the loss of bit rate information. By searching for documents and modifying parameters for multiple times, the problem persists. The recording time is set in the parameter again, and the generated file is normal. As a result, ffmpeg.exe is not properly closed, and the file information is not written.

The reason why ffmpeg was not properly closed was that the cmd window was closed during the test. When the mp3 file was played by the player, it was found that the audio could be played normally, so I didn't think too much. In the code implementation process, you can directly kill the Process to complete the recording.

[DllImport ("kernel32.dll")] static extern bool values (int dwCtrlEvent, int values); [DllImport ("kernel32.dll")] static extern bool values (IntPtr handlerRoutine, bool add ); [DllImport ("kernel32.dll")] static extern bool AttachConsole (int dwProcessId); [DllImport ("kernel32.dll")] static extern bool FreeConsole (); /// <summary> /// function: Stop recording /// </summary> pub Lic static void Stop () {try {AttachConsole (p. id); SetConsoleCtrlHandler (IntPtr. zero, true); GenerateConsoleCtrlEvent (0, 0); FreeConsole (); // p. close (); if (! P. hasExited) {p. kill (); p. waitForExit ();} // p. dispose ();} catch (Exception ex) {// Log. error ("An Error occurred while disabling the recording tool ffmpeg", ex );}}

 

Therefore, you only need to close the recording normally to solve this problem. Later, we found the last line of Press [q] to stop on the cmd interface. After the test, the MP3 generated is also normal. Now, you only need to input q in the Code Simulation to solve this problem,

C # The Code is as follows:

Static StreamWriter myStreamWriter; // <summary> // function: Start recording. // </summary> public static void Start (string audioDevice, string outFilePath) {if (File. exists (outFilePath) {File. delete (outFilePath);} ProcessStartInfo startInfo = new ProcessStartInfo (ffmpegPath); startInfo. windowStyle = ProcessWindowStyle. hidden; startInfo. createNoWindow = true; // if this clause is not added, the cmd window startInfo is displayed. useShellExecute = false; // Close Shell usage startInfo. redirectStandardOutput = true; // The standard output startInfo is redirected. redirectStandardInput = true; startInfo. arguments = audioDevice; p = new Process (); p. startInfo = startInfo; p. start (); myStreamWriter = p. standardInput;} // <summary> // function: Stop recording // </summary> public static void Stop () {try {myStreamWriter. writeLine ("q"); Thread. sleep (100); // The q command does not execute if (! P. hasExited) {p. kill (); p. waitForExit ();} // p. dispose ();} catch (Exception ex) {// Log. error ("An Error occurred while disabling the recording tool ffmpeg", ex );}}

 

 

Test demo https://pan.baidu.com/s/1mizerUS for sharing a recording

 

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.