aboutsummaryrefslogtreecommitdiffhomepage
path: root/DOCS/encoding.rst
blob: fa3ffb8c4a7b9ba3c471bd8eced68a24556c5bf9 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
General usage
=============

::

  mpv infile -o outfile [-of outfileformat] [-ofopts formatoptions] \
    [-ofps outfps | -oautofps] [-oharddup] [-ocopyts | -orawts] [-oneverdrop] \
    [(any other mpv options)] \
    -ovc outvideocodec [-ovcopts outvideocodecoptions] \
    -oac outaudiocodec [-oacopts outaudiocodecoptions]

Help for these options is provided if giving help as parameter, as in::

  mpv -ovc help

The suboptions of these generally are identical to ffmpeg's (as option parsing
is simply delegated to ffmpeg). The option -ocopyts enables copying timestamps
from the source as-is, instead of fixing them to match audio playback time
(note: this doesn't work with all output container formats); -orawts even turns
off discontinuity fixing.

Note that if neither -ofps nor -oautofps is specified, VFR encoding is assumed
and the time base is 24000fps. -oautofps sets -ofps to a guessed fps number
from the input video. Note that not all codecs and not all formats support VFR
encoding, and some which do have bugs when a target bitrate is specified - use
-ofps or -oautofps to force CFR encoding in these cases.

Of course, the options can be stored in a profile, like this .config/mpv/mpv.conf
section::

  [myencprofile]
  vf-add = scale=480:-2
  ovc = libx264
  ovcopts-add = preset=medium,tune=fastdecode
  ovcopts-add = crf=23
  ovcopts-add = maxrate=1500k,bufsize=1000k,rc_init_occupancy=900k,refs=2
  ovcopts-add = profile=baseline
  oac = aac
  oacopts-add = b=96k

It's also possible to define default encoding options by putting them into
the section named ``[encoding]``. (This behavior changed after mpv 0.3.x. In
mpv 0.3.x, config options in the default section / no section were applied
to encoding. This is not the case anymore.)

One can then encode using this profile using the command::

  mpv infile -o outfile.mp4 -profile myencprofile

Some example profiles are provided in a file
etc/encoding-profiles.conf; as for this, see below.


Encoding examples
=================

These are some examples of encoding targets this code has been used and tested
for.

Typical MPEG-4 Part 2 ("ASP", "DivX") encoding, AVI container::

  mpv infile -o outfile.avi \
    -ofps 25 \
    -ovc mpeg4 -ovcopts qscale=4 \
    -oac libmp3lame -oacopts ab=128k

Note: AVI does not support variable frame rate, so -ofps must be used. The
frame rate should ideally match the input (25 for PAL, 24000/1001 or 30000/1001
for NTSC)

Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, Matroska (MKV) container::

  mpv infile -o outfile.mkv \
    -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \
    -oac libvorbis -oacopts qscale=3

Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, MPEG-4 (MP4) container::

  mpv infile -o outfile.mp4 \
    -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \
    -oac aac -oacopts ab=128k

Typical VP8 encoding, WebM (restricted Matroska) container::

  mpv infile -o outfile.mkv \
    -of webm \
    -ovc libvpx -ovcopts qmin=6,b=1000000k \
    -oac libvorbis -oacopts qscale=3


Device targets
==============

As the options for various devices can get complex, profiles can be used.

An example profile file for encoding is provided in
etc/encoding-profiles.conf in the source tree. This file is installed and loaded
by default (if libavfilter is enabled at compilation). If you want to modify
it, you can replace and it with your own copy by doing::

  mkdir -p ~/.mpv
  cp /etc/mpv/encoding-profiles.conf ~/.mpv/encoding-profiles.conf

Refer to the top of that file for more comments - in a nutshell, the following
options are added by it::

  -profile enc-to-dvdpal      DVD-Video PAL, use dvdauthor -v pal+4:3 -a ac3+en
  -profile enc-to-dvdntsc     DVD-Video NTSC, use dvdauthor -v ntsc+4:3 -a ac3+en
  -profile enc-to-bb-9000     MP4 for Blackberry Bold 9000
  -profile enc-to-nok-6300    3GP for Nokia 6300
  -profile enc-to-psp         MP4 for PlayStation Portable
  -profile enc-to-iphone      MP4 for iPhone
  -profile enc-to-iphone-4    MP4 for iPhone 4 (double res)
  -profile enc-to-iphone-5    MP4 for iPhone 5 (even larger res)

You can encode using these with a command line like::

  mpv infile -o outfile.mp4 -profile enc-to-bb-9000

Of course, you are free to override options set by these profiles by specifying
them after the -profile option.


What works
==========

* Encoding at variable frame rate (default)
* Encoding at constant frame rate using -ofps framerate -oharddup
* 2-pass encoding (specify flags=+pass1 in the first pass's -ovcopts, specify
  flags=+pass2 in the second pass)
* Hardcoding subtitles using vobsub, ass or srt subtitle rendering (just
  configure mpv for the subtitles as usual)
* Hardcoding any other mpv OSD (e.g. time codes, using -osdlevel 3 and -vf
  expand=::::1)
* Encoding directly from a DVD, network stream, webcam, or any other source
  mpv supports
* Using x264 presets/tunings/profiles (by using profile=, tune=, preset= in the
  -ovcopts)
* Deinterlacing/Inverse Telecine with any of mpv's filters for that
* Audio file converting: mpv -o outfile.mp3 infile.flac -no-video -oac
  libmp3lame -oacopts ab=320k

What does not work yet
======================

* 3-pass encoding (ensuring constant total size and bitrate constraints while
  having VBR audio; mencoder calls this "frameno")
* Direct stream copy