bash - ffmpeg 命令在 python 中使用时出错

标签 bash shell unix ffmpeg

当我从 shell 运行这个命令时,它工作得很好。

ffmpeg -nostdin -i /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi -ss 00:00:00 -vcodec h264 -vf fps=25 -to 00:6:43 /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi

但是当我在 python 中做同样的事情时,它会给出错误:
import sys
import os

INPUT_DIR = sys.argv[1]
INPUT_VIDEO = sys.argv[2]
OUTPUT_PATH = sys.argv[3]
SOURCE = sys.argv[4]
DATE = sys.argv[5]

INPUT = INPUT_DIR+"sorted_result.txt"
COUNT=1
initial="00:00:00"

with open(INPUT,"r") as f:
  for line in f.readlines():
    OUT_DIR = OUTPUT_PATH+str(COUNT)
    directory = os.path.abspath(OUT_DIR)
    print('OUT DIR',OUT_DIR)
    print('directory',directory)
    try:
      os.mkdir(directory)
    except:
      pass
    cmd_1 = "ffmpeg -nostdin -i "+INPUT_VIDEO+" -ss " +initial+ " -vcodec h264 -vf fps=25 -to " +line+ " " +OUT_DIR+"/"+str(COUNT)+".avi"
os.system(cmd_1)
    COUNT += 1
    initial=line

我无法理解问题:

错误如下:
ffmpeg version 4.0-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-libxml2 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Trailing options were found on the commandline.
Input #0, avi, from '/data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/tmp/merged.avi':
  Metadata:
    encoder         : Lavf58.12.100
  Duration: 01:00:50.23, start: 0.000000, bitrate: 1334 kb/s
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 512x288 [SAR 1:1 DAR 16:9], 1001 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 639 kb/s
At least one output file must be specified
sh: line 1: /data/binil/v2t_final/output/cnbctv18/2018_07_02_14_38_30/1/1.avi: Permission denied

请帮忙。
这是我正在写的一些虚拟文本,因为看起来堆栈溢出不接受更少的描述和更多的代码。请不要介意这些句子。我不敢相信我还在写这篇文章,它仍然要求我添加更多描述。我还在做。不知道要写到什么程度。我希望这么多就足够了。

最佳答案

得到错误。
输入文件在新行中包含每个时间戳,因此它使用 '\n' 字符以及 ffmpeg 命令中的时间戳。因此它将 -vcodec 视为新命令并导致错误。

关于bash - ffmpeg 命令在 python 中使用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51148823/

相关文章:

java - 如何添加名为: `-DurlParams=intent=REGULAR&auto=w1` 的java系统属性

mysql - 在范围内选择一个数字,它不会与 bash shell 中存在的数字冲突

linux - 如何在linux脚本中提取字符串中的数字和特殊字符

c - 在 lubuntu 上使用 gcc 编译器运行 c

linux - bash 如何终止父进程,或从 bash 模块脚本中的函数退出父进程

linux - 我的 bash 脚本 (linux) 中的错误计数器在 while 语句期间不计数

c++ - 为什么要使用 umask?

c++ - pthread 启动函数中的 return() 与 pthread_exit()

html - 执行从 HTTP 调用的 BASH Linux 脚本

bash - 启动一个新的 tmux session 并分离它,所有这些都在一个 shell 脚本中