Ffmpeg-python: NVENCODE to speed up encoding.

Created on 31 Oct 2019  路  2Comments  路  Source: kkroening/ffmpeg-python

I would like to use GPU instead of CPU for encoding a video.

Getting Started with FFmpeg/libav using NVIDIA GPUs

After installing installing ffmpeg and configuring cuda before installing it.

Can i use the regular command here to make use of GPU instead of CPU?

Most helpful comment

Here's an example of how I do the things:

import ffmpeg

input_args = {
    "hwaccel": "nvdec",
    "vcodec": "h264_cuvid",
    "c:v": "h264_cuvid"
}

output_args = {
    "vcodec": "hevc_nvenc",
    "c:v": "hevc_nvenc",
    "preset": "fast",
    "crf": 0,
    "b:v": "20M",
    "acodec": "copy"
}

(
    ffmpeg
    .input('Input/my_video.mp4', **input_args)
    .output('Output/out.mkv', **output_args)
    .run()
)

Of course, this is a very simple example, in which nothing much is done to the input video, but it's running on GPU.

All 2 comments

Here's an example of how I do the things:

import ffmpeg

input_args = {
    "hwaccel": "nvdec",
    "vcodec": "h264_cuvid",
    "c:v": "h264_cuvid"
}

output_args = {
    "vcodec": "hevc_nvenc",
    "c:v": "hevc_nvenc",
    "preset": "fast",
    "crf": 0,
    "b:v": "20M",
    "acodec": "copy"
}

(
    ffmpeg
    .input('Input/my_video.mp4', **input_args)
    .output('Output/out.mkv', **output_args)
    .run()
)

Of course, this is a very simple example, in which nothing much is done to the input video, but it's running on GPU.

@serbanc94, thanks, your example is very helpful. And how can we find more options supported by input_args(eg, device_id), which isn't descripted in doc of ffmpeg-python.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oveddan picture oveddan  路  3Comments

monokal picture monokal  路  3Comments

Baa14453 picture Baa14453  路  5Comments

prajwal-mulkalwar picture prajwal-mulkalwar  路  6Comments

cbitterfield picture cbitterfield  路  4Comments