Skip to content

Use multiple GPU's #35

@ehnwebmaster

Description

@ehnwebmaster

vertd only uses the first GPU available:

For example .mp4 to .mkv command:

ffmpeg -hide_banner -loglevel error -progress pipe:1 -hwaccel cuda -i input/file.mp4 -c:v h264_nvenc -c:a aac -strict experimental -preset medium -b:v 5058664 -map_metadata 0 -map_chapters 0 output/file.mkv

Need to use -gpu n parameter

ffmpeg -i video1.mp4 -c:v h264_nvenc -gpu 0 output1.mkv

Since you can't use multiple gpu's to encode a video use a queue something like this will be works:

ffmpeg -i video2.mp4 -c:v h264_nvenc -gpu 2 output2.mkv
ffmpeg -i video3.mp4 -c:v h264_nvenc -gpu 3 output3.mkv

Use one GPU per video

Rust Example:

use std::sync::atomic::{AtomicUsize, Ordering};
use std::process::Command;

// Variable global o en el estado de tu aplicación (State<T>)
static JOB_COUNTER: AtomicUsize = AtomicUsize::new(0);

fn convertir_video(input: &str, output: &str) {
    // 1. Obtenemos el número de trabajo actual
    let current_job = JOB_COUNTER.fetch_add(1, Ordering::SeqCst);
    
    // 2. Calculamos qué GPU usar (Módulo 3: devuelve 0, 1 o 2 rotativamente)
    let gpu_id = current_job % 3;

    println!("Asignando trabajo {} a la GPU {}", current_job, gpu_id);

    // 3. Construimos el comando
    let status = Command::new("ffmpeg")
        .arg("-i").arg(input)
        .arg("-c:v").arg("h264_nvenc")
        
        // AQUÍ ESTÁ LA MAGIA:
        .arg("-gpu").arg(gpu_id.to_string()) 
        
        .arg("-c:a").arg("aac")
        .arg(output)
        .status()
        .expect("Falló ffmpeg");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions