首页 > 解决方案 > 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();
            }

        }
    }
}

标签: c#stringnetworkingserverffprobe

解决方案


您需要同时下载 ffprobe.exe 和 ffmpeg.exe。可执行文件丢失不是媒体之一。


推荐阅读