当前位置:网站首页>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
边栏推荐
- What is uid? What is auth? What is a verifier?
- 2022-2028 global optical transparency industry research and trend analysis report
- Explain TCP protocol in detail three handshakes and four waves
- Luogu deep foundation part 1 Introduction to language Chapter 4 loop structure programming (2022.02.14)
- C语言-入门-基础-语法-数据类型(四)
- 2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
- What is inner connection and outer connection? What are the uses and benefits
- 2022-2028 global edible probiotic raw material industry research and trend analysis report
- 《网络是怎么样连接的》读书笔记 - 认识网络基础概念(一)
- [C Advanced] file operation (2)
猜你喜欢
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
GoLand environment variable configuration
Markdown syntax
Implementation principle of redis string and sorted set
C language - Introduction - Foundation - syntax - [identifier, keyword, semicolon, space, comment, input and output] (III)
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
At the age of 30, I changed to Hongmeng with a high salary because I did these three things
2022-2028 global seeder industry research and trend analysis report
2022-2028 global edible probiotic raw material industry research and trend analysis report
C语言-入门-基础-语法-[运算符,类型转换](六)
随机推荐
Rules for using init in golang
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
Lauchpad x | MODE
el-table单选并隐藏全选框
C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
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
Research and investment strategy report of China's electronic hydrogen peroxide industry (2022 Edition)
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
Pueue data migration from '0.4.0' to '0.5.0' versions
Investment analysis and prospect prediction report of global and Chinese high purity tin oxide Market Ⓞ 2022 ~ 2027
2022-2028 global intelligent interactive tablet industry research and trend analysis report
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
2022-2028 global visual quality analyzer industry research and trend analysis report
ArrayBuffer
Write a jison parser from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
2022-2028 global optical transparency industry research and trend analysis report
Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator