当前位置:网站首页>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
边栏推荐
- After unplugging the network cable, does the original TCP connection still exist?
- Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
- Explanation of closures in golang
- Deadlock in channel
- 《网络是怎么样连接的》读书笔记 - Tcp/IP连接(二)
- 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)
- Dynamic analysis and development prospect prediction report of high purity manganese dioxide in the world and China Ⓡ 2022 ~ 2027
- C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
- Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

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

How to batch change file extensions in win10

The child container margin top acts on the parent container
![[C Advanced] file operation (2)](/img/50/e3f09d7025c14ee6c633732aa73cbf.jpg)
[C Advanced] file operation (2)

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

Mac platform forgets the root password of MySQL

Svg image quoted from CodeChina

Four common methods of copying object attributes (summarize the highest efficiency)

After unplugging the network cable, does the original TCP connection still exist?

2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
随机推荐
Research and investment strategy report of China's electronic hydrogen peroxide industry (2022 Edition)
Nurse level JDEC addition, deletion, modification and inspection exercise
HMS core helps baby bus show high-quality children's digital content to global developers
Mantis creates users without password options
C语言-入门-基础-语法-数据类型(四)
2022-2028 global visual quality analyzer industry research and trend analysis report
The old-fashioned synchronized lock optimization will make it clear to you at once!
C语言-入门-基础-语法-[运算符,类型转换](六)
2022-2028 global intelligent interactive tablet industry research and trend analysis report
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
2022-2028 global strain gauge pressure sensor industry research and trend analysis report
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
Summary of the most comprehensive CTF web question ideas (updating)
什么是uid?什么是Auth?什么是验证器?
26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
Write a jison parser from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
20220701 barbarat lemma proof
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