Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using gopro-overlay with PySide6 (Qt for Python) #218

Open
RalfPeter opened this issue Oct 11, 2024 · 0 comments
Open

Using gopro-overlay with PySide6 (Qt for Python) #218

RalfPeter opened this issue Oct 11, 2024 · 0 comments

Comments

@RalfPeter
Copy link

RalfPeter commented Oct 11, 2024

I had some problems integrating gopro-overlay with a gui application. I got some command windows when executing and i did not find a solution for progressbar.
So i decided to dive into the code and i made some little changes which i will share here (if anybody will be interested in this).

execution.py: i added creationflag

class InProcessExecution:

    def __init__(self, redirect=None, popen=subprocess.Popen):
        self.redirect = redirect
        self.popen = popen

    def execute(self, cmd):
        try:
            log(f"Executing {cmd}")
            if self.redirect:
                with open(self.redirect, "w") as std:
                    process = self.popen(cmd, stdin=subprocess.PIPE, stdout=std, stderr=std, creationflags=subprocess.CREATE_NO_WINDOW)  # <-- ergänzt: creationflags
            else:
                process = self.popen(cmd, stdin=subprocess.PIPE, stdout=None, stderr=None, creationflags=subprocess.CREATE_NO_WINDOW)  # <-- ergänzt: creationflags

ffmpeg.py: i added creationflag in line 77

        deadline = datetime.datetime.now() + timeout

        process = subprocess.Popen([self._path(), *args], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, creationflags=subprocess.CREATE_NO_WINDOW)  # <-- ergänzt: creationflags
        try:
            while True:

ffmpeg_gopro.py: in load_data i added a variable called out

class GoproRecording:
    ffmpeg: FFMPEG
    location: Path
    file: FileStat
    audio: Optional[AudioStream]
    video: VideoStream
    data: Optional[DataStream]

    def load_data(self, out=None) -> bytes:  # <-- ergänzt: out=none
        track = self.data.stream
        if track:
            cmd = [
                "-hide_banner",
                '-y',
                '-i', self.location,
                '-codec', 'copy',
                '-map', '0:%d' % track,
                '-f', 'rawvideo',
                "-"
            ]

            if out:
                out.append("Loading GoPro Data Track")
            else:
                progress = ProgressBarProgress("Loading GoPro Data Track", transfer=True, delta=True)
                progress.start()
            try:
                arr = bytearray()

                def update(b: bytes):
                    if not out:
                        progress.update(len(b))
                    arr.extend(b)

                result = self.ffmpeg.stream(cmd, cb=update, timeout=datetime.timedelta(seconds=45))
                if result != 0:
                    raise IOError(f"ffmpeg failed code: {result}")
                return bytes(arr)
            finally:
                if not out:
                    progress.complete()

process.py: i added creationflag

import subprocess


def run(cmd, **kwargs):
    return subprocess.run(cmd, check=True, **kwargs)


def invoke(cmd, **kwargs):
    try:
        return run(cmd, **kwargs, text=True, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW)  # <-- ergänzt: creationflags
    except subprocess.CalledProcessError as e:
        raise IOError(f"Error: {cmd}\n stdout: {e.stdout}\n stderr: {e.stderr}")

I hope it is the right way to share my idea. Perhaps someone will find it useful for his own project (or perhaps to be included in gopro-overlay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant