【问题标题】:c# how to correctly format an ffmpeg user input stream?c#如何正确格式化ffmpeg用户输入流?
【发布时间】:2021-04-11 14:26:48
【问题描述】:

所以我正在编写一个 c# 应用程序,它允许用户以像素为单位将视频缩放到自定义尺寸。我正在努力从 mpeg psi 参数的文本框中获取用户输入:

代码如下:

 var localStoragePath = Path.Combine(Path.GetTempPath(), name);
                            var directoryPath = Path.GetDirectoryName(localStoragePath);
                            Directory.CreateDirectory(directoryPath);
                            File.WriteAllBytes(localStoragePath, bytes);
                            Progress.Text = ($"File copy successful: {File.Exists(localStoragePath)}");
                            var readBack = File.ReadAllBytes(localStoragePath);
                            Progress.Text = ($"Read file Back: {readBack.Length}, {localStoragePath}");
                            var resizedFolderPath = @"C:\upscaledvideohere";
                            Directory.CreateDirectory(resizedFolderPath);
                            var resizedFiePath = Path.Combine(resizedFolderPath, Path.GetFileName(localStoragePath));

                            var psi = new ProcessStartInfo();
                            psi.FileName = @"C:\ffmpeg-2020-12-27-git-bff6fbead8-full_build\bin\ffmpeg.exe";
                            psi.Arguments = $"-i \"{localStoragePath}\" -vf scale=" + pixelsheight.Text  "\"{resizedFiePath}\"";
                            psi.RedirectStandardOutput = false;
                            psi.RedirectStandardError = false;
                            psi.UseShellExecute = true;
                            Progress.Text = ($"Args: {psi.Arguments}");

对于

 psi.Arguments = $"-i \"{localStoragePath}\" -vf scale=" + pixelsheight.Text  "\"{resizedFiePath}\""

为用户在像素高度文本框中输入的文本输入文本的正确方法是什么?

非常感谢。

【问题讨论】:

  • 我不是已经回答了吗?
  • 不,谢谢。这是这里的第一条评论。
  • 您错过了“+”和“$”。应该是$"-i \"{localStoragePath}\" -vf scale=" + pixelsheight.Text + $" \"{resizedFiePath}\""
  • 这是这里的第一条评论 - 我指的是this question
  • @KyleWang 实际上应该对整个事情进行插值,因为它在我已经回答的问题中

标签: c# visual-studio winforms ffmpeg


【解决方案1】:

您之前的问题更正确。当只进行插值会更简单时,您正在混合 concat 和插值

$"-i \"{localStoragePath}\" -vf scale=-1:{pixelsheight.Text} \"{resizedFiePath}\""

我还将 pixelHeight 设为 NumericUpDown 而不是文本,以防止因必须确保在文本框中输入数字而感到头疼


停止复制大量电影文件,方法是将它们全部读入内存中的一个字节数组,将其复制到另一个字节数组,然后将文件读入另一个您从不使用的文件,然后写入磁盘。在 500mb 的电影上运行 ffmpeg 将花费 1.5gb 的内存。使用 System.IO.File.Copy 不会占用任何内存

【讨论】:

    猜你喜欢
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 2014-02-27
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多