~boringcactus/vidslice

23132238f9baa9a061a445e2d786a32790aa60a7 — Melody Horn 5 years ago b81ee0c v1.4
use -ss as an input option for *far* better efficiency
3 files changed, 30 insertions(+), 19 deletions(-)

M options.py
M output.py
M vidslice.py
M options.py => options.py +15 -8
@@ 13,6 13,12 @@ EDIT_BOX_COL = 2
NEW_COL = 3


class FFmpegOptions:
    def __init__(self, input, output):
        self.input = input
        self.output = output


class Property:
    def __init__(self, parent, name, *, label=None, orig=None, edit=None, new_class=None, new=None):
        self.handlers = []


@@ 238,19 244,20 @@ class OptionsPanel(wx.Panel):
            self.enforce_constraints()

    def ffmpeg_opts(self):
        opts = []
        input_opts = []
        output_opts = []

        if self.start_time.is_edit():
            opts += ['-ss', str(self.start_time.get_final())]
            input_opts += ['-ss', str(self.start_time.get_final())]
        elif self.end_time.is_edit() and self.duration.is_edit():
            new_end = float(self.end_time.get_final())
            new_duration = float(self.duration.get_final())
            new_start = new_end - new_duration
            opts += ['-ss', str(new_start)]
            input_opts += ['-ss', str(new_start)]
        if self.end_time.is_edit():
            opts += ['-to', str(self.end_time.get_final())]
            output_opts += ['-to', str(self.end_time.get_final())]
        if self.duration.is_edit():
            opts += ['-t', str(self.duration.get_final())]
            output_opts += ['-t', str(self.duration.get_final())]

        if self.width.is_edit() or self.height.is_edit():
            width = str(self.width.get_final())


@@ 259,9 266,9 @@ class OptionsPanel(wx.Panel):
                width = "-1"
            if not self.height.is_edit():
                height = "-1"
            opts += ['-vf', 'scale=' + width + ':' + height]
            output_opts += ['-vf', 'scale=' + width + ':' + height]

        if self.framerate.is_edit():
            opts += ['-r', str(self.framerate.get_final())]
            output_opts += ['-r', str(self.framerate.get_final())]

        return opts
        return FFmpegOptions(input_opts, output_opts)

M output.py => output.py +14 -10
@@ 4,9 4,11 @@ import threading

import wx

from options import FFmpegOptions


class OutputPanel(wx.Panel):
    def __init__(self, *args, get_ffmpeg_args=lambda: [], **kw):
    def __init__(self, *args, get_ffmpeg_args=lambda: FFmpegOptions([], []), **kw):
        super(OutputPanel, self).__init__(*args, **kw)
        self.update_listeners = []
        self.input_path = None


@@ 74,29 76,31 @@ class OutputPanel(wx.Panel):
        self.logs.Clear()
        self.run_panel.Disable()
        real_args = self.get_ffmpeg_args()
        input_args = real_args.input
        output_args = real_args.output
        output_path = self.file_text.GetValue()
        (folder, name) = os.path.split(output_path)
        (name, ext) = os.path.splitext(name)
        if self.silence.GetValue():
            real_args += ['-an']
            output_args += ['-an']
        if ext == '.gif':
            filter_before = '[0:v] '
            filter_after = 'split [a][b];[a] palettegen [p];[b][p] paletteuse'
            filter_during = ''
            if '-vf' in real_args:
                for i in range(len(real_args) - 1):
                    [a, b] = real_args[i:i + 2]
            if '-vf' in output_args:
                for i in range(len(output_args) - 1):
                    [a, b] = output_args[i:i + 2]
                    if a == '-vf':
                        filter_during = b + ','
                    real_args[i:i + 2] = []
                    output_args[i:i + 2] = []
                    break
            real_args += ['-filter_complex', filter_before + filter_during + filter_after]
            output_args += ['-filter_complex', filter_before + filter_during + filter_after]
        if self.deepfry.GetValue():
            if ext == '.mp3':
                real_args += ['-q:a', '9']
                output_args += ['-q:a', '9']
            else:
                real_args += ['-q:a', '0.1', '-crf', '51']
        args = ['ffmpeg', '-hide_banner', '-y', '-i', self.input_path] + real_args + [output_path]
                output_args += ['-q:a', '0.1', '-crf', '51']
        args = ['ffmpeg', '-hide_banner', '-y'] + input_args + ['-i', self.input_path] + output_args + [output_path]
        print(args)

        def run():

M vidslice.py => vidslice.py +1 -1
@@ 9,7 9,7 @@ from options import OptionsPanel
from output import OutputPanel
from sources import SourcesPanel, update_ytdl

VERSION = "1.3"
VERSION = "1.4"


def check_update(parent):