work around ffmpeg2theora problems with some metadata output

This commit is contained in:
j 2010-11-15 17:35:07 +01:00
parent 59741c9cd0
commit 36b2fec446

View file

@ -4,6 +4,7 @@
from __future__ import division from __future__ import division
import os import os
import hashlib import hashlib
import re
import sys import sys
import struct import struct
import subprocess import subprocess
@ -63,5 +64,13 @@ def avinfo(filename):
if os.path.getsize(filename): if os.path.getsize(filename):
p = subprocess.Popen(['ffmpeg2theora', '--info', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['ffmpeg2theora', '--info', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
info, error = p.communicate() info, error = p.communicate()
return json.loads(info) try:
info = json.loads(info)
except:
#remove metadata, can be broken
reg = re.compile('"metadata": {.*?},', re.DOTALL)
info = re.sub(reg, '', info)
info = json.loads(info)
return info
return {'path': filename, 'size': 0} return {'path': filename, 'size': 0}