代码之家  ›  专栏  ›  技术社区  ›  Michael Samteladze

ffmpeg设置转换时的持续时间[关闭]

  •  2
  • Michael Samteladze  · 技术社区  · 14 年前

    我正在用ffmpeg转换视频,对话后的持续时间显示为00:00:00.00。 以下是我的论点

    "-i " + FileName + " -ar 22050 -b 500k -f flv -t " + Duration + " " + outputfile
    

    由我的代码呈现给

    -i 1.mov -ar 22050 -b 500k -f flv -t 00:03:34.99 1.flv
    

    我错过了什么?


    filargs = "flvtool2 -UP " + outputfile;
                proc = new Process();
                proc.StartInfo.FileName = spath + "flvtool2.exe";
                proc.StartInfo.Arguments = filargs;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow = false;
                proc.StartInfo.RedirectStandardOutput = false;
    
                proc.Start();
    
                proc.WaitForExit();
                proc.Close();
    

    我试过了,没有效果,持续时间还是0。其中“outputfile”是我的转换文件,没有持续时间

    2 回复  |  直到 12 年前
        1
  •  1
  •   Jason B    14 年前

    我在刚刚运行的测试中看到了相同的问题。这似乎是ffmpeg中的一个已知问题。对于flv,它不能正确写入所有元数据,包括持续时间。你可以用 flvtool2 为您修复元数据。只需运行:

    flvtool2 -UP file.flv
    

    它将根据时间戳自动查找持续时间,并将元数据写入文件。我刚试过,效果很好。

        2
  •  0
  •   Michael Samteladze    14 年前

    我已经解决了我的问题

    static void Fix(string Path)
            {
                string spath;
                spath = AppDomain.CurrentDomain.BaseDirectory;
                string filargs = "-U " + Path;
                Process proc1 = new Process();
                proc1.StartInfo.FileName = spath + "flvtool2.exe";
                proc1.StartInfo.Arguments = filargs;
                proc1.StartInfo.UseShellExecute = false;
                proc1.StartInfo.CreateNoWindow = false;
                proc1.StartInfo.RedirectStandardOutput
    = false;
                proc1.Start();
                proc1.WaitForExit();
                proc1.Close();
            }
    

    它做得很好