gpt4 book ai didi

PowerShell 和 ffmpeg : No such file or directory

转载 作者:行者123 更新时间:2023-12-04 23:01:13 26 4
gpt4 key购买 nike

我正在尝试在 Python 脚本中使用以下命令,但是我发现这是一个 PowerShell 问题,因为它似乎无法找到我指向的视频文件。
我在云盘上有一个视频文件Z:在以下位置(为了重现性,将其更改为您想要的包含视频文件的任何路径):Z:\Udemy_And_Misc_Downloads\TensorFlow Developer Certificate in 2021 Zero to Mastery\3. Neural network regression with TensorFlow\18. Setting up TensorFlow modelling experiments part 2 (increasing complexity).mp4请注意文件名中的空格和特殊字符,以防万一。
我想要做的是使用以下命令将该视频文件缩减为更小的尺寸:ffmpeg -i "Z:\Udemy_And_Misc_Downloads\TensorFlow Developer Certificate in 2021 Zero to Mastery\[TutsNode.com] - TensorFlow Developer Certificate in 2021 Zero to Mastery\3. Neural network regression with TensorFlow\18. Setting up TensorFlow modelling experiments part 2 (increasing complexity).mp4" -y -vcodec libx264 -acodec ac3 -threads 1 "Z:\Udemy_And_Misc_Downloads\TensorFlow Developer Certificate in 2021 Zero to Mastery\[TutsNode.com] - TensorFlow Developer Certificate in 2021 Zero to Mastery\3. Neural network regression with TensorFlow\18. Setting up TensorFlow modelling experiments part 2 (increasing complexity)DOWNSAMPLED.mp4"我知道它很长,因为它主要被文件名消耗,但我得到的错误是:Z:\Udemy_And_Misc_Downloads\TensorFlow Developer Certificate in 2021 Zero to Mastery\[TutsNode.com] - TensorFlow Developer Certificate in 2021 Zero to Mastery\3. Neural network regression with TensorFlow\18. Setting up TensorFlow modelling experiments part 2 (increasing complexity).mp4: No such file or directory路径是正确的,因为它是从文件夹的 URL 栏中直接复制粘贴。
我尝试过的事情包括:

  • 在文件名
  • 周围使用引号
  • 不在文件名周围使用引号
  • 在引用的文件名前加上“r”(我收到消息说“你的意思是文件:r 吗?)
  • 在引用文件名前加上“file:r”
  • 在文件路径中使用双斜杠\

  • 有没有powershell pro可以告诉我为什么它不能“找到”文件?
    更新
    如果我找到具有以下内容的文件名,则该命令运行:
    $oldvids = Get-ChildItem *.mp4, *mov, *wmv, *avi -Recurse
    foreach ($oldvid in $oldvids)
    {
    $newvid = [io.path]::ChangeExtension($oldvid.FullName, '_.mp4')
    ffmpeg -i $oldvid.FullName -y -vcodec libx264 -acodec ac3 -threads 1 $newvid
    }
    当我打印 $oldvid.name$oldvid.FullName ,路径/文件名如下所示:
    Z:\Udemy_And_Misc_Downloads\TensorFlow Developer Certificate in 2021 Zero to Mastery\5. Computer Vision and Convolutional Neu
    ral Networks in TensorFlow\35. Multi-class CNN's part 9 Making predictions with our model on custom images.mp4

    35. Multi-class CNN's part 9 Making predictions with our model on custom images.mp4
    ...第一个是我在发布的代码中尝试使用的内容的精确副本。那么有什么区别呢??
    第二次更新
    我认为问题在于文件位于 C: 以外的驱动器上。 .只需将文件移动到我的计算机上并运行命令对其进行测试,它就可以工作。所以我想,有没有办法告诉 PowerShell 使用 Z:驱动器找到文件?

    最佳答案

    我发现问题在于某些文件名中包含特殊字符(可能来自另一个操作系统),例如 ' .一旦我删除了这些,问题就消失了。我的错。
    但是,我创建了一个简化的脚本,如果他们想要的话,可以帮助其他人。我会通过添加一些错误检查来改进这个脚本,检查已经下采样的视频文件(我在文件名中用 ._ 表示,但可以使用任何东西)等等,但是在这里你去:

    import subprocess
    import os.path
    import os

    # ------------------------------------------------------------------------------------------------ #
    # GLOBAL VARIABLES #
    # ------------------------------------------------------------------------------------------------ #
    types = (".mp4", ".mov", ".wmv", ".avi") # the tuple of file types
    directory_to_recurse = r"Z:\Python_Projects\Misc\Video_Reformatter"

    # ------------------------------------------------------------------------------------------------ #
    # HELPER FUNCTION - RUN A POWERSHELL COMMAND #
    # ------------------------------------------------------------------------------------------------ #
    def run_powershell_command(cmd):
    completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
    return completed

    # ------------------------------------------------------------------------------------------------ #
    # SIMPLIFIED TEST #
    # ------------------------------------------------------------------------------------------------ #
    # Recursively iterate through all folders in "directory_to_recurse", finding video files
    # along the way
    for root, dirs, files in os.walk(directory_to_recurse):
    # Inspect
    print(root, "\n", dirs, "\n", files, "\n")
    for file in files:
    # If we've found a video file...
    if file.endswith(types):
    # ...parse some data
    full_path_and_file = os.path.join(root, file)
    filename_only = os.path.splitext(file)[0]
    extension_only = os.path.splitext(file)[1]
    # Inspect
    print(full_path_and_file,"\n", filename_only,"\n", extension_only,"\n")
    # Run the ffmpeg downsampling command
    result = run_powershell_command("ffmpeg -i '" + full_path_and_file +
    "' -y -vcodec libx264 -acodec ac3 -threads 2 '" +
    str(root) + "\\" + str(filename_only) + "._" +
    str(extension_only) + "'")
    # Inspect the result object (if desired)
    print("result:", result)
    # If we receive a return code of anything over 0, exit
    if result.returncode >= 1:
    print("ERROR!")
    exit(result.returncode)
    # Once we've successfully downsampled the video, delete the original
    os.remove(os.path.join(root, full_path_and_file))
    continue

    关于PowerShell 和 ffmpeg : No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72891941/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com