Skip to content

Commit

Permalink
updated converter
Browse files Browse the repository at this point in the history
fixed bug with samplerate
updated error checking to allow for better compliance
  • Loading branch information
Michael Higgins committed Mar 5, 2015
1 parent a850308 commit 59f6385
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 61 deletions.
126 changes: 66 additions & 60 deletions converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,66 +72,72 @@ def parse_options(self, opt, twopass=None):
if 'audio' not in opt and 'video' not in opt and 'subtitle' not in opt:
raise ConverterError('Neither audio nor video nor subtitle streams requested')

if 'audio' in opt:
y = opt['audio']

# Creates the new nested dictionary to preserve backwards compatability
try:
first = y.values()[0]
if not isinstance(first, dict) and first is not None:
y = {0: y}
except IndexError:
pass

for n in y:
x = y[n]

if not isinstance(x, dict) or 'codec' not in x:
raise ConverterError('Invalid audio codec specification')

if 'path' in x and 'source' not in x:
raise ConverterError('Cannot specify audio path without FFMPEG source number')

if 'source' in x and 'path' not in x:
raise ConverterError('Cannot specify alternate input source without a path')

c = x['codec']
if c not in self.audio_codecs:
raise ConverterError('Requested unknown audio codec ' + str(c))

audio_options.extend(self.audio_codecs[c]().parse_options(x, n))
if audio_options is None:
raise ConverterError('Unknown audio codec error')

if 'subtitle' in opt:
y = opt['subtitle']

# Creates the new nested dictionary to preserve backwards compatability
try:
first = y.values()[0]
if not isinstance(first, dict) and first is not None:
y = {0: y}
except IndexError:
pass

for n in y:
x = y[n]
if not isinstance(x, dict) or 'codec' not in x:
raise ConverterError('Invalid subtitle codec specification')

if 'path' in x and 'source' not in x:
raise ConverterError('Cannot specify subtitle path without FFMPEG source number')

if 'source' in x and 'path' not in x:
raise ConverterError('Cannot specify alternate input source without a path')

c = x['codec']
if c not in self.subtitle_codecs:
raise ConverterError('Requested unknown subtitle codec ' + str(c))

subtitle_options.extend(self.subtitle_codecs[c]().parse_options(x, n))
if subtitle_options is None:
raise ConverterError('Unknown subtitle codec error')
if 'audio' not in opt:
opt['audio'] = {'codec': None}

if 'subtitle' not in opt:
opt['subtitle'] = {'codec': None}

# Audio
y = opt['audio']

# Creates the new nested dictionary to preserve backwards compatability
try:
first = list(y.values())[0]
if not isinstance(first, dict):
y = {0: y}
except IndexError:
pass

for n in y:
x = y[n]

if not isinstance(x, dict) or 'codec' not in x:
raise ConverterError('Invalid audio codec specification')

if 'path' in x and 'source' not in x:
raise ConverterError('Cannot specify audio path without FFMPEG source number')

if 'source' in x and 'path' not in x:
raise ConverterError('Cannot specify alternate input source without a path')

c = x['codec']
if c not in self.audio_codecs:
raise ConverterError('Requested unknown audio codec ' + str(c))

audio_options.extend(self.audio_codecs[c]().parse_options(x, n))
if audio_options is None:
raise ConverterError('Unknown audio codec error')

# Subtitle
y = opt['subtitle']

# Creates the new nested dictionary to preserve backwards compatability
try:
first = list(y.values())[0]
if not isinstance(first, dict):
y = {0: y}
except IndexError:
pass

for n in y:
x = y[n]
if not isinstance(x, dict) or 'codec' not in x:
raise ConverterError('Invalid subtitle codec specification')

if 'path' in x and 'source' not in x:
raise ConverterError('Cannot specify subtitle path without FFMPEG source number')

if 'source' in x and 'path' not in x:
raise ConverterError('Cannot specify alternate input source without a path')

c = x['codec']
if c not in self.subtitle_codecs:
raise ConverterError('Requested unknown subtitle codec ' + str(c))

subtitle_options.extend(self.subtitle_codecs[c]().parse_options(x, n))
if subtitle_options is None:
raise ConverterError('Unknown subtitle codec error')

if 'video' in opt:
x = opt['video']
Expand Down
2 changes: 1 addition & 1 deletion converter/avcodecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def parse_options(self, opt, stream=0):
if 'bitrate' in safe:
optlist.extend(['-b:a:' + stream, str(safe['bitrate']) + 'k'])
if 'samplerate' in safe:
optlist.extend(['-r:a:' + stream, str(safe['samplerate'])])
optlist.extend(['-ar:a:' + stream, str(safe['samplerate'])])
if 'language' in safe:
lang = str(safe['language'])
else:
Expand Down

0 comments on commit 59f6385

Please sign in to comment.