当前位置:网站首页>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
边栏推荐
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
- Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
- Leetcode (Sword finger offer) - 35 Replication of complex linked list
- Fatal error in golang: concurrent map writes
- Les différents modèles imbriqués de listview et Pageview avec les conseils de flutter
- Write a jison parser from scratch (1/10):jison, not JSON
- The old-fashioned synchronized lock optimization will make it clear to you at once!
- Research Report on the current market situation and development prospects of calcium sulfate whiskers in China (2022 Edition)
- 【leetcode】540. A single element in an ordered array
- Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
猜你喜欢

Explain TCP protocol in detail three handshakes and four waves

AMLOGIC gsensor debugging

2022-2028 global gasket plate heat exchanger industry research and trend analysis report

You can see the employment prospects of PMP project management

2022-2028 global probiotics industry research and trend analysis report

2022-2028 global tensile strain sensor industry research and trend analysis report

How to ensure the uniqueness of ID in distributed environment
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C语言-入门-基础-语法-[运算符,类型转换](六)
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C語言-入門-基礎-語法-[運算符,類型轉換](六)

Mantis creates users without password options
随机推荐
2022-2028 global optical transparency industry research and trend analysis report
Multilingual Wikipedia website source code development part II
Investment analysis and prospect prediction report of global and Chinese high purity tin oxide Market Ⓞ 2022 ~ 2027
Research and investment strategy report of China's electronic hydrogen peroxide industry (2022 Edition)
Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
Clion console output Chinese garbled code
Are there any principal guaranteed financial products in 2022?
Dede plug-in (multi-function integration)
2022-2028 global protein confectionery industry research and trend analysis report
Deadlock in channel
Implementation principle of redis string and sorted set
PMP registration process and precautions
Flutter tips: various fancy nesting of listview and pageview
Fatal error in golang: concurrent map writes
26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
How do microservices aggregate API documents? This wave of show~
Tkinter Huarong Road 4x4 tutorial II
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share