欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > ffmpeg 的视频格式转换 c# win10

ffmpeg 的视频格式转换 c# win10

2025/6/7 15:51:37 来源:https://blog.csdn.net/vokxchh/article/details/148385975  浏览:    关键词:ffmpeg 的视频格式转换 c# win10

1,下载ffmpeg ,并设置环境变量。

ffmpeghttps://www.gyan.dev/ffmpeg/builds/

2.新建.net 9.0  winform

using System;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;namespace WinFormsApp11
{public partial class Form1 : Form{public Form1(){InitializeComponent();}void StartPreview(){Process previewProcess = new Process();previewProcess.StartInfo.Arguments = " -i " + inputName + " -c:v " + bianma+ " " + outputName;// ffmpeg -i demo.avi -c:v libx264 output.mp4 previewProcess.StartInfo.FileName = "ffmpeg.exe";previewProcess.StartInfo.UseShellExecute = false;previewProcess.StartInfo.RedirectStandardInput = true;previewProcess.StartInfo.RedirectStandardOutput = true;previewProcess.StartInfo.RedirectStandardError = true;previewProcess.StartInfo.CreateNoWindow = true;previewProcess.Start();string output = previewProcess.StandardError.ReadToEnd();//很重要,不然不会自己退出previewProcess.WaitForExit();}string inputName = "";string outputName = "";string bianma = "libx264";private void button1_Click(object sender, EventArgs e){button1.Visible = false;inputName = textBox1.Text;textBox2.Text = Environment.CurrentDirectory + "\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") +"_"+bianma+ "_output.mkv";outputName = textBox2.Text;Task.Run(() =>{StartPreview();MessageBox.Show("转换完成");button1.BeginInvoke(new MethodInvoker(delegate (){button1.Visible = true;}));});}private void Form1_Load(object sender, EventArgs e){comboBox1.SelectedIndex = 0;inputName = System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_input.avi";outputName = System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_output.mkv";textBox1.Text = inputName;textBox2.Text = outputName;}private void button2_Click(object sender, EventArgs e){OpenFileDialog openFileDialog = new OpenFileDialog();// 设置对话框标题openFileDialog.Title = "选择一个视频文件";openFileDialog.Filter = "视频文件 (*.avi,*.mp4,*.mkv)|*.avi;*.mp4;*.mkv|所有文件 (*.*)|*.*";if (openFileDialog.ShowDialog() == DialogResult.OK){// 获取用户选择的文件路径inputName = openFileDialog.FileName;textBox1.Text = openFileDialog.FileName;}}private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){if (comboBox1.Text == "libx264") { bianma = "libx264"; }if (comboBox1.Text == "libx265") { bianma = "libx265"; }}}}

   string output = previewProcess.StandardError.ReadToEnd();//很重要,不然不会自己退出

整个工程下载:

【免费】ffmpeg的视频格式转换c#win10资源-CSDN文库https://download.csdn.net/download/vokxchh/90947301

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词