add and rewrite parts of documentation

This commit is contained in:
Mathias Koehler 2011-12-11 21:27:14 +01:00
parent 113a0a1f00
commit 6b584c7d7e
2 changed files with 28 additions and 1 deletions

View file

@ -34,6 +34,9 @@ API
.. autoclass:: FFmpeg .. autoclass:: FFmpeg
:members: :members:
.. autoclass:: ffmpegwrapper.ffmpeg.FFmpegProcess
:members:
Input/Output Input/Output
~~~~~~~~~~~~ ~~~~~~~~~~~~

View file

@ -57,6 +57,10 @@ class Output(OptionStore):
class FFmpegProcess(object): class FFmpegProcess(object):
"""Class to exectute FFmpeg.
:param command: a sequence of the binary and it arguments
"""
def __init__(self, command): def __init__(self, command):
self.command = list(command) self.command = list(command)
@ -64,6 +68,8 @@ class FFmpegProcess(object):
self.process = None self.process = None
def _queue_output(self, out, queue): def _queue_output(self, out, queue):
"""Read the output from the command bytewise. On every newline
the line is put to the queue."""
line = '' line = ''
while self.process.poll() is None: while self.process.poll() is None:
chunk = out.read(1).decode('utf-8') chunk = out.read(1).decode('utf-8')
@ -76,6 +82,12 @@ class FFmpegProcess(object):
out.close() out.close()
def run(self): def run(self):
"""Executes the command. A thread will be started to collect
the outputs (stderr and stdout) from that command.
The outputs will be written to the queue.
:return: self
"""
self.process = Popen(self.command, bufsize=1, self.process = Popen(self.command, bufsize=1,
stdin=PIPE, stdout=PIPE, stderr=STDOUT) stdin=PIPE, stdout=PIPE, stderr=STDOUT)
thread = Thread(target=self._queue_output, thread = Thread(target=self._queue_output,
@ -85,6 +97,12 @@ class FFmpegProcess(object):
return self return self
def readlines(self, keepends=False): def readlines(self, keepends=False):
"""Yield lines from the queue that were collected from the
command. You can specify if you want to keep newlines at the ends.
Default is to drop them.
:param keepends: keep the newlines at the end. Default=False
"""
while self.process.poll() is None: while self.process.poll() is None:
try: try:
line = self.queue.get(timeout=0.1) line = self.queue.get(timeout=0.1)
@ -108,7 +126,7 @@ class FFmpegProcess(object):
class FFmpeg(OptionStore): class FFmpeg(OptionStore):
"""This class represent the FFmpeg command. """This class represent the FFmpeg command.
It behaves like a list. If you iterate over the class it will yield It behaves like a list. If you iterate over the object it will yield
small parts from the ffmpeg command with it arguments. The arguments small parts from the ffmpeg command with it arguments. The arguments
for the command are in the Option classes. They can be appended directly for the command are in the Option classes. They can be appended directly
or through one or more Stores. or through one or more Stores.
@ -126,6 +144,12 @@ class FFmpeg(OptionStore):
self._list.insert(0, Option({key: value})) self._list.insert(0, Option({key: value}))
def run(self): def run(self):
"""Executes the command of this object. Return a
:class:`FFmpegProcess` object which have already the
:meth:`FFmpegProcess.run` invoked.
:return: :class:`FFmpegProcess` object with `run()` invoked
"""
return FFmpegProcess(self).run() return FFmpegProcess(self).run()
def __enter__(self): def __enter__(self):