summaryrefslogtreecommitdiff
path: root/doc/note/ffmpeg/ffmpeg.txt
blob: 2b18a44fc576c512c4f86f1b8978532aeb9af168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

ffmpeg
================

## Extract Audio From webm

Lookup format of audio stream with:

  ffmpeg -i in.webm

Then use that knowlege to extract that (audio) stream:

  ffmpeg -i in.webm -vn -acodec copy out.FORMAT_FROM_BEFORE



## Convert Formats

  ffmpeg -i in.opus out.wav


## Fine-tune audio codec

[See also](https://slhck.info/video/2017/02/24/vbr-settings.html)

Use  -codec:v copy  to keep video, or -codec:v no  for audio-only.

  -codec:a aac        -q:a 1.3   (min=0.1, good=1.3 max=2)
  -codec:a aac        -b:a 96k
  -codec:a libmp3lame -q:a 2
  -codec:a libopus
  -filter:a lowpass=f=16000


## Record Desktop

  ffmpeg -f gdigrab -framerate 6 -probesize 10M -offset_x 0 -offset_y 0 \
      -video_size 1920x1200 -show_region 1 -i desktop -c:v h264_qsv \
      -pix_fmt yuv420p "output-$(date +%Y%m%d-%H%M%S).mp4"


## Trim video

  -i INFILE -ss <pos> -t <dur> OUTFILE
  -i INFILE -ss <pos> -to <pos> OUTFILE


## Concatenate

  && ffmpeg -i one.mkv -i two.mkv \
       -filter_complex '[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]' \
       -map "[v]" -map "[a]" out.mkv \


## Rotate Portrait

  -i INFILE -vf "transpose=2" OUTFILE



## Video to Gif

HINT: Use same filter for palette as for conversion.

  FILTERV=fps=6,scale=-1:600
  FILTERV=fps=6,scale=-1:480
  INPUTV=input.mp4

Create custom palette:
  ffmpeg -ss 4 -t 33 -i "$INPUTV" -vf "$FILTERV,palettegen=stats_mode=diff" palette.png

Use this palette:
  ffmpeg -ss 4 -t 33 -i "$INPUTV" -i palette.png -filter_complex "[0:v]$FILTERV[vid];[vid][1:v]paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" output.gif

Working example from web (but not optimized):
  ffmpeg -ss 0 -t 2.5 -i INPUT.mp4 -filter_complex "[0:v] fps=12,scale=-1:600,split [a][b];[a] palettegen=stats_mode=diff [p];[b][p] paletteuse=new=1" OUTPUT.gif


## Pictures to Video (eg Timelapse)

  -start_number 5619 -framerate 24 -i "input/IMG_%d.JPG" \
    -vf "scale=4096:-1,crop=4096:2160:0:0" \
    out.mkv