无法识别的选项'c副本'
问题描述:
我一直在研究脚本作为学习过程和创建方便工具的一部分。我试图循环播放列表中的视频文件来提取每个视频的某个部分。通过查看示例脚本和ffmpeg的文档,我终于想出了这一点:无法识别的选项'c副本'
import os
import sys
import subprocess as sp
from moviepy.tools import subprocess_call
def ffmpeg_extract_pandomim_subclip():
with open('videolist.txt') as f:
lines = f.readlines()
lines = [x.strip() for x in lines]
for video in lines:
name, ext = os.path.splitext(video)
targetname = "%s-pandomim%s" % (name, ext)
t1 = "00:10:00"
t2 = "00:15:00"
cmd = ["ffmpeg",
"-i", "%s%s" % (name, ext),
"-ss", t1,
"-to", t2, "-c copy", targetname]
subprocess_call(cmd)
ffmpeg_extract_pandomim_subclip()
我知道这是不是这样做的理想方式:我创建了一个videolist.txt并在TXT列出的所有视频文件名文件,逐行,(T1-1.mp4,T1-2.mp4,...)与python脚本“new 1.py”和实际的视频T1-1.mp4共享相同的文件夹, T1-2.mp4,...
这个错误让我很困惑,因为当我从cmd使用-c复制时,它工作得很好。
完整的错误是:
C:\Users\çomak\AppData\Local\Programs\Python\Python35-32\python.exe "C:/ffmpeg/bin/new 1.py"
[MoviePy] Running:
>>> ffmpeg -i T1-1.mp4 -ss 00:10:00 -to 00:15:00 -c copy T1-1-pandomim.mp4
[MoviePy] This command returned an error !Traceback (most recent call last):
File "C:/ffmpeg/bin/new 1.py", line 28, in <module>
ffmpeg_extract_pandomim_subclip()
File "C:/ffmpeg/bin/new 1.py", line 25, in ffmpeg_extract_pandomim_subclip
subprocess_call(cmd)
File "C:\Users\çomak\AppData\Local\Programs\Python\Python35-32\lib\site-packages\moviepy\tools.py", line 48, in subprocess_call
raise IOError(err.decode('utf8'))
OSError: ffmpeg version N-83975-g6c4665d Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 6.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil 55. 48.100/55. 48.100
libavcodec 57. 83.100/57. 83.100
libavformat 57. 66.104/57. 66.104
libavdevice 57. 3.100/57. 3.100
libavfilter 6. 76.100/6. 76.100
libswscale 4. 3.101/4. 3.101
libswresample 2. 4.100/2. 4.100
libpostproc 54. 2.100/54. 2.100
Unrecognized option 'c copy'.
Error splitting the argument list: Option not found
Process finished with exit code 1
我使用Pycharm,如果我删除它的工作拷贝-c部分,但是这个过程是缓慢的...用-c副本,它的速度要快得多。
我很感谢您的时间和精力来帮助我!
答
这将是由于subprocess.call
实际调用该命令的方式;你不能将所有的命令压缩成一个字符串,它们应该完全展开。
为了解决这个问题,只需将其扩展为两个参数,他们是
[ ..., "-c, "copy", ... ]
你可以尝试扩大这两个单独的参数,他们是:'“-c”,“复制”'? –
太棒了!非常感谢克拉克先生。我会记住这些细节 –