Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self._next_frame = None
        self.quitted = False
        self._log_callback_set = False
        self._callback_ref = WeakMethod(self._player_callback)

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(VideoFFPy, self).__init__(**kwargs)
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self.quitted = False
        self._log_callback_set = False
        self._state = ''
        self.state = 'stop'

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(SoundFFPy, self).__init__(**kwargs)
Ejemplo n.º 3
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self.quitted = False
        self._log_callback_set = False
        self._state = ''
        self.state = 'stop'

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(SoundFFPy, self).__init__(**kwargs)
Ejemplo n.º 4
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self._next_frame = None
        self.quitted = False
        self._log_callback_set = False
        self._callback_ref = WeakMethod(self._player_callback)

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(VideoFFPy, self).__init__(**kwargs)
Ejemplo n.º 5
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self._thread = None
        self._next_frame = None
        self._ffplayer_need_quit = False
        self._log_callback_set = False
        self._callback_ref = WeakMethod(self._player_callback)
        self._trigger = Clock.create_trigger(self._redraw)

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(VideoFFPy, self).__init__(**kwargs)
Ejemplo n.º 6
0
    def __init__(self, **kwargs):
        self._ffplayer = None
        self._thread = None
        self._next_frame = None
        self._ffplayer_need_quit = False
        self._log_callback_set = False
        self._callback_ref = WeakMethod(self._player_callback)
        self._trigger = Clock.create_trigger(self._redraw)

        if not get_log_callback():
            set_log_callback(_log_callback)
            self._log_callback_set = True

        super(VideoFFPy, self).__init__(**kwargs)
Ejemplo n.º 7
0
from ffpyplayer.tools import set_log_callback

from kivy.clock import Clock
from kivy.properties import (NumericProperty, ReferenceListProperty,
                             ObjectProperty, ListProperty, StringProperty,
                             BooleanProperty, DictProperty, AliasProperty,
                             OptionProperty, ConfigParserProperty)
from kivy.event import EventDispatcher
from kivy.logger import Logger

from cpl_media import error_guard
from .common import KivyMediaBase

__all__ = ('BasePlayer', 'VideoMetadata')

set_log_callback(logger=Logger, default_only=True)
logging.info('cpl_media: Using ffpyplayer {}'.format(ffpyplayer.__version__))

VideoMetadata = namedtuple('VideoMetadata', ['fmt', 'w', 'h', 'rate'])
"""Namedtuple type describing a video stream.
"""


class BasePlayer(EventDispatcher, KivyMediaBase):
    """Base class for every player.
    """

    _config_props_ = ('metadata_play', 'metadata_play_used')

    display_frame = None
    """Called from kivy thread to display the frame whenever a new image
Ejemplo n.º 8
0
 def __del__(self):
     self.unload()
     if self._log_callback_set:
         set_log_callback(None)
Ejemplo n.º 9
0
    'error': Logger.error,
    'warning': Logger.warning,
    'info': Logger.info,
    'verbose': Logger.debug,
    'debug': Logger.debug
}


def _log_callback(message, level):
    message = message.strip()
    if message:
        logger_func[level]('ffpyplayer: {}'.format(message))


if not get_log_callback():
    set_log_callback(_log_callback)


class VideoFFPy(VideoBase):

    YUV_RGB_FS = """
    $HEADER$
    uniform sampler2D tex_y;
    uniform sampler2D tex_u;
    uniform sampler2D tex_v;

    void main(void) {
        float y = texture2D(tex_y, tex_coord0).r;
        float u = texture2D(tex_u, tex_coord0).r - 0.5;
        float v = texture2D(tex_v, tex_coord0).r - 0.5;
        float r = y +             1.402 * v;
Ejemplo n.º 10
0
Logger.info('VideoFFPy: Using ffpyplayer {}'.format(ffpyplayer.version))


logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
               'fatal': Logger.critical, 'error': Logger.error,
               'warning': Logger.warning, 'info': Logger.info,
               'verbose': Logger.debug, 'debug': Logger.debug}


def _log_callback(message, level):
    message = message.strip()
    if message:
        logger_func[level]('ffpyplayer: {}'.format(message))

if not get_log_callback():
    set_log_callback(_log_callback)


class VideoFFPy(VideoBase):

    YUV_RGB_FS = """
    $HEADER$
    uniform sampler2D tex_y;
    uniform sampler2D tex_u;
    uniform sampler2D tex_v;

    void main(void) {
        float y = texture2D(tex_y, tex_coord0).r;
        float u = texture2D(tex_u, tex_coord0).r - 0.5;
        float v = texture2D(tex_v, tex_coord0).r - 0.5;
        float r = y +             1.402 * v;
Ejemplo n.º 11
0
 def __del__(self):
     self.unload()
     if self._log_callback_set:
         set_log_callback(None)
Ejemplo n.º 12
0
__all__ = ('get_media', )

from os import environ
from os.path import join, abspath, dirname, exists

from ffpyplayer.tools import set_loglevel, set_log_callback
import logging

set_log_callback(logger=logging, default_only=True)
set_loglevel('trace')

def get_media(fname):
    if exists(fname):
        return abspath(fname)

    root = dirname(__file__)
    if exists(join(root, fname)):
        return join(root, fname)

    ex = abspath(join(root, '../../examples', fname))
    if exists(ex):
        return ex

    if 'FFPYPLAYER_TEST_DIRS' in environ:
        for d in environ['FFPYPLAYER_TEST_DIRS'].split(';'):
            d = d.strip()
            if not d:
                continue

            if exists(join(d, fname)):
Ejemplo n.º 13
0
            self.root.image.texture = None
            self.root.image.texture = self.texture
            self.root.seek.value = pts
            logging.debug('ffpyplayer: Blitted new frame with time: {}.'
                          .format(pts))

        if self.root.seek.value:
            self.root.seek.max = self.ffplayer.get_metadata()['duration']

    def display_subtitle(self, text, fmt, pts, t_start, t_end):
        pass # fmt is text (unformatted), or ass (formatted subs)

    def reload_buffer(self, *args):
        logging.debug('ffpyplayer: Reloading buffer.')
        frame = self.next_frame
        if not frame:
            return
        self.texture.blit_buffer(frame[0].to_memoryview()[0], colorfmt='rgb',
                                 bufferfmt='ubyte')

if __name__ == '__main__':
    set_log_callback(log_callback)
    a = PlayerApp()
    a.run()
    # because MediaPlayer runs non-daemon threads, when the main thread exists
    # it'll get stuck waiting for those threads to close, so we manually
    # have to delete these threads by deleting the MediaPlayer object.
    a._done = True
    a.ffplayer = None
    set_log_callback(None)
Ejemplo n.º 14
0
__all__ = ('get_media', )

from os import environ
from os.path import join, abspath, dirname, exists

from ffpyplayer.tools import set_loglevel, set_log_callback
import logging

set_log_callback(logger=logging, default_only=True)
set_loglevel('trace')

def get_media(fname):
    if exists(fname):
        return abspath(fname)

    root = dirname(__file__)
    if exists(join(root, fname)):
        return join(root, fname)

    ex = abspath(join(root, '../../examples', fname))
    if exists(ex):
        return ex

    if 'FFPYPLAYER_TEST_DIRS' in environ:
        for d in environ['FFPYPLAYER_TEST_DIRS'].split(';'):
            d = d.strip()
            if not d:
                continue

            if exists(join(d, fname)):