当前位置:网站首页>C # use ffmpeg for audio transcoding
C # use ffmpeg for audio transcoding
2022-07-04 09:33:00 【Dandelion_ drq】
Put it first ffmpeg
Official documents and download addresses :
Official documents :http://ffmpeg.org/ffmpeg.html
Download address :http://ffmpeg.org/download.html
use ffmpeg
Transcoding is simple , If you use all the default parameters, just use the following sentence :
ffmpeg.exe -i D:\test\1.aac -y D:\test\1.mp3 -- 1.aac Is the input file to transcode ,1.mp3 It's the output file ,-y Overwrite output file
Of course ffmpeg
Many parameters are supported , For example, what encoder to use , Specify the code rate, etc …… I won't go into details here ( The key is that I don't understand hhh)
After knowing how to use this powerful tool , Is in the C#
How to use it in ~~
It's also very simple. , use Process
Start a process to call ffmpeg
Just fine .
Go straight to the code , I wrote a console program , Receive two parameters , They are input file and output file ( All absolute paths ), And then call ffmpeg
Transcoding , Finally complete transcoding and output corresponding operation information .
using System;
using System.Diagnostics;
namespace AudioTranscoding
{
class Program
{
static void Main(string[] args)
{
Process process = new Process();
try
{
if (args.Length != 2)
{
Console.WriteLine(" Illegal parameter ");
return;
}
string inputFile = args[0];
string outputFile = args[1];
process.StartInfo.FileName = "ffmpeg.exe"; // You can also specify ffmpeg The absolute path of
process.StartInfo.Arguments = " -i " + inputFile + " -y " + outputFile;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.ErrorDataReceived += new DataReceivedEventHandler(Output); // capture ffmpeg.exe Error messages for
DateTime beginTime = DateTime.Now;
process.Start();
process.BeginErrorReadLine(); // Start asynchronous read
Console.WriteLine("\n Start audio transcoding ...\n");
process.WaitForExit(); // Wait for transcoding to complete
if (process.ExitCode == 0)
{
int exitCode = process.ExitCode;
DateTime endTime = DateTime.Now;
TimeSpan t = endTime - beginTime;
double seconds = t.TotalSeconds;
Console.WriteLine("\n Transcoding complete ! Total time :" + seconds + " second \n");
}
// ffmpeg.exe An error occurred
else
{
Console.WriteLine("\nffmpeg.exe There was an error in the program , Transcoding failed !");
}
}
catch (Exception ex)
{
Console.WriteLine("\n error !!" + ex.ToString());
}
finally
{
process.Close();
}
}
private static void Output(object sendProcess, DataReceivedEventArgs output)
{
Process p = sendProcess as Process;
if (p.HasExited && p.ExitCode == 1) // stay ffmpeg Output information only when an error occurs
{
Console.WriteLine(output.Data);
}
}
}
}
Running results :
Transcoding succeeded :
An error occurred :
Reference resources :
ffmpeg Common conversion commands
.net call ffmpeg Converting audio files amr - mp3
边栏推荐
- Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
- How to ensure the uniqueness of ID in distributed environment
- Reading notes of how the network is connected - understanding the basic concepts of the network (I)
- Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global protein confectionery industry research and trend analysis report
- 2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
- Problems encountered by scan, scanf and scanln in golang
- Investment analysis and future production and marketing demand forecast report of China's paper industry Ⓥ 2022 ~ 2028
- Tkinter Huarong Road 4x4 tutorial II
- How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
猜你喜欢
2022-2028 global elastic strain sensor industry research and trend analysis report
After unplugging the network cable, does the original TCP connection still exist?
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
2022-2028 global optical transparency industry research and trend analysis report
2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
C language - Introduction - Foundation - syntax - data type (4)
PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
保姆级JDEC增删改查练习
Daughter love: frequency spectrum analysis of a piece of music
MySQL foundation 02 - installing MySQL in non docker version
随机推荐
Talk about single case mode
DR6018-CP01-wifi6-Qualcomm-IPQ6010-IPQ6018-FAMILY-2T2R-2.5G-ETH-port-CP01-802-11AX-MU-MIMO-OFDMA
What is permission? What is a role? What are users?
Some points needing attention in PMP learning
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
法向量点云旋转
C language - Introduction - Foundation - syntax - [identifier, keyword, semicolon, space, comment, input and output] (III)
"How to connect the network" reading notes - Web server request and response (4)
2022-2028 global small batch batch batch furnace industry research and trend analysis report
You can see the employment prospects of PMP project management
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027
Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
PHP is used to add, modify and delete movie information, which is divided into foreground management and background management. Foreground users can browse information and post messages, and backgroun
HMS core helps baby bus show high-quality children's digital content to global developers
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
Latex download installation record
After unplugging the network cable, does the original TCP connection still exist?
Write a jison parser from scratch (1/10):jison, not JSON