Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not an ffmpeg wizard here, but here are my screencasting commands. Probably the most useful knowledge in this snippet is how to use Alsa from ffmpeg; i.e., Alsa devices can be referred to as hw:0, hw:1, etc; and one finds out which device to use from arecord.

  # Example output file.
  f=/tmp/output.mp4

  # Example video resolution.
  g=1920x1080

  # Example capture framerate
  fr=4

  # Example X11 display
  d=$DISPLAY

  # Simple screencast.
  #
  # Try adjusting the libx264 CRF from 15 to some greater number, as long
  # as there is no visible effect on video quality.
  #
  # If increasing the capture framerate, you may also wish to use a
  # faster preset.
  ffmpeg  -probesize 50M  -f x11grab -video_size "$g" -framerate "$fr" -i "$d"    \
         -c:v libx264 -crf 15 -preset veryslow   "$f"

  # Simple screencast without drawing the pointer/cursor.
  ffmpeg  -probesize 50M  -f x11grab -video_size "$g" -framerate "$fr" -draw_mouse 0 -i "$d"      \
         -c:v libx264 -crf 15 -preset veryslow   "$f"

  # See what devices are available for capturing sound.
  arecord -l

  # Select a device.
  audioCaptureDevice=hw:0

  # List some permitted parameters associated with device 0.
  #
  # We are interested in the "FORMAT", "CHANNELS", and "RATE" parameters
  # for use in the ffmpeg command.
  arecord --dump-hw-params -D "$audioCaptureDevice"

  audioSampleFormat=pcm_s32le
  audioNumChannels=2
  audioRate=44100

  f=/tmp/output.mp3

  # Record sound.
  ffmpeg  -thread_queue_size 8192 -f alsa -channels "$audioNumChannels" -sample_rate "$audioRate" \
         -c:a "$audioSampleFormat" -ar "$audioRate" -i "$audioCaptureDevice" "$f"

  f=/tmp/output.mkv

  # Screencast with sound.
  #
  # Note that there seems to be an FFMPEG bug where the audio in the last
  # 15 seconds of the video is cut off. The workaround is to record for
  # 15 exrtra seconds, and then cut the extra video.
  ffmpeg  -probesize 50M  -f x11grab -video_size "$g" -framerate "$fr" -i "$d"                    \
         -thread_queue_size 8192 -f alsa -channels "$audioNumChannels" -sample_rate "$audioRate" \
         -c:a "$audioSampleFormat" -ar "$audioRate" -i "$audioCaptureDevice"                     \
         -c:a flac -c:v libx264 -crf 17          "$f"


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: