c#  ffmpeg视频转换

什么是ffmpeg,它有什么作用呢,怎么可以使用它呢,带着问题去找答案吧!先参考百度百科把,我觉得它很强大无奇不有,为了方便大家我就把链接提供了!

http://baike.baidu.com/link?url=bD4xX59DgppfdclpyGfmC38WTeEkOTM9yc35XGi4OLnQYY7BqmPJSIZHyPKp0imUdI2yujK76Nm047ACZW2hHa

今天工作中遇到这么个问题,这个问题很屌,我通过搜索引擎找了个遍,几乎没有找到理想的答案,于是被逼无奈之下,自己研究参数,于是就有了如下的成就,所以,遇到问题不要害怕,这才是成长最快的时刻。当问题解决了的时候,会有种无比的成就感,把自己的成果分享给他人,供他人参考,这也是种喜悦!

------------没有做不到的,只有想不到的。

转码进度公式=当前时间/总时间*100%;

   public class FFmpeg
{
static int timeCount;
public static void Execute()
{
Process p = new Process();
p.StartInfo.FileName = @"E:\张立平资料\Demo\FFmpeg_Demo\ffmpeg\ffmpeg.exe";
p.StartInfo.UseShellExecute = false;
string srcFileName = @"E:\张立平资料\Demo\FFmpeg_Demo\videoold\test.mov";
string destFileName = @"E:\张立平资料\Demo\FFmpeg_Demo\videonew\test.mp4";
p.StartInfo.Arguments = "-i " + srcFileName + " -y -ab 56 -ar 22050 -b 800 -r 29.97 -s 420x340 " + destFileName; //执行参数
//-i D:/vts-collector/test/swap/7a3c9800-2e2f-42fe-ba39-56b25f972e06.mov -y -ab 56 -ar 22050 -b 800 -r 29.97 -s 420x340 D:/vts-collector/test/swap/7a3c9800-2e2f-42fe-ba39-56b25f972e06_mov_stream.mp4 p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); using (p)
{
p.Start();
p.BeginErrorReadLine();//开始异步读取
p.WaitForExit();//阻塞等待进程结束
p.Close();//关闭进程
}
} private static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{ var output = e.Data;
if (output != null)
{
if (output.Contains("Duration"))
{
Int32 indexOfDuration = output.IndexOf("Duration");
Int32 indexOfBegin = output.IndexOf(":", indexOfDuration);
Int32 indexOfEnd = output.IndexOf(",", indexOfBegin);
var duration = output.Substring(indexOfBegin + , indexOfEnd - indexOfBegin - );
timeCount =ConvertStringtoSecond(duration);
}
if (output.Contains("time="))
{
Int32 indexOfTime = output.IndexOf("time=");
Int32 indexOfBegin = output.IndexOf("=", indexOfTime);
Int32 indexOfEnd = output.IndexOf("bitrate", indexOfBegin);
string timeStr = output.Substring(indexOfBegin + , indexOfEnd - indexOfBegin - );
var time =Convert.ToDouble(timeStr);
var process = time / timeCount*;
process = Math.Round(process);
Console.Write("{0}% ", process);
}
//Console.WriteLine(e.Data);
}
} private static int ConvertStringtoSecond(string input)
{
int totalSecond = ;
try
{
string[] split = input.Split(new char[] { ':', '.' });
int hour = int.Parse(split[]) * ;
int min = int.Parse(split[]) * ;
int second = int.Parse(split[]);
int millisecond = int.Parse(split[]) / ;
totalSecond = hour + min + second + millisecond;
}
catch (System.Exception ex)
{
Console.Write(ex.Message); }
return totalSecond;
} private static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}
}

最新文章

  1. 将Json数据保存在静态脚本文件中读取
  2. 一次基于etcd的分布式锁自动延时失败问题的排查
  3. 导入excel
  4. IOS7.0 UILabel实现自适应高度的新方法
  5. (转)C# 打印PDF文件使用第三方DLL
  6. android AsyncTask实例
  7. php数组的创建及操作
  8. Xcode创建Object-C程序
  9. RPC远程过程调用协议
  10. SharePoint 2013 - REST API about Content
  11. 晨曦之光 linux Crontab 使用(转)
  12. 反编译与调试APK
  13. Exp6 信息收集与漏洞扫描
  14. Richard Sabey于2004年给出了由123456789各出现一次的e的估计
  15. SpringBoot编写自定义Starter
  16. HDU 2874 Connections between cities(LCA离线算法实现)
  17. 语义分割Semantic Segmentation研究综述
  18. 【学习笔记】初识FreeMarker简单使用
  19. 使用unity2017.3 vuforia7摄像头放大的问题
  20. NOI2007 社交网络

热门文章

  1. SAXReader
  2. JS 学习笔记--JS中的事件对象基础
  3. hdu 1548 A strange lift 宽搜bfs+优先队列
  4. Swift-4-数组和字典
  5. 15万甚至30万以内的SUV值不值得买?
  6. C++中的RAII机制
  7. sublime text3使用心得及个人配置 sublime常用快捷键大全
  8. ssh 远程 centos 乱码
  9. Sqli-labs less 56
  10. 解决vsftpd日志时间问题