How to ffmpeg
(Página en constante actualización)
Casos más frecuentes en el uso de esta Utilidad.
VIDEO
1. Cambiar formato del video de m4v a formato mp4 y ajustar ancho a 640 pxls
ffmpeg -i inputFile.m4v -vf scale=640:-1 outputFile.mp4
2. Extraer parte de un video
ffmpeg -ss 00:20:23 -i laFarm.mp4 -to 00:22:10 -c copy laFarm_part01.mp4
3. Adicionar subtítulos a un video
ffmpeg -i video.mp4 -vf subtitles=subtitilo.srt videoOutput.mp4
Nota 1: archivo srt debe estar en formato UTF8
Nota 2: ASS (Advanced Substation Alpha)
ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi
4. Crear un video optimizado a partir de una imagen y un archivo mp3
ffmpeg -loop 1 -i imagen.jpg -i sonido.mp3 -shortest -c:a copy video_salida.mp4
5. Crear un video a partir de un conjunto de imágenes ordenadas
ffmpeg -r 1/5 -i img%02d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p OUT.mp4
Archivos de imagenes en formato png, nombres empiezan por img y tienen 2 números en el nombre
6. Agregarle sonido al video creado en el paso anterior
ffmpeg -i OUT.mp4 -i 'Music.m4a' -map 0:v -map 1:a -c:v copy -shortest OUT+SOUND.mp4
7. Convertir x265 (hevc) a x264
ffmpeg -i input_file.mp4 -map 0 -c:v libx264 -crf 18 -c:a copy output.mp4
8. Agregar Marca de Agua a un Video
Fuente: https://parzibyte.me/blog/2018/08/22/marca-de-agua-con-ffmpeg-sobre-video/
ffmpeg -i video.mp4 -i marca_de_agua.png -filter_complex "overlay=1:1" video_con_marca.mp4
ffmpeg -i video.mp4 -i marcaagua-85x127.png -filter_complex "overlay=25:25" videoConMarca.mp4
Variables
ffmpeg proporciona algunas variables que podemos usar. Son:
main_h: la altura del vídeo
main_w: la anchura del vídeo
overlay_h: la altura de nuestra imagen
overlay_w: la anchura de nuestra imagen
Cómo centrar la marca de agua
Nos ayudamos de las variables. Para centrar horizontalmente restamos main_w menos overlay_w y dividimos entre 2.
Lo mismo para centrar verticalmente. Entonces el comando para centrar una imagen quedaría así:
ffmpeg -i video.mp4 -i marca_de_agua.png -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" video_con_marca.mp4
Marca de agua en la parte inferior derecha
Igualmente utilizamos las variables, sólo que ahora no dividimos, sólo restamos. El comando quedaría así:
ffmpeg -i video.mp4 -i marca_de_agua.png -filter_complex "overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)" video_con_marca.mp4
Con eso nuestra marca de agua quedaría en la parte inferior derecha.
Notas
La imagen medirá lo que mida, este comando no redimensiona nada
La imagen debe ser transparente, y tal vez con una opacidad baja.
9. Convertir segmento de un video en gif animado
a. Crear paleta desde el segundo 1 y con 4 segundos
ffmpeg -ss 00:00:01 -t 4 -i slider1OK.mp4 -filter_complex "[0:v] palettegen" palette.png
b. Crear gif con base en la paleta
ffmpeg -ss 00:00:01 -t 4 -i slider1OK.mp4 -i palette.png -filter_complex "[0:v] fps=5,scale=1024:-1 [new];[new][1:v] paletteuse" slider1OK.gif
10. Extrarer un área de un video
ffmpeg -i input.mp4 -vf "crop=w:h:x:y" output.mp4
vf indicates the usage of a video filter.
crop is the name of the filter.
w:h is the width and height of the output video.
x:y is the coordinate where the video will be cropped.
11. Convertir un gif animado en mp4 (básico)
ffmpeg -i gif_example.gif -b:v 0 -crf 25 videoFromGif.mp4
12. Aumentar la velocidad de un video
ffmpeg -iVideo.mp4 -vf "setpts=0.50*PTS"Video-2X.mp4
ffmpeg -iVideo.mp4 -vf "setpts=0.25*PTS" Video-4X.mp4
14. Remover sonido de un video
ffmpeg -i Video.mp4 -an -c copy -y Video-ns.mp4
15. Agregar sonido a video mp4
ffmpeg -i video1.mp4 -i audio1.mp3 -c:v copy -map 0:v -map 1:a -y output.mp4
ffmpeg -i Video.mp4 -audio.mp3 -c:v copy -map 0:v -map 1:a -shortest -y Video-s.mp4
AUDIO
1. Cambiar formato archivo de audio en m4a a formato mp3 (aplica desde wav también)
ffmpeg -i Cuanto_Tiempo_Nos_Queda.m4a -acodec libmp3lame -aq 2 Cuanto_Tiempo_Nos_Queda.mp3
2. Subir el volúmen de un archivo mp3 al doble
ffmpeg -i Cuanto_Tiempo_Nos_Queda.mp3 -af "volume=2" Cuanto_Tiempo_Nos_Queda_2V.mp3
Nota: Si se quisiese solamente subirlo un 50%, utilizar el parametro "volume=1.5"
3. Obtener audio en formato mp3 desde un archivo de video
ffmpeg -i inputFile.mp4 -codec:a libmp3lame outputFile.mp3
4. Rebajar el tamaño de un archivo mp3 ( convertirlo a mono)
lame -a -h -b 16 -q 0 Mozart.mp3 Mozart_mono.mp3
5. Gestión de metadata con ffmpeg
ffmpeg -i fuente.mp3 -codec copy -metadata artist="Anónimo" -metadata title="NUEVO ORDEN" destino_ok.mp3
Otros metadatos: comment, year, author, album, etc ver https://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata
Gestión de TAGS ID en archivos mp3
Fuente: http://manpages.ubuntu.com/manpages/bionic/man1/id3tool.1.html
id3tool - a command line editor for id3 tags.
The programs follow the usual GNU command line syntax, with long options starting with two
dashes (`-'). A complete list of options are included below. For a complete description,
use the help option.
-t, --set-title=WORD
Sets the title to WORD
-a, --set-album=WORD
Sets the album to WORD
-r, --set-artist=WORD
Sets the artist to WORD
-y, --set-year=YEAR
Sets the year to YEAR [4 digits]
-n, --set-note=WORD
Sets the note to WORD
-g, --set-genre=INT
Sets the genre code to INT (the codes can be acquired from the genre list.)
-G, --set-genre-word=WORD
Sets the genre to WORD (given that WORD is from the genre list.)
-c, --set-track=INT
Sets the track to INT
-h, --help
Show summary of options.
-v, --version
Show version of program.
-l, --genre-list
Shows the genre list.
Agregar una imagen de portada a un archivo de audio y producir un mp3
ffmpeg -i fuente.mp3 -i portada.jpg -c copy -c:a libmp3lame -map 0 -map 1 testSalida.mp3
Agregar iniatura (imagen) a un video
ffmpeg -i videoFuente.mp4 -i laPortada.jpg -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic vodeoSalida.mp4
NOTA: Una buena web de ffmpeg:
https://www.busindre.com/comandos_ffmpeg_utiles