当前位置:网站首页>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
边栏推荐
- Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
- 《网络是怎么样连接的》读书笔记 - Tcp/IP连接(二)
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
- PMP registration process and precautions
- Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
- el-table单选并隐藏全选框
- Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
- 《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
- Talk about single case mode
- Launpad | 基礎知識
猜你喜欢

You can see the employment prospects of PMP project management

C语言-入门-基础-语法-数据类型(四)

GoLand environment variable configuration

2022-2028 global intelligent interactive tablet industry research and trend analysis report

If you can quickly generate a dictionary from two lists

How should PMP learning ideas be realized?

2022-2028 global special starch industry research and trend analysis report

Mantis creates users without password options
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C語言-入門-基礎-語法-[運算符,類型轉換](六)

Latex download installation record
随机推荐
Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
The old-fashioned synchronized lock optimization will make it clear to you at once!
The child container margin top acts on the parent container
Four common methods of copying object attributes (summarize the highest efficiency)
lolcat
Opencv environment construction (I)
C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
In depth investigation and Strategic Research Report on China's motion controller Market (2022 Edition)
C language - Introduction - Foundation - syntax - data type (4)
Tkinter Huarong Road 4x4 tutorial II
Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
2022-2028 global intelligent interactive tablet industry research and trend analysis report
Implementing expired localstorage cache with lazy deletion and scheduled deletion
What is uid? What is auth? What is a verifier?
How do microservices aggregate API documents? This wave of show~
At the age of 30, I changed to Hongmeng with a high salary because I did these three things
Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share