Python 3:/:'float'和'bytes'不支持的操作数类型

时间:2015-08-15 14:43:33

标签: python python-3.x

我正在慢慢地尝试将旧的python 2代码转换为Python 3,但是我遇到了包含以下代码的障碍:

seconds = functools.reduce(lambda x,y:x*60+y,map(int,duration.split(":")))

哪位给了我:

  

TypeError:'str'不支持缓冲区接口

我把它改为:

b'functools.reduce(lambda x,y:x*60+y,map(int,duration.split(":")))'

这使得以下行rate = frames/seconds给了我这个错误:

  

TypeError:/:'float'和'bytes'

的不支持的操作数类型

所以我尝试将原始字符串转换为像这样的

seconds = float(functools.reduce(lambda x,y:x*60+y,map(int,duration.split(":"))))

但这只是导致了

  

TypeError:'str'不支持缓冲区接口

任何人都可以看看吗?

import sys,os,re
import functools
from subprocess import *

if len(sys.argv)<=1:
  print ("usage: python oneinn.py filename frames")
  sys.exit(0)

try:
  fvideo = sys.argv[1]
  frames = float(sys.argv[2])
except:
  sys.stderr.write("Failed to parse parameters.\n")
  sys.exit(1)

output = Popen(["ffmpeg", "-i", fvideo], stderr=PIPE).communicate()

# searching and parsing "Duration: 00:05:24.13," from ffmpeg stderr, ignoring the centiseconds
re_duration = re.compile("Duration: (.*?)\.")
duration = b're_duration.search(output[1]).groups()[0]'

seconds = float(functools.reduce(lambda x,y:x*60+y,map(int,duration.split(":"))))
rate = frames/seconds

print ("Duration = %s (%i seconds)" % (duration, seconds))
print ("Capturing one frame every %.1f seconds" % (1/rate))

output = Popen(["ffmpeg", "-i", fvideo, "-r", str(rate), "-vcodec", "png", 'Preview-%d.png']).communicate()

0 个答案:

没有答案