Advertisement
thioshp

Encode Video/Audio Files with MPV

May 8th, 2016
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. General usage
  2. =============
  3.  
  4. ::
  5.  
  6. mpv infile -o outfile [-of outfileformat] [-ofopts formatoptions] \
  7. [-ofps outfps | -oautofps] [-oharddup] [-ocopyts | -orawts] [-oneverdrop] \
  8. [(any other mpv options)] \
  9. -ovc outvideocodec [-ovcopts outvideocodecoptions] \
  10. -oac outaudiocodec [-oacopts outaudiocodecoptions]
  11.  
  12. Help for these options is provided if giving help as parameter, as in::
  13.  
  14. mpv -ovc help
  15.  
  16. The suboptions of these generally are identical to ffmpeg's (as option parsing
  17. is simply delegated to ffmpeg). The option -ocopyts enables copying timestamps
  18. from the source as-is, instead of fixing them to match audio playback time
  19. (note: this doesn't work with all output container formats); -orawts even turns
  20. off discontinuity fixing.
  21.  
  22. Note that if neither -ofps nor -oautofps is specified, VFR encoding is assumed
  23. and the time base is 24000fps. -oautofps sets -ofps to a guessed fps number
  24. from the input video. Note that not all codecs and not all formats support VFR
  25. encoding, and some which do have bugs when a target bitrate is specified - use
  26. -ofps or -oautofps to force CFR encoding in these cases.
  27.  
  28. Of course, the options can be stored in a profile, like this .config/mpv/mpv.conf
  29. section::
  30.  
  31. [myencprofile]
  32. vf-add = scale=480:-2
  33. ovc = libx264
  34. ovcopts-add = preset=medium,tune=fastdecode
  35. ovcopts-add = crf=23
  36. ovcopts-add = maxrate=1500k,bufsize=1000k,rc_init_occupancy=900k,refs=2
  37. ovcopts-add = profile=baseline
  38. oac = aac
  39. oacopts-add = b=96k
  40.  
  41. It's also possible to define default encoding options by putting them into
  42. the section named ``[encoding]``. (This behavior changed after mpv 0.3.x. In
  43. mpv 0.3.x, config options in the default section / no section were applied
  44. to encoding. This is not the case anymore.)
  45.  
  46. One can then encode using this profile using the command::
  47.  
  48. mpv infile -o outfile.mp4 -profile myencprofile
  49.  
  50. Some example profiles are provided in a file
  51. etc/encoding-profiles.conf; as for this, see below.
  52.  
  53.  
  54. Encoding examples
  55. =================
  56.  
  57. These are some examples of encoding targets this code has been used and tested
  58. for.
  59.  
  60. Typical MPEG-4 Part 2 ("ASP", "DivX") encoding, AVI container::
  61.  
  62. mpv infile -o outfile.avi \
  63. -ofps 25 \
  64. -ovc mpeg4 -ovcopts qscale=4 \
  65. -oac libmp3lame -oacopts ab=128k
  66.  
  67. Note: AVI does not support variable frame rate, so -ofps must be used. The
  68. frame rate should ideally match the input (25 for PAL, 24000/1001 or 30000/1001
  69. for NTSC)
  70.  
  71. Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, Matroska (MKV) container::
  72.  
  73. mpv infile -o outfile.mkv \
  74. -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \
  75. -oac libvorbis -oacopts qscale=3
  76.  
  77. Typical MPEG-4 Part 10 ("AVC", "H.264") encoding, MPEG-4 (MP4) container::
  78.  
  79. mpv infile -o outfile.mp4 \
  80. -ovc libx264 -ovcopts preset=medium,crf=23,profile=baseline \
  81. -oac aac -oacopts ab=128k
  82.  
  83. Typical VP8 encoding, WebM (restricted Matroska) container::
  84.  
  85. mpv infile -o outfile.mkv \
  86. -of webm \
  87. -ovc libvpx -ovcopts qmin=6,b=1000000k \
  88. -oac libvorbis -oacopts qscale=3
  89.  
  90.  
  91. Device targets
  92. ==============
  93.  
  94. As the options for various devices can get complex, profiles can be used.
  95.  
  96. An example profile file for encoding is provided in
  97. etc/encoding-profiles.conf in the source tree. This file is installed and loaded
  98. by default (if libavfilter is enabled at compilation). If you want to modify
  99. it, you can replace and it with your own copy by doing::
  100.  
  101. mkdir -p ~/.mpv
  102. cp /etc/mpv/encoding-profiles.conf ~/.mpv/encoding-profiles.conf
  103.  
  104. Refer to the top of that file for more comments - in a nutshell, the following
  105. options are added by it::
  106.  
  107. -profile enc-to-dvdpal DVD-Video PAL, use dvdauthor -v pal+4:3 -a ac3+en
  108. -profile enc-to-dvdntsc DVD-Video NTSC, use dvdauthor -v ntsc+4:3 -a ac3+en
  109. -profile enc-to-bb-9000 MP4 for Blackberry Bold 9000
  110. -profile enc-to-nok-6300 3GP for Nokia 6300
  111. -profile enc-to-psp MP4 for PlayStation Portable
  112. -profile enc-to-iphone MP4 for iPhone
  113. -profile enc-to-iphone-4 MP4 for iPhone 4 (double res)
  114. -profile enc-to-iphone-5 MP4 for iPhone 5 (even larger res)
  115.  
  116. You can encode using these with a command line like::
  117.  
  118. mpv infile -o outfile.mp4 -profile enc-to-bb-9000
  119.  
  120. Of course, you are free to override options set by these profiles by specifying
  121. them after the -profile option.
  122.  
  123.  
  124. What works
  125. ==========
  126.  
  127. * Encoding at variable frame rate (default)
  128. * Encoding at constant frame rate using -ofps framerate -oharddup
  129. * 2-pass encoding (specify flags=+pass1 in the first pass's -ovcopts, specify
  130. flags=+pass2 in the second pass)
  131. * Hardcoding subtitles using vobsub, ass or srt subtitle rendering (just
  132. configure mpv for the subtitles as usual)
  133. * Hardcoding any other mpv OSD (e.g. time codes, using -osdlevel 3 and -vf
  134. expand=::::1)
  135. * Encoding directly from a DVD, network stream, webcam, or any other source
  136. mpv supports
  137. * Using x264 presets/tunings/profiles (by using profile=, tune=, preset= in the
  138. -ovcopts)
  139. * Deinterlacing/Inverse Telecine with any of mpv's filters for that
  140. * Audio file converting: mpv -o outfile.mp3 infile.flac -no-video -oac
  141. libmp3lame -oacopts ab=320k
  142.  
  143. What does not work yet
  144. ======================
  145.  
  146. * 3-pass encoding (ensuring constant total size and bitrate constraints while
  147. having VBR audio; mencoder calls this "frameno")
  148. * Direct stream copy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement