Skip to content

Commit

Permalink
Merge pull request #2121 from xiaomofa/fix-gpu-h264_nvenc
Browse files Browse the repository at this point in the history
Fix GPU h264_nvenc encoding not working.
  • Loading branch information
OsaAjani authored Jan 10, 2025
2 parents 35d2ceb + bee6c14 commit 9c320f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion moviepy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def deprecated_func(*args, **kwargs):
"mp3": {"type": "audio", "codec": ["libmp3lame"]},
"wav": {"type": "audio", "codec": ["pcm_s16le", "pcm_s24le", "pcm_s32le"]},
"m4a": {"type": "audio", "codec": ["libfdk_aac"]},
"flac":{"type": "audio", "codec": ["flac"]}
"flac": {"type": "audio", "codec": ["flac"]},
}

for ext in ["jpg", "jpeg", "png", "bmp", "tiff"]:
Expand Down
13 changes: 11 additions & 2 deletions moviepy/video/io/ffmpeg_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ def __init__(
if audiofile is not None:
cmd.extend(["-i", audiofile, "-acodec", "copy"])

cmd.extend(["-vcodec", codec, "-preset", preset])
if codec == "h264_nvenc":
cmd.extend(["-c:v", codec])
else:
cmd.extend(["-vcodec", codec])

cmd.extend(["-preset", preset])

if ffmpeg_params is not None:
cmd.extend(ffmpeg_params)
Expand All @@ -136,7 +141,11 @@ def __init__(
if codec == "libvpx" and with_mask:
cmd.extend(["-pix_fmt", "yuva420p"])
cmd.extend(["-auto-alt-ref", "0"])
elif (codec == "libx264") and (size[0] % 2 == 0) and (size[1] % 2 == 0):
elif (
(codec == "libx264" or codec == "h264_nvenc")
and (size[0] % 2 == 0)
and (size[1] % 2 == 0)
):
cmd.extend(["-pix_fmt", "yuva420p"])

cmd.extend([ffmpeg_escape_filename(filename)])
Expand Down

0 comments on commit 9c320f1

Please sign in to comment.