Notes to Self

Alex Sokolsky's Notes on Computers and Programming


fast-forward mpeg? Not really. ffmpeg man page, use with webcam.


Know thyself.

Identify the audio recording devices available with pacmd list-sources. I picked alsa_input.usb-046d_HD_Pro_Webcam_C920_CDF1191F-02.analog-stereo.

Identify the video formats available using

v4l2-ctl --list-formats-ext -d /dev/video4


ffmpeg -f v4l2 -list_formats all -i /dev/video0

I picked MJPG 1920x1080.


This will:

ffmpeg -y \
    -f v4l2 -t 10 -framerate 30 -video_size 1920x1080 -input_format mjpeg -i /dev/video4 \
    -f pulse -t 10 -sample_rate 44100 -channels 1 -i alsa_input.usb-046d_HD_Pro_Webcam_C920_CDF1191F-02.analog-stereo \
    -c:v libx264 -preset faster -c:a ac3_fixed \
    -metadata title="From my desk" out.mkv

To avoid re-compression:

ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -input_format mjpeg \
    -i /dev/video0 -c copy out.mkv


Take a picture

ffmpeg -f v4l2 -video_size 1280x720 -i /dev/video0 -frames 1 out.jpg


More Utilities

Use ffprobe to display stream info:

ffprobe out.mkv

Simple player:

ffplay /dev/video0

Trimming / Extraction

To cut out 20 seconds starting from 1:50 minutes, use:

ffmpeg -i input.mkv -ss 00:01:50 -c copy -t 20 output.mkv

The -ss option can be placed in front of -i, resulting in faster copying but less accuracy. If you experience out-of-sync audio or video, you will have to have to re-encode:

ffmpeg -i input.mkv -ss 00:01:50 -c:v libx264 -c:a libfaac -t 20 output.mkv