使用ffmpeg.exe,使用带有c#的asp.net将所有视频文件转换为flv

时间:2011-12-19 07:25:45

标签: c# asp.net

这是我的代码如下。它不能从给定视频中获取图像而不将任何类型的视频转换为flv格式。它转换后但转换后的flv和thumb图像文件不会保存在temp(存储图像)数据(存储转换flv)文件夹中。那个文件夹是空的。 我正在调试代码,但它没有给出任何异常和错误。

请调试我的代码。等待你的回复专家......

在Default2.aspx页中

文件上传控件和保存按钮就在那里。

Default2.aspx.cs page

protected void Page_Load(object sender, EventArgs e)
{
    string ffmpegPath = "";
    string tempLocation = "";
    string mediaOutPath = "";
    string thumbOutPath = "";
    string currentFile = "";
    ffmpegPath = Server.MapPath("~/ffmpeg/ffmpeg.exe");
    tempLocation = Server.MapPath("~/VideoGallery/temp/");
    mediaOutPath = Server.MapPath("~/VideoGallery/data/");
    thumbOutPath = Server.MapPath("~/VideoGallery/thumb/");
}
protected void Submit1_ServerClick(object sender, System.EventArgs e)
{

    if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
    {
        currentFile = System.IO.Path.GetFileName(File1.PostedFile.FileName);
        try
        {

            Convert(tempLocation + currentFile, mediaOutPath + currentFile, thumbOutPath +
            currentFile);


            File1.PostedFile.SaveAs(tempLocation + currentFile);
            Response.Write("The file has been uploaded.");
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.Message);
        }
    }
    else
    {
        Response.Write("Please select a file to upload.");
    }
}
protected void Convert(string fileIn, string fileOut, string thumbOut)
{
    try
    {
        //convert flv
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = ffmpegPath;
        proc.StartInfo.Arguments = "-i " + fileIn +
        " -ar 22050 -ab 32 -f flv -s 320×240 -aspect 4:3 -y " + fileOut.Split('.')[0] +
        ".flv";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.CreateNoWindow = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();
        proc.WaitForExit();

        //convert img

        proc.StartInfo.Arguments = "-i " + fileIn +
        " -an -ss 00:00:03 -s 120×90 -vframes 1 -f mjpeg " + thumbOut.Split('.')[0] +
        ".jpg";

        proc.Start();
        proc.WaitForExit();
        proc.Close();
    }
    catch (Exception ex)
    {
        Response.Write("Error: " + ex.Message);
    }
}

}

0 个答案:

没有答案