- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 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 栏中直接复制粘贴。
我尝试过的事情包括:
$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/
我是一名优秀的程序员,十分优秀!