Skip to content

Add detection for NVENC and use accordingly - Needs testing from NVIDIA users #2259

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

LevaniVashadze
Copy link
Contributor

Changed video encoding to standard h264, since the nvenc encoderes relied on nvidia cards and didn't work on my amd machine.

@OpenSourceSimon
Copy link
Collaborator

@LevaniVashadze Good one, will it throw an error if you do not have an Nvidia card? Looks a bit like PR #2256, maybe we could add a universal check to check the compatibility of different codecs? Since the h264_nvenc codec is much faster when you have an Nvidia card

@LevaniVashadze
Copy link
Contributor Author

Yeah also thought of that, but was too lazy, but does seem like a duplicate. I added a check now, but need someone to test on nvidia hardware, it does return False for me and if it fails it will return false too, so it's pretty fool proof

@LevaniVashadze
Copy link
Contributor Author

def check_nvenc_support():
    """Check if the system supports NVENC encoding by attempting to encode a test frame."""
    import subprocess

    try:
        # Try to encode a single black frame using NVENC
        result = subprocess.run(
            ['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i',
             'color=black:s=1080x1080', '-vframes', '1', '-an',
             '-c:v', 'hevc_nvenc', '-f', 'null', '-'],
            capture_output=True,
            text=True,
            stderr=subprocess.PIPE
        )

        # If the command succeeds (return code 0) and there's no error output, NVENC is supported
        return result.returncode == 0 and not result.stderr
    except Exception:
        return False

Just needs to run this function in a python console and have ffmpeg installed

@LevaniVashadze LevaniVashadze changed the title Removed nvenc encoder Add detection for NVENC and use accordingly - Needs testing from NVIDIA users Feb 26, 2025
@OpenSourceSimon
Copy link
Collaborator

@LevaniVashadze is that the most safe and reliable method? I don't think all the users have ffmpeg installed in their PATH. I will soon run that code to see the output when having an Nvidia card

@JasonLovesDoggo
Copy link
Collaborator

@LevaniVashadze is that the most safe and reliable method? I don't think all the users have ffmpeg installed in their PATH. I will soon run that code to see the output when having an Nvidia card

you... need ffmpeg installed and in path for the bot to run..

Copy link
Collaborator

@JasonLovesDoggo JasonLovesDoggo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the tiny comment, LGTM

Copy link
Contributor

This pull request is stale as it has been open for 7 days with no activity. Remove stale label or comment, or this will be closed in 10 days.

@LevaniVashadze
Copy link
Contributor Author

LevaniVashadze commented Mar 11, 2025

def check_nvenc_support():
    """Check if the system supports NVENC encoding by attempting to encode a test frame."""
    import subprocess

    try:
        # Try to encode a single black frame using NVENC
        result = subprocess.run(
            ['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i',
             'color=black:s=1080x1080', '-vframes', '1', '-an',
             '-c:v', 'hevc_nvenc', '-f', 'null', '-'],
            capture_output=True,
            text=True,
            stderr=subprocess.PIPE
        )

        # If the command succeeds (return code 0) and there's no error output, NVENC is supported
        return result.returncode == 0 and not result.stderr
    except Exception:
        return False

Just needs to run this function in a python console and have ffmpeg installed

could anyone with a nvidia gpu just run this piece of code in the python console? and see what the function returns, thanks in advance(must have ffmpeg installed)

@OpenSourceSimon
Copy link
Collaborator

def check_nvenc_support():
    """Check if the system supports NVENC encoding by attempting to encode a test frame."""
    import subprocess

    try:
        # Try to encode a single black frame using NVENC
        result = subprocess.run(
            ['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i',
             'color=black:s=1080x1080', '-vframes', '1', '-an',
             '-c:v', 'hevc_nvenc', '-f', 'null', '-'],
            capture_output=True,
            text=True,
            stderr=subprocess.PIPE
        )

        # If the command succeeds (return code 0) and there's no error output, NVENC is supported
        return result.returncode == 0 and not result.stderr
    except Exception:
        return False

Just needs to run this function in a python console and have ffmpeg installed

could anyone with a nvidia gpu just run this piece of code in the python console? and see what the function returns, thanks in advance(must have ffmpeg installed)

Returns false for me

@OpenSourceSimon
Copy link
Collaborator

@LevaniVashadze This code returns that the codec is supported

import subprocess

result = subprocess.run(
    ['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i',
     'color=black:s=1080x1080', '-vframes', '1', '-an',
     '-c:v', 'hevc_nvenc', '-f', 'null', '-'],
    capture_output=True,
    text=True
)

# Check if NVENC is working
if result.returncode == 0:
    print("✅ NVENC is supported and working!")
else:
    print("❌ NVENC failed:", result.stderr)

@LevaniVashadze
Copy link
Contributor Author

Hmm that seems to work then, when I ran it my resultcode was 4294967295 and it HAD a result.stderr(error). So I guess I'll modify it a bit.

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

Successfully merging this pull request may close these issues.

3 participants