> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-es/procesamiento-de-video/ffmpeg-nvenc.md).

# FFmpeg NVENC

Codificación de video acelerada por GPU con FFmpeg NVENC en Clore.ai

Codificación de video acelerada por hardware con GPU NVIDIA.

{% hint style="success" %}
Todos los ejemplos se pueden ejecutar en servidores GPU alquilados a través de [Marketplace de CLORE.AI](https://clore.ai/marketplace).
{% endhint %}

## Alquilar en CLORE.AI

1. Visita [Marketplace de CLORE.AI](https://clore.ai/marketplace)
2. Filtra por tipo de GPU, VRAM y precio
3. Elige **Bajo demanda** (tarifa fija) o **Spot** (precio ofertado)
4. Configura tu pedido:
   * Selecciona la imagen de Docker
   * Configura los puertos (TCP para SSH, HTTP para interfaces web)
   * Añade variables de entorno si es necesario
   * Introduce el comando de inicio
5. Selecciona el método de pago: **CLORE**, **BTC**, o **USDT/USDC**
6. Crea el pedido y espera al despliegue

### Accede a tu servidor

* Encuentra los detalles de conexión en **Mis pedidos**
* Interfaces web: Usa la URL del puerto HTTP
* SSH: `ssh -p <port> root@<proxy-address>`

## ¿Qué es NVENC?

NVENC (NVIDIA Video Encoder) ofrece:

* codificación 5-10 veces más rápida que la CPU
* Compatibilidad con H.264, H.265/HEVC y AV1
* Codificación 4K/8K en tiempo real
* Bajo uso de cómputo de la GPU

## Requisitos

| Códec | GPU mínima | Recomendado |
| ----- | ---------- | ----------- |
| H.264 | GTX 600+   | RTX 3060+   |
| HEVC  | GTX 900+   | RTX 3070+   |
| AV1   | RTX 4000+  | RTX 4090    |

## Despliegue rápido

**Imagen de Docker:**

```
nvidia/cuda:12.8.1-devel-ubuntu22.04
```

**Puertos:**

```
22/tcp
```

**Comando:**

```bash
apt-get update && \
apt-get install -y ffmpeg && \\
echo "FFmpeg con NVENC listo"
```

## Comprobar compatibilidad con NVENC

```bash

# Comprobar codificadores disponibles
ffmpeg -encoders | grep nvenc

# Debería mostrar:

# V....D h264_nvenc

# V....D hevc_nvenc

# V....D av1_nvenc (RTX 4000+)
```

## Codificación básica

### Codificación H.264

```bash
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -cq 23 output.mp4
```

### Codificación HEVC/H.265

```bash
ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p7 -cq 23 output.mp4
```

### Codificación AV1 (RTX 4000+)

```bash
ffmpeg -i input.mp4 -c:v av1_nvenc -preset p7 -cq 23 output.mp4
```

## Preajustes

| Preajuste | Calidad  | Velocidad     |
| --------- | -------- | ------------- |
| p1        | Más bajo | El más rápido |
| p2-p3     | Baja     | Rápido        |
| p4-p5     | Medio    | Equilibrado   |
| p6-p7     | Alta     | Lento         |

```bash

# Codificación más rápida
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p1 output.mp4

# Mejor calidad
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 output.mp4
```

## Control de calidad

### Calidad constante (CQ)

```bash

# Más bajo = mejor calidad, archivo más grande
ffmpeg -i input.mp4 -c:v h264_nvenc -cq 18 output.mp4

# Valores recomendados: 18-28
```

### Tasa de bits constante (CBR)

```bash
ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 10M output.mp4
```

### Tasa de bits variable (VBR)

```bash
ffmpeg -i input.mp4 -c:v h264_nvenc -b:v 10M -maxrate 15M -bufsize 20M output.mp4
```

## Resolución y escalado

### Redimensionar video

```bash

# Escalar a 1080p
ffmpeg -i input.mp4 -vf "scale=1920:1080" -c:v h264_nvenc output.mp4

# Escalar a 4K
ffmpeg -i input.mp4 -vf "scale=3840:2160" -c:v hevc_nvenc output.mp4

# Mantener la relación de aspecto
ffmpeg -i input.mp4 -vf "scale=-1:1080" -c:v h264_nvenc output.mp4
```

### Escalado por GPU (más rápido)

```bash
ffmpeg -hwaccel cuda -hwaccel_output_format cuda \\
    -i input.mp4 \\
    -vf "scale_cuda=1920:1080" \\
    -c:v h264_nvenc output.mp4
```

## Decodificación por hardware + codificación

Pila completa de GPU:

```bash
ffmpeg \\
    -hwaccel cuda \\
    -hwaccel_output_format cuda \\
    -i input.mp4 \\
    -c:v h264_nvenc \\
    -preset p4 \\
    output.mp4
```

## Conversión por lotes

### Script de shell

```bash
#!/bin/bash
INPUT_DIR=$1
OUTPUT_DIR=$2

mkdir -p "$OUTPUT_DIR"

for file in "$INPUT_DIR"/*.{mp4,mkv,avi,mov}; do
    if [ -f "$file" ]; then
        filename=$(basename "$file")
        name="${filename%.*}"

        ffmpeg -hwaccel cuda -i "$file" \\
            -c:v h264_nvenc -preset p5 -cq 23 \\
            -c:a aac -b:a 192k \\
            "$OUTPUT_DIR/${name}.mp4"

        echo "Convertido: $filename"
    fi
done
```

### Lote en Python

```python
import subprocess
import os
from concurrent.futures import ThreadPoolExecutor

def convert_video(input_path, output_path):
    cmd = [
        'ffmpeg', '-y',
        '-hwaccel', 'cuda',
        '-i', input_path,
        '-c:v', 'h264_nvenc',
        '-preset', 'p5',
        '-cq', '23',
        '-c:a', 'aac',
        '-b:a', '192k',
        output_path
    ]
    subprocess.run(cmd, check=True)

input_dir = './videos'
output_dir = './converted'
os.makedirs(output_dir, exist_ok=True)

files = [f for f in os.listdir(input_dir) if f.endswith(('.mp4', '.mkv', '.avi'))]

# Procesar en paralelo (si hay varias GPU o recursos suficientes)
for f in files:
    input_path = os.path.join(input_dir, f)
    output_path = os.path.join(output_dir, f.rsplit('.', 1)[0] + '.mp4')
    convert_video(input_path, output_path)
    print(f"Convertido: {f}")
```

## Tareas comunes

### Convertir a MP4 optimizado para la web

```bash
ffmpeg -i input.mp4 \\
    -c:v h264_nvenc -preset p5 -cq 23 \\
    -c:a aac -b:a 128k \\
    -movflags +faststart \\
    web_video.mp4
```

### Extraer audio

```bash
ffmpeg -i video.mp4 -vn -c:a copy audio.aac
ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 320k audio.mp3
```

### Añadir subtítulos

```bash

# Incrustar subtítulos en el video
ffmpeg -i input.mp4 -vf "subtitles=subs.srt" -c:v h264_nvenc output.mp4

# Incrustar como subtítulos suaves
ffmpeg -i input.mp4 -i subs.srt -c:v copy -c:a copy -c:s mov_text output.mp4
```

### Recortar video

```bash

# Desde 00:01:00 durante 30 segundos
ffmpeg -ss 00:01:00 -i input.mp4 -t 30 -c:v h264_nvenc output.mp4

# Desde el inicio hasta la marca de tiempo final
ffmpeg -i input.mp4 -ss 00:00:30 -to 00:02:00 -c:v h264_nvenc output.mp4
```

### Concatenar videos

```bash

# Crear lista de archivos
echo "file 'video1.mp4'" > list.txt
echo "file 'video2.mp4'" >> list.txt
echo "file 'video3.mp4'" >> list.txt

# Concatenar
ffmpeg -f concat -safe 0 -i list.txt -c:v h264_nvenc output.mp4
```

### Crear GIF

```bash
ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos" output.gif
```

### Extraer fotogramas

```bash

# Cada fotograma
ffmpeg -i input.mp4 frames/frame_%04d.png

# Cada 1 segundo
ffmpeg -i input.mp4 -vf "fps=1" frames/frame_%04d.png
```

### Fotogramas a video

```bash
ffmpeg -framerate 30 -i frames/frame_%04d.png -c:v h264_nvenc output.mp4
```

## Transmisión

### Transmisión RTMP

```bash
ffmpeg -re -i input.mp4 \\
    -c:v h264_nvenc -preset p4 -b:v 4M \\
    -c:a aac -b:a 128k \\
    -f flv rtmp://server/live/stream
```

### Salida HLS

```bash
ffmpeg -i input.mp4 \\
    -c:v h264_nvenc -preset p5 \\
    -c:a aac \\
    -f hls -hls_time 10 -hls_list_size 0 \\
    output.m3u8
```

## Comparación de rendimiento

### Velocidad de codificación (video 4K)

| Codificador | GPU/CPU         | Velocidad |
| ----------- | --------------- | --------- |
| libx264     | CPU (8 núcleos) | \~30 fps  |
| h264\_nvenc | RTX 3090        | \~300 fps |
| h264\_nvenc | RTX 4090        | \~450 fps |
| hevc\_nvenc | RTX 3090        | \~200 fps |
| hevc\_nvenc | RTX 4090        | \~350 fps |

## Opciones avanzadas

### Codificación en dos pasadas

```bash

# Pasada 1
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -b:v 10M -pass 1 -f null /dev/null

# Pasada 2
ffmpeg -i input.mp4 -c:v h264_nvenc -preset p7 -b:v 10M -pass 2 output.mp4
```

### B-frames y GOP

```bash
ffmpeg -i input.mp4 \\
    -c:v h264_nvenc \\
    -bf 2 \           # B-frames
    -g 60 \           # Tamaño de GOP
    -keyint_min 30 \  # Intervalo mínimo de fotograma clave
    output.mp4
```

### Compatibilidad HDR (HEVC)

```bash
ffmpeg -i hdr_input.mp4 \\
    -c:v hevc_nvenc \\
    -preset p5 \\
    -profile:v main10 \\
    -pix_fmt p010le \\
    hdr_output.mp4
```

## Multi-GPU

```bash

# Usar GPU específica
ffmpeg -hwaccel cuda -hwaccel_device 0 -i input.mp4 -c:v h264_nvenc output.mp4

# Codificación paralela en diferentes GPU
ffmpeg -hwaccel cuda -hwaccel_device 0 -i video1.mp4 -c:v h264_nvenc out1.mp4 &
ffmpeg -hwaccel cuda -hwaccel_device 1 -i video2.mp4 -c:v h264_nvenc out2.mp4 &
wait
```

## Solución de problemas

### NVENC no encontrado

```bash

# Comprobar el controlador NVIDIA
nvidia-smi

# Comprobar la compilación de FFmpeg
ffmpeg -encoders | grep nvenc
```

### La codificación falló

```bash

# Reducir las sesiones concurrentes (límite de NVENC)

# GPU de consumo: 3-5 sesiones

# GPU profesionales: ilimitadas
```

### Calidad deficiente

* Usa un ajuste preestablecido más alto (p6, p7)
* Reduce el valor CQ (18-20)
* Aumenta la tasa de bits

## Estimación de costos

Tarifas típicas del marketplace de CLORE.AI (a partir de 2024):

| GPU       | Tarifa por hora | Tarifa diaria | Sesión de 4 horas |
| --------- | --------------- | ------------- | ----------------- |
| RTX 3060  | \~$0.03         | \~$0.70       | \~$0.12           |
| RTX 3090  | \~$0.06         | \~$1.50       | \~$0.25           |
| RTX 4090  | \~$0.10         | \~$2.30       | \~$0.40           |
| A100 40GB | \~$0.17         | \~$4.00       | \~$0.70           |
| A100 80GB | \~$0.25         | \~$6.00       | \~$1.00           |

*Los precios varían según el proveedor y la demanda. Consulta* [*Marketplace de CLORE.AI*](https://clore.ai/marketplace) *las tarifas actuales.*

**Ahorra dinero:**

* Usa el **Spot** mercado para trabajo interrumpible — alrededor de un tercio de los servidores fija el precio spot por debajo del precio bajo demanda (mediana de \~13% de descuento), el resto lo iguala
* Paga con **CLORE** tokens
* Compara precios entre distintos proveedores

## Siguientes pasos

* [Generación de video con IA](/guides/guides_v2-es/generacion-de-video/ai-video-generation.md)
* [Interpolación RIFE](/guides/guides_v2-es/procesamiento-de-video/rife-interpolation.md)
* [Escalado con Real-ESRGAN](/guides/guides_v2-es/procesamiento-de-imagenes/real-esrgan-upscaling.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-es/procesamiento-de-video/ffmpeg-nvenc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
