2

ffmpeg の助けを借りて c# asp.net で 2 つのビデオをマージすることは可能ですか。ffmpeg のドキュメントでは、cat コマンドが提供されました。しかし、それはasp.netでは機能しません。Linux専用だと思っていました。

cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg

asp.net はこのコマンドを実行しますが、出力はありません。助けて。

namespace demo
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Button2_Click(object sender, EventArgs e)
        {
            string strFile = "cars1.flv";
            MergeFiles(strFile);
        }

        public void MergeFiles(string strFile)
        {
            string strParam;
            string Path_FFMPEG = Server.MapPath("~/ffmpeg/bin/ffmpeg.exe");

            //Converting a video into mp4 format
            string strOrginal = Server.MapPath("~/Videos/");
            strOrginal = strOrginal + strFile;
            string strConvert = Server.MapPath("~/Videos/ConvertedFiles/");
            string strExtn = Path.GetExtension(strOrginal);
            if (strExtn != ".mp4")
            {
                strConvert = strConvert + strFile.Replace(strExtn, ".mp4");
                strParam  = "-i " + strOrginal + " " + strConvert;
                //strParam = "-i " + strOrginal + " -same_quant " + strConvert;
                process(Path_FFMPEG, strParam);
            }

            //Merging two videos               
            String video1 = Server.MapPath("~/Videos/Cars1.mp4");
            String video2 = Server.MapPath("~/Videos/ConvertedFiles/Cars2.mp4");
            String strResult = Server.MapPath("~/Videos/ConvertedFiles/Merge.mp4");
            //strParam = "-loop_input -shortest -y -i " + video1 + " -i " + video2 + " -acodec copy -vcodec mjpeg " + strResult;

            strParam = " -i " + video1 + " -i " + video2 + " -acodec copy -vcodec mjpeg " + strResult;

            process(Path_FFMPEG, strParam);
        }

        public void process(string Path_FFMPEG, string strParam)
        {
            try
            {
                Process ffmpeg = new Process();
                ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, strParam);
                ffmpeg_StartInfo.UseShellExecute = false;
                ffmpeg_StartInfo.RedirectStandardError = true;
                ffmpeg_StartInfo.RedirectStandardOutput = true;
                ffmpeg.StartInfo = ffmpeg_StartInfo;
                ffmpeg_StartInfo.CreateNoWindow = true;
                ffmpeg.EnableRaisingEvents = true;
                ffmpeg.Start();
                ffmpeg.WaitForExit();
                ffmpeg.Close();
                ffmpeg.Dispose();
                ffmpeg = null;
            }
            catch (Exception ex)
            {

            }
        }

    }
}
4

2 に答える 2

0

ついに私は自分の質問に対する答えを見つけました。

次の方法で問題が解決します。

public void MergeFiles(string strFile)
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.FileName = Server.MapPath("~/app.bat");
            p.Start();
            p.WaitForExit();
            p.Dispose();
        }

app.bat

app.batには次のコードが含まれています。

copy e:\cars1.mpg /b + e:\cars2.mpg /b e:\output.mpg /b

注:これはWindows専用です。そのため、「cat」コマンドは機能しません。「cat」コマンドの代わりに、copyコマンドを使用します。

于 2012-05-07T04:25:37.427 に答える