How to use ffpyplayer - 10 common examples

To help you get started, we’ve selected a few ffpyplayer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BillBillBillBill / Tickeys-linux / tickeys / kivy / core / audio / audio_ffpyplayer.py View on Github external
def load(self):
        self.unload()
        ff_opts = {'vn': True, 'sn': True}  # only audio
        self._ffplayer = MediaPlayer(self.source,
                                     callback=self._callback_ref,
                                     loglevel='info', ff_opts=ff_opts)
        player = self._ffplayer
        player.set_volume(self.volume)
        player.toggle_pause()
        self._state = 'paused'
        # wait until loaded or failed, shouldn't take long, but just to make
        # sure metadata is available.
        s = time.clock()
        while ((not player.get_metadata()['duration'])
               and not self.quitted and time.clock() - s < 10.):
            time.sleep(0.005)
github snuq / Snu-Photo-Manager / generalelements.py View on Github external
def open_video(self):
        self.player = MediaPlayer(self.source, ff_opts={'paused': True, 'ss': 1.0, 'an': True})
        frame = None
        while not frame:
            frame, value = self.player.get_frame(force_refresh=True)
        data = self.player.get_metadata()
        self.length = data['duration']
        self.framerate = data['frame_rate']
        self.pixel_format = data['src_pix_fmt']
github snuq / Snu-Photo-Manager / main.py View on Github external
extension = os.path.splitext(fullpath)[1].lower()

        try:
            if extension in imagetypes:
                #This is an image file, use PIL to generate a thumnail
                image = Image.open(full_filename)
                image.thumbnail((self.thumbsize, self.thumbsize), Image.ANTIALIAS)
                if image.mode != 'RGB':
                    image = image.convert('RGB')
                output = BytesIO()
                image.save(output, 'jpeg')
                thumbnail = output.getvalue()

            elif extension in movietypes:
                #This is a video file, use ffpyplayer to generate a thumbnail
                player = MediaPlayer(full_filename, ff_opts={'paused': True, 'ss': 1.0, 'an': True})
                frame = None
                while not frame:
                    frame, value = player.get_frame(force_refresh=True)
                player.close_player()
                player = None
                frame = frame[0]
                frame_size = frame.get_size()
                frame_converter = SWScale(frame_size[0], frame_size[1], frame.get_pixel_format(), ofmt='rgb24')
                new_frame = frame_converter.scale(frame)
                image_data = bytes(new_frame.to_bytearray()[0])

                image = Image.frombuffer(mode='RGB', size=(frame_size[0], frame_size[1]), data=image_data, decoder_name='raw')
                image = image.transpose(1)

                image.thumbnail((self.thumbsize, self.thumbsize), Image.ANTIALIAS)
                output = BytesIO()
github kivy / kivy / kivy / core / audio / audio_ffpyplayer.py View on Github external
def load(self):
        self.unload()
        ff_opts = {'vn': True, 'sn': True}  # only audio
        self._ffplayer = MediaPlayer(self.source,
                                     callback=self._player_callback,
                                     loglevel='info', ff_opts=ff_opts)
        player = self._ffplayer
        player.set_volume(self.volume)
        player.toggle_pause()
        self._state = 'paused'
        # wait until loaded or failed, shouldn't take long, but just to make
        # sure metadata is available.
        s = time.perf_counter()
        while ((not player.get_metadata()['duration']) and
               not self.quitted and time.perf_counter() - s < 10.):
            time.sleep(0.005)
github kivy / kivy / kivy / core / video / video_ffpyplayer.py View on Github external
def play(self):
        if self._ffplayer and self._state == 'paused':
            self._ffplayer.toggle_pause()
            self._state = 'playing'
            return

        self.load()
        self._out_fmt = 'rgba'
        ff_opts = {
            'paused': True,
            'out_fmt': self._out_fmt,
            'sn': True,
            'volume': self._volume,
        }
        self._ffplayer = MediaPlayer(
                self._filename, callback=self._player_callback,
                thread_lib='SDL',
                loglevel='info', ff_opts=ff_opts)

        # Disabled as an attempt to fix kivy issue #6210
        # self._ffplayer.set_volume(self._volume)

        self._thread = Thread(target=self._next_frame_run, name='Next frame')
        self._thread.daemon = True
        self._thread.start()
github snuq / Snu-Photo-Manager / main.py View on Github external
image = image.convert('RGB')
                output = BytesIO()
                image.save(output, 'jpeg')
                thumbnail = output.getvalue()

            elif extension in movietypes:
                #This is a video file, use ffpyplayer to generate a thumbnail
                player = MediaPlayer(full_filename, ff_opts={'paused': True, 'ss': 1.0, 'an': True})
                frame = None
                while not frame:
                    frame, value = player.get_frame(force_refresh=True)
                player.close_player()
                player = None
                frame = frame[0]
                frame_size = frame.get_size()
                frame_converter = SWScale(frame_size[0], frame_size[1], frame.get_pixel_format(), ofmt='rgb24')
                new_frame = frame_converter.scale(frame)
                image_data = bytes(new_frame.to_bytearray()[0])

                image = Image.frombuffer(mode='RGB', size=(frame_size[0], frame_size[1]), data=image_data, decoder_name='raw')
                image = image.transpose(1)

                image.thumbnail((self.thumbsize, self.thumbsize), Image.ANTIALIAS)
                output = BytesIO()
                image.save(output, 'jpeg')
                thumbnail = output.getvalue()
            return thumbnail
        except:
            return None
github BillBillBillBill / Tickeys-linux / tickeys / kivy / core / image / img_ffpyplayer.py View on Github external
self.filename = filename
        images = []

        while True:
            frame, t = loader.next_frame()
            if frame is None:
                break
            images.append(frame)
        if not len(images):
            raise Exception('No image found in {}'.format(filename))

        w, h = images[0].get_size()
        ifmt = images[0].get_pixel_format()
        if ifmt != 'rgba' and ifmt != 'rgb24':
            fmt = 'rgba'
            sws = SWScale(w, h, ifmt, ofmt=fmt)
            for i, image in enumerate(images):
                images[i] = sws.scale(image)
        else:
            fmt = ifmt if ifmt == 'rgba' else 'rgb'

        return [ImageData(w, h, fmt, img.to_memoryview()[0], source_image=img)
                for img in images]
github kivy / kivy / kivy / core / image / img_ffpyplayer.py View on Github external
self.filename = filename
        images = []

        while True:
            frame, t = loader.next_frame()
            if frame is None:
                break
            images.append(frame)
        if not len(images):
            raise Exception('No image found in {}'.format(filename))

        w, h = images[0].get_size()
        ifmt = images[0].get_pixel_format()
        if ifmt != 'rgba' and ifmt != 'rgb24':
            fmt = 'rgba'
            sws = SWScale(w, h, ifmt, ofmt=fmt)
            for i, image in enumerate(images):
                images[i] = sws.scale(image)
        else:
            fmt = ifmt if ifmt == 'rgba' else 'rgb'

        return [ImageData(w, h, fmt, img.to_memoryview()[0], source_image=img)
                for img in images]
github snuq / Snu-Photo-Manager / generalelements.py View on Github external
self.first_frame = None
        else:
            self.player.set_pause(False)
            frame = None
            while not frame:
                frame, value = self.player.get_frame(force_refresh=False)
                if value == 'eof':
                    return None
            self.player.set_pause(True)
        self.frame_number = self.frame_number + 1
        if self.max_frames:
            if self.frame_number > self.max_frames:
                return None
        frame_image = frame[0]
        frame_size = frame_image.get_size()
        frame_converter = SWScale(frame_size[0], frame_size[1], frame_image.get_pixel_format(), ofmt='rgb24')
        new_frame = frame_converter.scale(frame_image)
        image_data = bytes(new_frame.to_bytearray()[0])
        image = Image.frombuffer(mode='RGB', size=(frame_size[0], frame_size[1]), data=image_data, decoder_name='raw')
        #for some reason, video frames are read upside-down? fix it here...
        image = image.transpose(PIL.Image.FLIP_TOP_BOTTOM)
        if image.mode != 'RGB':
            image = image.convert('RGB')
        image = self.adjust_image(image, preview=False)
        return [image, frame[1]]
github snuq / Snu-Photo-Manager / generalelements.py View on Github external
def reload_edit_image(self, *_):
        """Regenerate the edit preview image."""
        if self.video:
            if not self.player:
                return
            location = self.length * self.position
            frame = self.seek_player(location)
            frame = frame[0]
            frame_size = frame.get_size()
            pixel_format = frame.get_pixel_format()
            frame_converter = SWScale(frame_size[0], frame_size[1], pixel_format, ofmt='rgb24')
            new_frame = frame_converter.scale(frame)
            image_data = bytes(new_frame.to_bytearray()[0])

            original_image = Image.frombuffer(mode='RGB', size=(frame_size[0], frame_size[1]), data=image_data, decoder_name='raw')
            #for some reason, video frames are read upside-down? fix it here...
            original_image = original_image.transpose(PIL.Image.FLIP_TOP_BOTTOM)
            self.original_width = original_image.size[0]
            self.original_height = original_image.size[1]
            self.original_image = original_image
            image = original_image.copy()

        else:
            original_image = Image.open(self.source)
            try:
                self.exif = original_image.info.get('exif', b'')
            except:

ffpyplayer

A cython implementation of an ffmpeg based player.

LGPL-3.0
Latest version published 2 months ago

Package Health Score

61 / 100
Full package analysis

Similar packages