Rechercher dans ce blog

vendredi 11 décembre 2015

ffmpeg encode settings mémo


ffmpeg encoding settings memo


To test settings : 

ffplay -i 'in-1920p'-vf "crop=1888:1056:0:0,scale=1280:720"

mac os x aac encoding  ffmpeg gpl

-strict -2 -codec:a aac -b:a 56k

From 720p

To Divx VGA


ffmpeg -i 'in-720p.mov' -c:v libxvid -filter:v crop=in_w-320:in_h,scale=640:480 -qscale:v 4 -ac 1 -codec:a libmp3lame -b:a 64k out-VGA.avi

to Divx 480p


ffmpeg -i 'in-720p.mov' -c:v libxvid -filter:v crop=in_w-200:in_h,scale=720:480 -qscale:v 4 -ac 1 -codec:a libmp3lame -b:a 64k out-480P.avi

to MP4 480p


ffmpeg -i 'in-720p.mov' -codec:v libx264 -preset slow -crf 18 -filter:v crop=in_w-200:in_h,scale=720:480 -ac 1 -codec:a libfdk_aac -b:a 56k out-480p.mp4

(Quality crf 18=high - 23=normal)

to MP4 480p main profile


fmpeg -i 'in-720p.mov' -codec:v libx264 -preset slow -filter:v crop=in_w-200:in_h,scale=720:480 -crf 18 -pix_fmt yuv420p -profile:v main -ac 1 -codec:a libfdk_aac -b:a 56k out-480p.mSap4

From HD 1920p

De 1080p à 720p même format d'image 16/9 : crop inutile.

De 1080p à 480p : crop=1616:1080:0:0

Normalement 1620 car 720/480= 1,5 et 1,5x1080=1620 mais pas divisible par 16. Donc j'arrondis à 1616.

De 1080p à VGA (640x480) : crop=1440:1080:0:0


Attention si crop nécessaire 

Maintient de dar et sar à 1
-aspect 16:9

SAINT JACUT MATIN SOIR

To 720p mp4


bin/ffmpeg28 -i /Users/moi/Desktop/sources\ vues\ backup/2012-09-28\ 07_12_19\ \(id\).mov -codec:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -profile:v main -vf rotate=-1.5*PI/180:bilinear=1,format=yuv420p,crop=1856:1008:48:48,scale=1280:720 -aspect 16:9 -an saint-jacut_1_nosound-nots-720P-H264-aac-crf18-main-yuv420p.mp4

bin/ffmpeg28 -i "/Users/moi/Desktop/sources vues backup/2012-09-28 14_15_01 (id).mov" -codec:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -profile:v main -vf rotate=-1.5*PI/180:bilinear=1,format=yuv420p,crop=1856:1008:48:48,scale=1280:720 -aspect 16:9 -t 05:18:12  -an saint-jacut_2_nosound-nots-720P-H264-aac-crf18-main-yuv420p.mp4

Saint Jacut marée montante

Le crop est calculé pour couper l'image en bas 1056 (pour retirer la barrière), puis à droite pour conserver le rapport h/l selon le format de sortie. Le crop est calculé également pour être divisible par 16

To mp4 720p


ffmpeg -i 'in-1920p.mov' -codec:v libx264 -preset slow -filter:v crop=1888:1056:0:0,scale=1280:720 -crf 18 -pix_fmt yuv420p -profile:v main -ac 1 -codec:a libfdk_aac -b:a 56k out-720p.mp4

To mp4 480p


ffmpeg -i 'in-1920p.mov' -codec:v libx264 -preset slow -filter:v crop=1584:1056:0:0,scale=720:480 -crf 18 -profile:v main -ac 1 -codec:a libfdk_aac -b:a 56k out-480p.mp4

To mp4 480p no audio


ffmpeg -i 'in-1920p.mov' -codec:v libx264 -preset slow -filter:v crop=1584:1056:0:0,scale=720:480 -crf 18 -profile:v main -an out-480p.mp4

To mp4 VGA


ffmpeg -i 'in-1980p.mov' -codec:v libx264 -preset slow -filter:v crop=1408:1056:0:0,scale=640:480 -crf 18  -profile:v main -ac 1 -codec:a libfdk_aac -b:a 56k out-VGA.mp4

To mp4 VGA no audio


ffmpeg -i 'in-1980p.mov' -codec:v libx264 -preset slow -filter:v crop=1408:1056:0:0,scale=640:480 -crf 18  -profile:v main -an out-VGA.mp4

no sound => -an

From HD SONY 1440 to VGA with rotation (machines à laver)


ffmpeg -i '/in-1440.mov' -c:v libxvid -filter:v hflip,vflip,format=yuv420p,scale=640:480 -qscale 4 -ac 1 -codec:a libmp3lame -b:a 64k out-VGA.avi


Méthodes de rotation - ffmpeg options


* rotate=PI:bilinear=0,format=yuv420p

* hflip,vflip,format=yuv420p

* transpose=2,transpose=2,format=yuv420p" -metadata:s:v rotate=0

* cropdetect=24:16:0

Start and End time position to encoding


ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss START -t LENGTH OUTFILE.mp4
where START is starting positing in seconds or in format hh:mm:ss LENGTH is the chunk length in seconds or in format hh:mm:ss

So you will need to run this command few times depending on how long your video. If let's say your video is 31 minutes long and you want so split into 15 min chunks here is how you run it:

ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 0 -t 00:15:00 OUTFILE-1.mp4

ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 00:15:00 -t 00:15:00 OUTFILE-2.mp4

Concat demuxer

The concat demuxer was added to FFmpeg 1.1. You can read about it in the documentation.

Instructions

Create a file mylist.txt with all the files you want to have concatenated in the following form (lines starting with a # are ignored):
# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Note that these can be either relative or absolute paths. Then you can stream copy or re-encode your files:
ffmpeg -f concat -i mylist.txt -c copy output

----

Constant Rate Factor (CRF) - ffmpeg options profiles...


This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression efficiency with a single pass. Each frame gets the bitrate it needs to keep the requested quality level. The downside is that you can't tell it to get a specific filesize or not go over a specific size or bitrate.

1. Choose a CRF value

The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn't technically lossless.

The range is exponential, so increasing the CRF value +6 is roughly half the bitrate while -6 is roughly twice the bitrate. General usage is to choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value and if it looks bad then choose a lower value.

Note: The CRF quantizer scale mentioned on this page only applies to 8-bit x264 (10-bit x264 quantizer scale is 0-63). You can see what you are using by referring to the ffmpeg console output during encoding (yuv420p or similar for 8-bit, and yuv420p10le or similar for 10-bit). 8-bit is more common among distributors.

2. Choose a preset

A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.

The general guideline is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. The default preset is medium. Ignore placebo as it is not useful (see FAQ). You can see a list of current presets with -preset help (see example below), and what settings they apply with x264 --fullhelp.

You can optionally use -tune to change settings based upon the specifics of your input. Current tunings include: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency. For example, if your input is animation then use the animation tuning, or if you want to preserve grain then use the grain tuning. If you are unsure of what to use or your input does not match any of tunings then omit the -tune option. You can see a list of current tunings with -tune help, and what settings they apply with x264 --fullhelp.

Profiles

Another optional setting is -profile:v which will limit the output to a specific H.264 profile. This can generally be omitted unless the target device only supports a certain profile (see Compatibility). Current profiles include: baseline, main, high, high10, high422, high444. Note that usage of -profile:v is incompatible with lossless encoding.

To list all possible internal preset and tunes:

ffmpeg -f lavfi -i nullsrc -c:v libx264 -preset help -f mp4 -


------------

ffmpeg map option


from : https://trac.ffmpeg.org/wiki/Map

In all following examples, we will use an example input file like this one:
# fmpeg -i input.mkv

ffmpeg version ... Copyright (c) 2000-2012 the FFmpeg developers
...
Input #0, matroska,webm, from 'input.mkv':
  Duration: 01:39:44.02, start: 0.000000, bitrate: 5793 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x800, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(ger): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
    Stream #0:2(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
    Stream #0:3(ger): Subtitle: text (default)
At least one output file must be specified

#

Example 1

Now, let's say we want to:
  • copy video stream
  • encode german audio stream to mp3 (128kbps) and aac (96kbps) (creating 2 audio streams in the output)
  • drop english audio stream
  • copy subtitle stream
This can be done using the following FFmpeg command line:
ffmpeg -i input.mkv \
    -map 0:0 -map 0:1 -map 0:1 -map 0:3 \
    -c:v copy \
    -c:a:0 libmp3lame -b:a:0 128k \
    -c:a:1 libfaac -b:a:1 96k \
    -c:s copy \
    output.mkv
Note there is no "-map 0:2" and that "-map 0:1" has been specified twice.
Using "-map 0:0 -map 0:1 -map 0:1 -map 0:3" we told FFmpeg to select/map specified input streams to output in that order.
So, our output will now have the following streams:
Output #0, matroska, to 'output.mkv':
    Stream #0:0(eng): Video ...
    Stream #0:1(ger): Audio ...
    Stream #0:2(ger): Audio ...
    Stream #0:3(ger): Subtitle ...
After we selected which streams we would like in our output, using "-map" option, we specified codecs for each stream in our output.
Video and subtitle stream have just been copied and german audio stream has been encoded to 2 new audio streams, mp3 and aac.
We used "-c:a:0" to specify codec for the output's first AUDIO stream and "-c:a:1" to specify codec for the output's second AUDIO stream.
Note that "a:0" refers to the output's first AUDIO stream (#0:1 in our case), "a:1" refers to the output's 2nd AUDIO stream (#0:2 in our case), etc.
The result will be:
Output #0, matroska, to 'output.mkv':
    Stream #0:0(eng): Video ...
    Stream #0:1(ger): Audio ...
    Stream #0:2(ger): Audio ...
    Stream #0:3(ger): Subtitle ...
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (dca -> libmp3lame)
  Stream #0:2 -> #0:2 (dca -> libfaac)
  Stream #0:3 -> #0:3 (copy)

Example 2

Let's say that we want to reorder input streams backwards, so that we have output like this:
    Stream #0:0(ger): Subtitle: text (default)
    Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
    Stream #0:2(ger): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
    Stream #0:3(eng): Video: h264 (High), yuv420p, 1920x800, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
This can simply be done using the following command line:
ffmpeg -i input.mkv -map 0:3 -map 0:2 -map 0:1 -map 0:0 -c copy output.mkv
Note that we specified all the input streams, but in the reverse order, which causes that order to be respected in the output.
The option "-c copy" tells FFmpeg to use "copy" on all streams.

Example 3

If we want to extract only audio streams, from input file, then we can do it like this:
ffmpeg -i input.mkv -map 0:1 -map 0:2 -c copy output.mkv

Example 4

If we want to re-encode just the video streams, but copy all the other streams (like audio, subtitles, attachments, etc), we might use something like this:
ffmpeg -i input.mkv -map 0 -c copy -c:v mpeg2video output.mkv
It will tell ffmpeg to:
  • read the input file 'input.mkv'
  • select all the input streams (first input = 0) to be processed (using "-map 0")
  • mark all the streams to be just copied to the output (using "-c copy")
  • mark just the video streams to be re-encoded (using "-c:v mpeg2video")
  • write the output file 'output.mkv'