diff --git a/ffmpegwrapper/codec.py b/ffmpegwrapper/codec.py index 5bdc017..757f237 100644 --- a/ffmpegwrapper/codec.py +++ b/ffmpegwrapper/codec.py @@ -2,18 +2,18 @@ from itertools import chain -from .options import CombinedOptions +from .options import OptionStore NO_AUDIO = ['-an'] NO_VIDEO = ['-vn'] -class Codec(CombinedOptions): +class Codec(OptionStore): def __init__(self, name, *args): self.name = name - CombinedOptions.__init__(self, *args) + OptionStore.__init__(self, *args) class VideoCodec(Codec): diff --git a/ffmpegwrapper/ffmpeg.py b/ffmpegwrapper/ffmpeg.py index f45b890..f00e392 100644 --- a/ffmpegwrapper/ffmpeg.py +++ b/ffmpegwrapper/ffmpeg.py @@ -16,38 +16,39 @@ from select import select from subprocess import Popen, PIPE, STDOUT from itertools import chain -from .options import CombinedOptions, Options +from .options import OptionStore, Option -class Input(CombinedOptions): +class Input(OptionStore): def __init__(self, file, *args): self.file = file - CombinedOptions.__init__(self, *args) + OptionStore.__init__(self, *args) def __iter__(self): - return chain(CombinedOptions.__iter__(self), ['-i', self.file]) + return chain(OptionStore.__iter__(self), ['-i', self.file]) +class Output(OptionStore): -class Output(CombinedOptions): def __init__(self, file, *args): self.file = file - CombinedOptions.__init__(self, *args) + OptionStore.__init__(self, *args) def overwrite(self): self.add_option('-y', None) return self def __iter__(self): - return chain(CombinedOptions.__iter__(self), [self.file]) + return chain(OptionStore.__iter__(self), [self.file]) -class FFmpeg(CombinedOptions): +class FFmpeg(OptionStore): + def __init__(self, binary="ffmpeg", *args): self.binary = binary - CombinedOptions.__init__(self, *args) + OptionStore.__init__(self, *args) def run(self): self.pipe = Popen(self, executable=self.binary, diff --git a/ffmpegwrapper/filter.py b/ffmpegwrapper/filter.py index 6d56fd8..cfdda6c 100644 --- a/ffmpegwrapper/filter.py +++ b/ffmpegwrapper/filter.py @@ -2,23 +2,23 @@ from itertools import chain -from .options import CombinedOptions +from .options import OptionStore -class CombinedFilter(CombinedOptions): +class FilterStore(OptionStore): def __str__(self): - return ",".join(CombinedFilter.__iter__(self)) + return ",".join(FilterStore.__iter__(self)) def __iter__(self): - for key, value in CombinedOptions.iteritems(self): + for key, value in OptionStore.iteritems(self): if value is not None: yield "=".join([key, str(value)]) else: yield key -class VideoFilter(CombinedFilter): +class VideoFilter(FilterStore): def blackframe(self, amount, threshold): filter = self._format_parameter(amount, threshold) @@ -171,14 +171,14 @@ class VideoFilter(CombinedFilter): return self def __iter__(self): - return chain(['-vf', CombinedFilter.__str__(self)]) + return chain(['-vf', FilterStore.__str__(self)]) -class AudioFilter(CombinedFilter): +class AudioFilter(FilterStore): def null(self): self.add_option('null', None) return self def __iter__(self): - return chain(['-af', CombinedFilter.__str__(self)]) + return chain(['-af', FilterStore.__str__(self)]) diff --git a/ffmpegwrapper/options.py b/ffmpegwrapper/options.py index 232f526..fb7dcad 100644 --- a/ffmpegwrapper/options.py +++ b/ffmpegwrapper/options.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -class Options(dict): +class Option(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) @@ -25,7 +25,7 @@ class Options(dict): cls=self.__class__.__name__) -class CombinedOptions(object): +class OptionStore(object): def __init__(self, *args): self._list = list(args) @@ -52,7 +52,7 @@ class CombinedOptions(object): return self._list.index(item) def add_option(self, key, value): - self._list.append(Options({key: value})) + self._list.append(Option({key: value})) @property def option_containers(self): diff --git a/test.py b/test.py index 23ad3e8..71207f2 100644 --- a/test.py +++ b/test.py @@ -4,7 +4,7 @@ import unittest from ffmpegwrapper import FFmpeg, Input, Output, \ VideoCodec, AudioCodec, VideoFilter -from ffmpegwrapper.options import Options +from ffmpegwrapper.options import Option class FFmpegTestCase(unittest.TestCase): @@ -14,7 +14,7 @@ class FFmpegTestCase(unittest.TestCase): self.assertEqual(list(input), ['-i', '/old']) self.assertEqual(input.file, '/old') - option = Options({'-vf': 'x11grab'}) + option = Option({'-vf': 'x11grab'}) input.append(option) self.assertEqual(list(input), ['-vf', 'x11grab', '-i', '/old']) self.assertEqual(input.pop(), option) @@ -27,7 +27,7 @@ class FFmpegTestCase(unittest.TestCase): self.assertEqual(list(output), ['/new']) self.assertEqual(output.file, '/new') - option = Options({'-vcodec': 'libx264'}) + option = Option({'-vcodec': 'libx264'}) output.append(option) self.assertEqual(list(output), ['-vcodec', 'libx264', '/new']) self.assertEqual(output.pop(), option)