c# - 在 c# 中使用 ffmpeg 时遇到问题如何正确格式化字符串以升级视频?

标签 c# visual-studio video ffmpeg video-processing

所以我正在用 c# 编写一个应用程序来将视频升级到一定的分辨率。它使用 ffmpeg 来做到这一点。选择视频文件并单击 1080p 后会发生什么情况,它会创建目录文件夹,但实际上并未将升级后的视频写入其中。
我想我一定有一个字符串格式问题:

private void HD_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == null)
            {
                MessageBox.Show("You've not selected your video file yet. Please do so before continuing, cheers.");

            }
            else
            {
             
                    var originFilePath = textBox1.Text;
                    string name = Path.GetFileName(originFilePath);
                    byte[] bytes = null;
                    using (FileStream fileStream = new FileStream(originFilePath, FileMode.Open, FileAccess.Read))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            fileStream.CopyTo(ms);
                            bytes = ms.ToArray();
                        }

                        var localStoragePath = Path.Combine(Path.GetTempPath(), name);
                        var directoryPath = Path.GetDirectoryName(localStoragePath);
                        Directory.CreateDirectory(directoryPath);
                        File.WriteAllBytes(localStoragePath, bytes);
                        Console.WriteLine($"File copy successful: {File.Exists(localStoragePath)}");
                        var readBack = File.ReadAllBytes(localStoragePath);
                        Console.WriteLine($"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\binffmpeg.exe";
                        psi.Arguments = $"-i \"{localStoragePath}\" -vf scale=1080 \"{resizedFiePath}\"";
                        psi.RedirectStandardOutput = false;
                        psi.RedirectStandardError = false;
                        psi.UseShellExecute = true;
                        Console.WriteLine($"Args: {psi.Arguments}");

                        try
                        {
                            using (Process exeProcess = Process.Start(psi))
                            {
                                Console.WriteLine($"process started with processId: {exeProcess.Id}");
                                exeProcess.WaitForExit();
                                Console.WriteLine($"Exit Code: {exeProcess.ExitCode}");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace.ToString());
                            Console.WriteLine(ex.Message.ToString());
                            return;
                        }
                        Console.WriteLine($"process completed");
                        Console.WriteLine($"Temp Out Exists: {File.Exists(resizedFiePath)}");
                    }

                    Console.ReadLine();
                }
            }
        
    
我想知道字符串格式错误可能在哪里?谢谢你。

最佳答案

据我所知,scale command of ffmpeg需要两个维度。如果您希望缩放保持成比例,请将选项之一指定为 -1。由于 1080 是您的高度,因此您的比例命令将是 scale=-1:1080要调试这样的事情,请在参数行之后放置一个断点,指向变量(或使用本地窗口),以便出现工具提示,然后右键单击它并复制该值。将该值粘贴到命令提示符中,然后查看 ffmpeg 是否符合您的预期。如果没有,请修复命令提示符中的参数,并将更改带回您的代码中

关于c# - 在 c# 中使用 ffmpeg 时遇到问题如何正确格式化字符串以升级视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65502499/

相关文章:

c# - 如何更改 Xamarin.Forms UWP 应用程序的强调色?

c++ - 编译C++程序导致 "Fatal Error LNK1104"

audio - ffmpeg 在输出时将 start_time 设置为负值

javascript - 通过 iFrame API 以编程方式嵌入 youtube 视频无法在移动设备上播放

c# - 为什么枚举字符串值不一致?

c# - 如何获取 DataTable 一行中的最后一个单元格?

c# - 如何从另一个线程中止单元测试?

visual-studio - 如何让 NUnit 在我的 testassembly.dll.config 中尊重我的 bindingRedirect?

python - 使用 setup.py 链接 library.lib

ios - IOS平台是否可以在拨出或来电时显示图片或视频?