这让我发疯。
我正在使用光纤通过SSH在远程服务器上执行一些视频处理任务。

我拨打了远程计算机上的ffprobe的电话,以获取返回视频的信息,该视频将在我们进入此功能之前发送到该服务器。我正在尝试从ffprobe的输出中分析有关Duration的内容,以便以秒为单位获取视频的长度。这是函数的麻烦部分,我似乎无法将字符串转换为整数。

with cd("~/videos"):
   command = "ffprobe  "
   command += videoNameOnly
   output = run(command)
   durationIndex = output.find("Duration:")
   durationIndex = durationIndex + 10
   duration = output[durationIndex:]
   durationFrags = duration.split(":")
   print "====================================="
   print durationFrags[0].strip()
   print durationFrags[1].strip()
   print durationFrags[2].strip()
   hours = int(durationFrags[0].strip())

输出如下
00
00
52.90, start
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 712, in main
    *args, **kwargs
  File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 298, in execute
    multiprocessing
  File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 197, in _execute
    return task.run(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 112, in run
    return self.wrapped(*args, **kwargs)
  File "/home/amyface/fabfile.py", line 26, in main
    encode();
  File "/home/amyface/fabfile.py", line 34, in encode
    runJobs(jobs,cursor)
  File "/home/amyface/fabfile.py", line 60, in runJobs
    getMiddleFrame(sourceVideo,videoNameOnly,cursor)
  File "/home/amyface/fabfile.py", line 96, in getMiddleFrame
    hours = int(durationFrags[0].strip())
ValueError: invalid literal for int() with base 10: '\x1b[0m\x1b[0;39m\x1b[0m\x1b[0;39m\x1b[0m\x1b[0;39m00'
Disconnecting from [I have removed the server name from here]

怎么不让我将“00”转换成整数?
另外,“以10为底”之后的错误中的奇怪值是什么?

最佳答案

我对织物一无所知,但是根据ValueErrordurationFrags[0].strip()'\x1b[0m\x1b[0;39m\x1b[0m\x1b[0;39m\x1b[0m\x1b[0;39m00',而不是'00'。这会产生设计用于终端的输出吗?在我看来,这些看起来像是ANSI转义代码。

关于python - 无法在结构中使用python将字符串转换为整数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11161374/

10-10 17:29