c# - FFProbe.Analyse 在给定字符串时收到错误“系统找不到指定的文件”
问题描述
我想压缩每个驱动器及其子目录中的每个视频,以便我到目前为止使用的代码找到每个驱动器并查找 .mp4 位置。然后它使用该字符串列表来压缩每个文件,但在以下位置出现此错误:
var mediaInfo = FFProbe.Analyse(filePath: d)
和
.FromFileInput(d, verifyExists: true)
System.ComponentModel.Win32Exception: '系统找不到指定的文件'
我检查了.Analyse
需要什么,它是一个字符串,并且d
是一个具有正确路径位置的字符串C:\\Users\\Helix\\Desktop\\apartment\\5 Little Monkeys Swinging In The Tree.mp4"
,我认为它可以工作,但它似乎不喜欢它。我究竟做错了什么?
我也很好奇是否GetDrives()
适用于网络驱动器?如果确实如此,运行此代码的两台服务器在同时获取同一个文件时会发生冲突吗?
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MediaToolkit;
using MediaToolkit.Model;
using FFMpegCore;
using FFMpegCore.Enums;
namespace Video_Compressor_for_Servers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CompAll_Click(object sender, EventArgs e)
{
//An empty list for later to collect strings
List<string> file = new List<string>();
//extract primary drives strings into a list since there could be more than just C:\
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
//The d.Name output has "Drive C:\" as the output. remove the "Drive " part first
var replacement = d.Name.Replace("Drive ", "");
/*Grab each files location with the Directory tool from the earlier IO libary.
GetFiles is a subcommand of directory with options in the brackets. These
options can be found in more detail by seaching for GetFiles C#*/
string[] files = Directory.GetFiles(@"C:\Users\Helix\Desktop\apartment\","*.mp4", SearchOption.AllDirectories);// replacement//AllDirectories
//Convert the array to a list
List<string> templist = files.ToList();
//Add them to the earlier empty list we made
file.AddRange(templist);
}
//Now that we have paths to all the files we need we can now compress them
foreach (string d in file)
{
var mediaInfo = FFProbe.Analyse(filePath: d);
//Open the video file with MediaToolkit
FFMpegArguments
.FromFileInput(d, verifyExists: true)
.OutputToFile(d, false, options => options
.WithVideoCodec(VideoCodec.LibX264)
.WithConstantRateFactor(21)
.WithAudioCodec(AudioCodec.Aac)
.WithVariableBitrate(4)
.WithVideoFilters(filterOptions => filterOptions
.Scale(VideoSize.Ed))
.WithFastStart())
.ProcessSynchronously();
}
}
}
}
解决方案
您需要同时下载 ffprobe.exe 和 ffmpeg.exe。可执行文件丢失不是媒体之一。
推荐阅读
- python - harcascadePath = cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
- python - 即使密码正确,也无法在 Django 项目中以用户或管理员身份登录
- flutter - I/flutter (9637): NoSuchMethodError: 在 null 上调用了 getter 'length'
- firebase - 您将如何检查 Flutter 中是否存在有关 Firebase 的用户名?
- javascript - 如何在 ejs 文件中使用 await?
- ios - CallKit屏蔽手机屏幕接听电话后是否可以打开应用程序?
- python - 对于给定的 bin,如何确定一个数组中的任何值是否低于另一个数组中的任何值?
- swiftui - 在继续之前等待 actionSheet 结果?
- r - 一列中有多个日期:R
- c++ - 使用 const 和非 const 版本的运算符 [ ] 重载