Difference between revisions of "High quality screen capture with Ffmpeg"

From MyLabWiki
Jump to: navigation, search
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
Capture without audio:
 
  
   ffmpeg -f x11grab -r 25 -s 1280x720 -i :0.0+0,48 -vcodec libx264 -vpre lossless_ultrafast -threads 0 video.mkv
+
'''See also: [[High quality screen capture with avconv]]'''
 +
 
 +
== Capture without audio ==
 +
 
 +
   ffmpeg -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -vcodec libx264 -vpre lossless_ultrafast -threads 0 video.mkv
  
 
Compress and convert to MP4 format (Youtube ready):
 
Compress and convert to MP4 format (Youtube ready):
Line 7: Line 10:
 
   ffmpeg -i video.mkv -vcodec libx264 -vpre hq -crf '''22''' -threads 0 video.mp4
 
   ffmpeg -i video.mkv -vcodec libx264 -vpre hq -crf '''22''' -threads 0 video.mp4
  
Lower -crf gives higher quality. For post processing in iMovie or [[:Category:Final_Cut_Express|Final Cut Express]] better to use .mov container in the above conversion.
+
Lower -crf may give higher quality but for screen captures the improvement is only marginal. For post processing in iMovie or [[:Category:Final_Cut_Express|Final Cut Express]] better to use .mov container in the above conversion.
  
For including audio:
+
If ffmpeg complains that it has no '''hq''' preset, then try some of the others. Look for .ffpreset files in /usr/share/ffmpeg/. I had good success with '''-vpre medium''' (actually it might be the same as hq used to be).
  
   ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1024x768 -i :0.0 -acodec pcm_s16le  
+
== Capturing with audio ==
 +
 
 +
   ffmpeg -f alsa -i pulse -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -acodec pcm_s16le  
 
     -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv
 
     -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv
 +
 +
If you get "Application provided invalid, non monotonically increasing dts to muxer" errors try using MOV container instead.
  
 
In order to make ffmpeg capture audio from other applications:
 
In order to make ffmpeg capture audio from other applications:
Line 22: Line 29:
 
The settings will be remembered until we change them back.
 
The settings will be remembered until we change them back.
  
Note: This does not work with Java running in firefox.
+
Other useful audio options to adjust:
 +
* -ac: Channels
 +
* -ar: Audio sample rate
 +
* -ab: Audio bitrate
 +
 
 +
Notes:
 +
# This does not work with Java running in firefox. In fact, it does not seem to work with applications that play through the pulseaudio ALSA plugin.
  
 
'''TODO:'''<br/>
 
'''TODO:'''<br/>
Line 31: Line 44:
 
   pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2
 
   pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2
 
Can we use this device name in ffmpeg recording?
 
Can we use this device name in ffmpeg recording?
 
  
 
== References ==
 
== References ==

Latest revision as of 22:40, 19 March 2013

See also: High quality screen capture with avconv

Capture without audio

 ffmpeg -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -vcodec libx264 -vpre lossless_ultrafast -threads 0 video.mkv

Compress and convert to MP4 format (Youtube ready):

 ffmpeg -i video.mkv -vcodec libx264 -vpre hq -crf 22 -threads 0 video.mp4

Lower -crf may give higher quality but for screen captures the improvement is only marginal. For post processing in iMovie or Final Cut Express better to use .mov container in the above conversion.

If ffmpeg complains that it has no hq preset, then try some of the others. Look for .ffpreset files in /usr/share/ffmpeg/. I had good success with -vpre medium (actually it might be the same as hq used to be).

Capturing with audio

 ffmpeg -f alsa -i pulse -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -acodec pcm_s16le 
   -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mkv

If you get "Application provided invalid, non monotonically increasing dts to muxer" errors try using MOV container instead.

In order to make ffmpeg capture audio from other applications:

  1. Start the ffmpeg capture (it just has to run)
  2. Start pavucontrol
  3. In the Recording tab, ffmpeg should be visible and here we can choose between input and monitor

The settings will be remembered until we change them back.

Other useful audio options to adjust:

  • -ac: Channels
  • -ar: Audio sample rate
  • -ab: Audio bitrate

Notes:

  1. This does not work with Java running in firefox. In fact, it does not seem to work with applications that play through the pulseaudio ALSA plugin.

TODO:
The audio output can also be captured with gstreamer:

 gst-launch -e pulsesrc device="alsa_output.pci-0000_00_1b.0.analog-stereo.monitor" ! audioconvert ! \
               lamemp3enc target=1 bitrate=128 cbr=true ! filesink location=output.mp3

where the device name is the one returned by

 pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

Can we use this device name in ffmpeg recording?

References