AUDIO
ffmpeg -i audio.wav
Input #0, wav, from 'audio.wav':
Duration: 00:05:08.1, start: 0.000000, bitrate: 1411 kb/s
Stream #0.0: Audio: pcm_s16le, 44100 Hz, stereo, 1411 kb/s
La piste fait 5 min et 8.1s, le codec est PCM 16-bit, signé little-endian. La fréquence de 44100Hz, stéréo et 1411kbit/s de bitrate.
Let's convert this to an MP3 file:
ffmpeg -i IN.wav -acodec mp3 -ab 192k OUT.mp3
-acodec mp3 renseigne le codec à utiliser.
-ab 192k bitrate of 192 kbit/s.
OGG
ffmpeg -i IN.wav -acodec vorbis -aq 60 OUT.ogg
-aq qualité de l'audio (0 est le plus bas, 60 donne un débit de 160 kbit/s, which is very good)
Resample l'audio à 22050 Hz au lieu de 44100 Hz, mono, bitrate inférieur et fichier MP2 :
ffmpeg -i IN.wav -acodec mp2 -ac 1 -ar 22050 -ab 64k OUT.mp2
-ac 1 pour 1 seul canal (mono) instead of leaving it as the input (stereo, 2 channels).
-ar 22050 resample l'audio à 22050 Hz au lieu de 44100 Hz.
convert en WAV mais unsigned 8-bit au lieu de 16-bit. NOTE: WAV est uncompressed, donc pas besoin de renseigner le bitrate:
ffmpeg -i IN.mp2 -acodec pcm_u8 OUT.8bit.wav
ffmpeg -formats
pour connaitre les formats.
-acodec quel codec audio utiliser. -acodec copy utilise le même codec (donc ne re-code pas).
-ar resample l'audio on the fly, le bitrate se gère avce -ab, et la stéréo avec -ac.
VIDEO TRANSCODING
ffmpeg -i IN.flv -target ntsc-dvd -aspect 4:3 OUT.mpg
-target ntsc-dvd permet de régler les paramètres pour un NTSC DVD-Video (les bons codecs audio et video, bitrates, image size, frame rate, etc.)
-aspect 4:3 (largeur:hauteur).
ffmpeg -i IN.flv -target ntsc-dvd -b 2000k -acodec mp2 -ar 22050 -ab 64k -aspect 4:3 OUT.mpg
-s 320x240 taille de l'image (320px x 240px)
-b 300k bitrate vidéo
-r 10 framerate vidéo à 10 fps
-ar 22050 fréquence de l'audio à 22050 Hz
-ab 64 bitrate audio à 64 kbit/s
ffmpeg -i IN.mpg -vcodec mpeg4 -s 320x240 -b 300k -r 10 -acodec mp3 -ar 22050 -ab 64k -f avi OUT.avi
-vcodec mpeg4 codec audio à utiliser
-f avi container
CROP ET PADDING L'IMAGE
Rogner 30 px en haut et en bas, puis convertir en 16:9 NTSC DVD:
ffmpeg -i IN.flv -croptop 30 -cropbottom 30 -target ntsc-dvd -aspect 16:9 OUT.169.mpg
-croptop 30 et -cropbottom 30 retire 30 pixels en haut et bas. Il existe aussi -cropleft et -cropright. Le crop doit être fait AVANT tout redimensionnement.
EX: Faire une video de 480x360 letterbox AVI à 15 frames par seconde :
ffmpeg -i IN.mpg -acodec mp3 -ar 44100 -ab 128k -vcodec msmpeg4v2 -b 500k \ -s 480x270 -r 15 -padtop 44 -padbottom 46 -padcolor 000000 -f avi OUT.avi
Pour garder un même ration avec 480 px wide, then the height will have to be 480/(16/9)=270 pixels, hence the "-s 480x270".
Our image being 270 pixels high while we need it to be 360 pixels high in order to obtain the standard 4:3 aspect ratio, we need to slap an extra 90 pixels on it. However, the number of pixels specified in the -padtop et -padbottom options has to be an even number, hence 44 for one and 46 for the other rather than 45 each.
-padcolor RRVVBB There are also "-padleft" and "-padright" options for widening an image with an aspect ratio that's too low for the target.
-pad are applied AFTER resizing has taken place. They add the specified number of pixels to the RESIZED image.
JUSTE UNE PARTIE DE LA VIDEO
-t 90 90s à convertir. On peut utiliser -t 00:02:37.200 (2 min 37s et 200ms).
-ss 90 début du segment à convertir à 90s ou 00:01:30.000
EX: convertir à partir de 3min pour une durée de 12min : -ss 180 ou -ss 00:03:00, et -t 720 ou -t 00:12:00.
IGNORER L'AUDIO OU LA VIDÉO
-an pour exclure le flux audio
-vn pour exclure le flux vidéo
exporter l'audio en 44.1 kHz, 16-bit, stéréo (2 canaux):
ffmpeg -i IN.flv -vn -acodec pcm_s16le -ar 44100 -ac 2 OUT.wav
ffmpeg -i IN.flv
Input #0, flv, from 'OUT.flv':
Duration: 00:04:25.7, start: 0.000000, bitrate: N/A
Stream #0.0: Audio: mp3, 22050 Hz, mono
Stream #0.1: Video: flv, yuv420p, 320x240, 29.97 fps(r)
ffmpeg -i IN.flv -vn -acodec copy OUT.mp3
-vcodec copy pour la vidéo
extract l'audio d'un DVD : mplayer -ao pcm:file=output.wav
tccat to obtain a .vob file of a DVD title, you can feed the .vob file to ffmpeg and extract the audio that way.
DVD ISO > AVI
ffmpeg -i A.vob
Input #0, mpeg, from 'mr.vob':
Duration: 00:03:16.2, start: 620.890956, bitrate: 7704 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x576, 6799 kb/s, 25.00 fps(r)
Stream #0.1[0x89]: Audio: dts, 48000 Hz, stereo, 768 kb/s
Stream #0.2[0x80]: Audio: ac3, 48000 Hz, 5:1, 384 kb/s
Stream #0.3[0x83]: Audio: ac3, 48000 Hz, stereo, 96 kb/s
Stream #0.4[0x82]: Audio: ac3, 48000 Hz, stereo, 96 kb/s
Stream #0.5[0x84]: Audio: ac3, 48000 Hz, stereo, 192 kb/s
Stream #0.6[0x2d]: Subtitle: dvdsub
Stream #0.7[0x2c]: Subtitle: dvdsub
Stream #0.8[0x2b]: Subtitle: dvdsub
Stream #0.9[0x2a]: Subtitle: dvdsub
The first stream, #0.0, is the video stream. Stream #0.1 is the DTS-encoded sound track and #0.2 is its AC3-encoded Dolby 5:1 equivalent. Stereo audio streams #0.3 through #0.5 are soundtracks with commentaries. Say I want to create a mono MP3 from this with the commentary from the third audio stream, #0.3. If I don't tell ffmpeg which one to use, it'll go ahead and transcode the first one it finds, the DTS stream in this case. I don't want that :
ffmpeg -i mr.vob -map 0:3 -vn -acodec mp3 -ar 22050 -ab 96k -ac 1 mr.mp3
-map can also be used to create a new movie from this .vob file using, for example stream #0.0 for the video and #0.5 for the audio. If any streams in a video file are mapped with "-map" then they must all be specified explicitly. Le 1er -map sert pour la vidéo, et le 2eme sert pour l'audio :
ffmpeg -i mr.vob -map 0:0 -map 0:5 -vcodec mpeg4 -b 1000k \ -s 640x360 -acodec mp3 -ar 22050 -ab 64k -ac 1 -f avi mr.avi
MULTIPLE SOURCES
ffmpeg -i oldmovie.vob -i altered_audio.wav -map 0:0 -map 1:0 -target ntsc-dvd \ -b required_video_bit_rate -aspect 16:9 newmovie.mpg
Or, if you'd rather use MP2 audio and a lower audio bit rate:
ffmpeg -i oldmovie.vob -i altered_audio.wav -map 0:0 -map 1:0 -target ntsc-dvd \ -b required_video_bit_rate -acodec mp2 -ab audio_bit_rate -aspect 16:9 newmovie.mpg
Obviously replace "16:9" with "4:3" if you're reworking a 4:3 aspect ratio movie. Also, this assumes that the first stream in the .vob file is the video stream, so you'll need to adjust the "-map 0:0" accordingly if, for example the video stream is the second stream as is the case with my DVD recorder, in which case you'll need "-map 0:1" instead. Either way round, this is the stream that'll be used for the video in the output file. The audio stream is mapped to "-map 1:0". The "1" means "second file" (remember, the list is zero-based) and the ":0" means "first stream".
DELAYING THE AUDIO OR THE VIDEO
-itsoffset
ffmpeg -i IN_1 -itsoffset 00:00:03.5 -i IN_2 ....
input_2 sera retardé de 3.5 seconds. In other words, The content of input_1 will start at the beginning of the movie generated by ffmpeg, and the content in input_2 will start 3.5 seconds into the movie.
NOTE : put the source that needs delaying after -itsoffset :
ffmpeg -i video_source -itsoffset delay -i audio_source -map 0:x -map 1:y ......
Conversely, if the audio comes in too late and the video therefore needs delaying:
ffmpeg -i audio_source -itsoffset delay -i video_source -map 1:x -map 0:y ......
Note how the "-map" options specify video from the second source and audio from the first in this second example.
Note also that video_source and audio_source can be the same file. Nothing's to stop you from fixing (or breaking) the A/V sync within the same original movie.
CALCUL DU BITRATE
bitrate = taille / durée. Ex, vidéo de 120 min dans un DVD? 4.5 Go / 120 min = 37,5 Mbytes/min. Divisé par 60 = 625 ko/s (5 000 kb). Enlever le birate de l'audio. On obtient le bitrate de la vidéo. Retirer environ 5% pour être à l'aise.
avi en mpg
ffmpeg -i test.avi out.mpg
avi > gif animés (non compressés) :
ffmpeg -i test.avi out.gif
wav > mp3 à 22050 Hz:
ffmpeg -i test.wav -ar 22050 out.mp3
Combinaison entre fichiers audio et fichiers vidéo
fusionner un fichier audio et un fichier vidéo pour créer une vidéo avec une piste sonore:
ffmpeg -i son.wav -i video.yuv out.mpg
Création de vidéos à partir d'un ensemble d'images
Les images sont diffusées l'une après l'autre suivant la cadence (-r), avec une compression fixée (-b). Puis on donne les fichiers sources et le fichier de sortie.
ffmpeg -r 24 -b 1800 -i %02d.bmp out.mpg
enchaînement de 24 im/s, avec un taux de compression 1800 Kbits/s. Les images sources sont 00.bmp, 01.bmp, 02.bmp,... selon le nombre d'images existantes.
options disponibles de ffmpeg
`-formats' Voir les formats, codecs et protocoles disponibles
`-i nomFichier' Fichier d’entrée
`-y' Ecrasement du fichier de sortie
`-title chaineDeCaracteres' Definir le titre de la vidéo .
`-author chaineDeCaracteres' Définir le nom de l’auteur.
`-copyright chaineDeCaracteres' Définir le copyright.
`-comment chaineDeCaracteres' Inclure des commentaires.
`-target type' Spécifier le format du fichier sortant
`-b bitrate' Spécifier le taux de compression en kb/s(par défaut = 200 kb/s).
`-r fps' Spécifier le nombre d’images par seconde (par défaut = 25).
-s size résolution en Largeurxhauteur (par défaut, 160x128).
Les abbreviations suivantes sont reconnues:
`sqcif' 128x96, `qcif' 176x144, `cif' 352x288, `4cif' 704x576
`-aspect aspect' Définir l’aspect (4:3, 16:9 ou 1.3333, 1.7777).
`-maxrate bitrate' Spécifier la tolérance maximale du taux de compression (en kbit/s).
`-minrate bitrate' Spécifier la tolérance minimale du taux de compression (en kbit/s).