使用FFMPEG + Python修剪视频:无效参数

时间:2019-06-26 07:54:58

标签: python video ffmpeg

我正在寻找一个简短的Python脚本,根据我使用时间码创建的.txt文件自动为我进行一些视频剪辑。我为此使用以下代码:

#!/usr/bin/env python3
import subprocess
first = True
with open('VideoSlicepoints_Python.txt') as f:
  for line in f.readlines():
    if first:
        first = False
    else:
        filename, VideoDing_Timecode, Video_R4Start, Video_R4End, Video_R24Start, Video_R24End, Video_R0plus15 = line.strip().split(';')
        cmd = ['ffmpeg', '-i', filename, '-ss', Video_R4Start, '-to', Video_R4End, '-c', 'copy', '"S:/_RobotThesis/VideoRounds/' + filename[:-4] + '_r4' + filename[-4:] + '"']
        print(" ".join(cmd))
        subprocess.run(cmd, stderr=subprocess.STDOUT)

当它尝试循环到视频时,这会向我返回以下错误:

[NULL @ 0000027cddf8a100] Unable to find a suitable output format for '"S:/_RobotThesis/VideoRounds/log1_front_r4.MTS"'
"S:/_RobotThesis/VideoRounds/log1_front_r4.MTS": Invalid argument

现在,我认为这是一个格式问题,但是当我直接输入命令时(在CMD提示符中可见),它就可以正常工作:

ffmpeg -i log1_front.MTS -ss 09:37.1 -to 11:37.1 -c copy "S:/_RobotThesis/VideoRounds/log1_front_r4.MTS"

作为参考,这是我正在使用的.txt文件的摘录(它基于csv文件,这就是为什么它具有标头,而我在脚本中排除了标头的原因):

Filename;VideoDing_Timecode;Video_R4Start;Video_R4End;Video_R24Start;Video_R24End;Video_R0plus15
log1_front.MTS;04:44.0;09:37.1;11:37.1;28:00.3;30:00.3;19:44.0
log2_front.MTS;03:50.0;08:11.2;10:11.2;19:44.9;21:44.9;18:50.0
log3_front.MTS;04:10.1;08:32.4;10:32.4;16:49.2;18:49.2;19:10.1
log5_front.MTS;01:14.7;04:50.2;06:50.2;14:24.5;16:24.5;16:14.7
  

编辑:

以下是CMD中的完整输出:

ffmpeg -i log1_front.MTS -ss 09:37.1 -to 11:37.1 -c copy "S:/_RobotThesis/VideoRounds/log1_front_r4.MTS"
ffmpeg version N-94054-gdd357d76e5 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 28.100 / 56. 28.100
  libavcodec     58. 53.100 / 58. 53.100
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 55.100 /  7. 55.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mpegts, from 'log1_front.MTS':
  Duration: 00:37:35.05, start: 1.440000, bitrate: 12560 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(top first), 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 256 kb/s
[NULL @ 000002d1f347a100] Unable to find a suitable output format for '"S:/_RobotThesis/VideoRounds/log1_front_r4.MTS"'
"S:/_RobotThesis/VideoRounds/log1_front_r4.MTS": Invalid argument

1 个答案:

答案 0 :(得分:0)

显然,当我直接输入命令时,需要使用双引号。但是,当我使用Python时,我需要删除这些双引号。不知道为什么会这样,但是对于想要剪切视频的任何人,以供将来参考,下面是正确的代码:

<img src="/MyPath/image.jpg" />