ranger-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ranger-users] Video files: thumbnail previews


From: Joshua Landau
Subject: Re: [Ranger-users] Video files: thumbnail previews
Date: Mon, 29 Jul 2013 01:44:35 +0100

On 28 July 2013 23:24, Joshua Landau <address@hidden> wrote:
On 28 July 2013 23:05, Germain Zouein <address@hidden> wrote:
I think I'll use ffmpegthumbnailer (http://code.google.com/p/ffmpegthumbnailer/) instead of ffmpeg. It looks pretty neat, is (much) faster than what I'm currently doing, can seek to a percentage of time (e.g. 10% of the video). Other FMs use that (e.g. Thunar) so I guess it's rather reliable. Can you try that and let me know how fast it is?
Something like this (you can use `time` to time it if you want ): `ffmpegthumbnailer -i <path to video file> -o <output path> -s 0`

+1

It's a *touch* faster, which makes sense as it's just a less-hacky way of doing the same thing. That's especially good, though, as it defaults to 10% of the way in. It's another (optional) dependency, though.

Despite swearing I wouldn't be helpful, here's something that works for me (this goes in core/actions.py [you knew that]).
This works a lot more reliably than the current version, and works for pager-previews or whatever the thing you get when pressing "i" is termed.

# CODE #
if self.settings.preview_images and self.settings.preview_videos and file.video:
    thumb = '/tmp/' + sha1(path.encode()).hexdigest() + '.jpg'

    if os.path.isfile(thumb) and os.path.getmtime(thumb) > os.path.getmtime(path):
        pager.set_image(thumb)
        return thumb

    else:
        try:
            data = "">
        except:
            data = "" = {'loading': True}
        else:
            if data['loading']:
                return None

        # Reload with ffmpegthumbnailer
        cmd = CommandLoader(
            ["ffmpegthumbnailer", "-i", path, "-o", thumb, "-s", "0"],
            descr="loading preview image",

            # Don't set:
            # silent=True
            # as it randomly breaks on *some* things (it never finishes)
            # for some reason.
        )

        def on_after(signal):
            exit = signal.process.poll()

            if os.path.isfile(thumb) and exit == 0:
                pager.set_image(thumb)
                self.ui.need_redraw = True

            else:
                self.notify("Couldn't generate preview!", bad=True)

            data['loading'] = False

        cmd.signal_bind('after', on_after)
        self.loader.add(cmd)
# CODE END #

If you want to set silent=True, you have to change the "if self.silent and not self.read:" part of core/loader.py to:

# CODE #
while process.poll() is None:
    yield
    if self.finished:
        break

    try:
        read, _, __ = select.select([process.stdout, process.stderr], [], [], 0.03)
        for rd in read:
            rd.read()

    except select.error:
        sleep(0.03)
# NO MORE CODE #

or equiv.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]