ffmpeg 调用路径总是不对

云翀 2009-05-19 11:41:48
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

namespace Sqq_Media
{
/// <summary>
/// ffmpeg 的摘要说明
/// </summary>
public class ffmpeg
{
public ffmpeg()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 定义变量

// 存信變量
private Hashtable _variables = new Hashtable();

#endregion

#region 定义属性

/// <summary>
/// ffmpeg.exe文件所在路徑
/// </summary>
public string Path
{
get { return (string)_variables["Path"]; }
set { _variables.Add("Path", value); }
}
/// <summary>
/// 要轉換成Flv的寬度(默認400)
/// </summary>
public int FlvWidth
{
get
{
if (_variables.ContainsKey("FlvWidth")) return (int)_variables["FlvWidth"];
else return 160;
}
set { _variables.Add("FlvWidth", value); }
}
/// <summary>
/// 要轉換成Flv的高度(默認350)
/// </summary>
public int FlvHeight
{
get
{
if (_variables.ContainsKey("FlvHeight")) return (int)_variables["FlvHeight"];
else return 128;
}
set { _variables.Add("FlvHeight", value); }
}
/// <summary>
/// 臷圖寬(默認240)
/// </summary>
public int ImageWidth
{
get
{
if (_variables.ContainsKey("ImageWidth")) return (int)_variables["ImageWidth"];
else return 160;
}
set { _variables.Add("ImageWidth", value); }
}
/// <summary>
/// 臷圖高(默認180)
/// </summary>
public int ImageHeight
{
get
{
if (_variables.ContainsKey("ImageHeight")) return (int)_variables["ImageHeight"];
else return 128;
}
set { _variables.Add("ImageHeight", value); }
}

#endregion

#region 構造函數

public ffmpeg(string path)
{
Path = path;
}

#endregion

#region 內部方法

/// <summary>
/// 轉換為Flv文件
/// </summary>
private void RunFlv(string fullName, string path)
{ //ffmpeg -i F:\01.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 寬x高 f:\test.flv
if (System.IO.File.Exists(fullName))
{
string flvName = System.IO.Path.ChangeExtension(fullName, ".flv");
if (!String.IsNullOrEmpty(path))
{
string lastChar = path.Substring(path.Length - 1);
if (lastChar == @"\" || lastChar == @"/") path = path.Substring(0, path.Length - 1);
flvName = path + @"\" + GetFileName(flvName);
}
string args = String.Format("-i {0} -ab 56 -ar 22050 -b 500 -r 15 -s {1}x{2} {3}", fullName, this.FlvWidth, this.FlvHeight, flvName);
RunCmd(args);
}
}
/// <summary>
/// 轉換為Jpg文件
/// </summary>
private void RunJpg(string fullName, string path)
{ //ffmpeg -i F:\01.wmv -y -f image2 -t 0.001 -s 寬x高 f:\test.jpg;
if (System.IO.File.Exists(fullName))
{
string jpgName = System.IO.Path.ChangeExtension(fullName, ".jpg");
if (!String.IsNullOrEmpty(path))
{
string lastChar = path.Substring(path.Length - 1);
if (lastChar == @"\" || lastChar == @"/") path = path.Substring(0, path.Length - 1);
jpgName = path + @"\" + GetFileName(jpgName);
}
string args = String.Format("-i {0} -y -f image2 -t 0.001 -s {1}x{2} {3}", fullName, this.ImageWidth, this.ImageHeight, jpgName);
RunCmd(args);
}
}
/// <summary>
/// 從文件路徑中取得文件名
/// </summary>
private string GetFileName(string fullName)
{
fullName = fullName.Replace(@"/", @"\");
return fullName.Substring(fullName.LastIndexOf(@"\"));
}
/// <summary>
/// 運行Dos命令
/// </summary>
public void RunCmd(string args)
{
string cmdFile = this.Path + "ffmpeg.exe";
System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(cmdFile);
processInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
processInfo.Arguments = args;
processInfo.UseShellExecute = false;
System.Diagnostics.Process.Start(processInfo);
}

#endregion


#region 對外方法

/// <summary>
/// 轉換為Flv文件
/// </summary>
public void ToFlv(string fullName)
{
RunFlv(fullName, String.Empty);
}
/// <summary>
/// 轉換為Flv文件到指定的目錄
/// </summary>
public void ToFlv(string fullName, string path)
{
RunFlv(fullName, path);
}
/// <summary>
/// 轉換為Jpg文件
/// </summary>
public void ToJpg(string fullName)
{
RunJpg(fullName, String.Empty);
}
/// <summary>
/// 轉換為Jpg文件到指定的目錄
/// </summary>
public void ToJpg(string fullName, string path)
{
RunJpg(fullName, path);
}

#endregion


}
}

-------------------------------
我把ffmpeg.exe放到网站的根目录下,直接这样写
ffmpeg ffmpeg = new ffmpeg("");
不知道问题出在哪??
...全文
238 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang_kun 2009-07-01
  • 打赏
  • 举报
回复
进来学习........................
云翀 2009-05-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wszhoho 的回复:]
C# code
ffmpeg _ffmpeg = new ffmpeg(Server.MapPath("~"));
[/Quote]
还是不对
yccwt 2009-05-19
  • 打赏
  • 举报
回复
断点调调看
wszhoho 2009-05-19
  • 打赏
  • 举报
回复

ffmpeg _ffmpeg = new ffmpeg(Server.MapPath("~"));

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧