Skip to content

Instantly share code, notes, and snippets.

@rudolfbyker
Last active August 9, 2025 19:32
Show Gist options
  • Save rudolfbyker/017abd82d6bb62c60627d1dc74ec18ac to your computer and use it in GitHub Desktop.
Save rudolfbyker/017abd82d6bb62c60627d1dc74ec18ac to your computer and use it in GitHub Desktop.

Revisions

  1. rudolfbyker revised this gist Aug 9, 2025. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -288,18 +288,18 @@ When capturing directly using ffmpeg, I could only get "progressive interleaved"

    It's better to capture the interlaced video directly (see `capture_gstreamer_raw.sh`) and run it through a more advanced deinterlacing filter like [`nnedi`](https://ffmpeg.org/ffmpeg-all.html#nnedi).

    ## Watch the stream from the TV card directly in the terminal

    Capture using Gstreamer, without worrying about quality or synchronization.
    Low latency is the top priority here.
    Use `mpv` for playback, which works even without installing a desktop environment.

    See `watch.sh` below.

    ## Other useful commands

    ### Watch a video file from the beginning even though it's still being written to

    ```shell
    tail -f tmp.mkv | ffmpeg -i - -f mpegts - | mpv -
    ```

    ### Watch the stream from the TV card directly in the terminal

    Use `mpv` for playback. Use `ffmpeg` to transcode into a format that `mpv` understands. Because we use `mpv`, this even works without installing a desktop environment.

    ```shell
    ffmpeg -i /dev/video0 -f alsa -i hw:1 -c:v libx264 -preset fast -c:a aac -f mpegts - | mpv -
    ```
  2. rudolfbyker revised this gist Aug 9, 2025. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions watch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/usr/bin/env sh
    # See https://www.linuxtv.org/wiki/index.php/V4L_capturing

    set -eu

    VIDEO_DEVICE=/dev/video0
    VIDEO_CAPABILITIES="video/x-raw,format=YUY2,width=720,height=576,framerate=25/1" # YUY2 == yuyv422 == YUV 4:2:2

    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # Our VHS player only has mono output

    TV_NORM="PAL-I" # PAL-I for South Africa

    gst-launch-1.0 -q \
    v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" \
    ! $VIDEO_CAPABILITIES \
    ! queue max-size-buffers=1 leaky=downstream \
    ! videoconvert \
    ! jpegenc quality=85 \
    ! image/jpeg,framerate=25/1 \
    ! fdsink fd=1 | \
    mpv --no-cache --untimed --profile=low-latency --demuxer-lavf-format=mjpeg -
  3. rudolfbyker revised this gist Aug 9, 2025. 4 changed files with 51 additions and 19 deletions.
    10 changes: 10 additions & 0 deletions capture_gstreamer_ffv1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/usr/bin/env sh

    set -eu

    v4l2-ctl --set-input 1
    sleep 1

    SCRIPTS_DIR="$(dirname "$0")"

    "$SCRIPTS_DIR/capture_gstreamer_to_stdout.sh" | ffmpeg -y -hide_banner -i pipe:0 -c:v ffv1 -c:a copy $(date +%Y%m%dT%H%M%S).mkv
    12 changes: 12 additions & 0 deletions capture_gstreamer_ffv1_segments.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/usr/bin/env sh

    set -eu

    v4l2-ctl --set-input 1
    sleep 1

    SCRIPTS_DIR="$(dirname "$0")"
    BASE="$(date +%Y%m%dT%H%M%S)"
    SEGMENT_TIME=600

    "$SCRIPTS_DIR/capture_gstreamer_to_stdout.sh" | ffmpeg -y -hide_banner -i pipe:0 -c:v ffv1 -c:a copy -f segment -segment_time "$SEGMENT_TIME" -reset_timestamps 1 "${BASE}_%03d.mkv"
    23 changes: 4 additions & 19 deletions capture_gstreamer_raw.sh
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,10 @@
    #!/usr/bin/env sh
    # See https://www.linuxtv.org/wiki/index.php/V4L_capturing

    set -eu

    VIDEO_DEVICE=/dev/video0
    VIDEO_CAPABILITIES="video/x-raw, format=YUY2" # YUY2 == yuyv422 == YUV 4:2:2
    v4l2-ctl --set-input 1
    sleep 1

    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # My VHS player only has mono output
    SCRIPTS_DIR="$(dirname "$0")"

    TV_NORM="PAL-I" # PAL-I for South Africa

    gst-launch-1.0 -q \
    v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
    ! $VIDEO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    alsasrc device="$AUDIO_DEVICE" do-timestamp=true \
    ! $AUDIO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    matroskamux name=mux \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! fdsink fd=1
    "$SCRIPTS_DIR/capture_gstreamer_to_stdout.sh" | pv > $(date +%Y%m%dT%H%M%S).mkv
    25 changes: 25 additions & 0 deletions capture_gstreamer_to_stdout.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/usr/bin/env sh
    # See https://www.linuxtv.org/wiki/index.php/V4L_capturing

    set -eu

    VIDEO_DEVICE=/dev/video0
    VIDEO_CAPABILITIES="video/x-raw,format=YUY2,width=720,height=576,framerate=25/1" # YUY2 == yuyv422 == YUV 4:2:2

    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # Our VHS player only has mono output

    TV_NORM="PAL-I" # PAL-I for South Africa

    gst-launch-1.0 -q \
    v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
    ! $VIDEO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    alsasrc device="$AUDIO_DEVICE" do-timestamp=true \
    ! $AUDIO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    matroskamux name=mux \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! fdsink fd=1
  4. rudolfbyker revised this gist Jun 21, 2025. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,7 @@
    - v4l-utils
    - gstreamer1.0-tools
    - gstreamer1.0-plugins-good
    - gstreamer1.0-alsa

    ## Setting up the driver

    2 changes: 1 addition & 1 deletion capture_gstreamer_raw.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    set -eu

    VIDEO_DEVICE=/dev/video0
    VIDEO_CAPABILITIES="video/x-raw, format=YUY2"
    VIDEO_CAPABILITIES="video/x-raw, format=YUY2" # YUY2 == yuyv422 == YUV 4:2:2

    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # My VHS player only has mono output
  5. rudolfbyker revised this gist Jun 21, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion capture_gstreamer_raw.sh
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ VIDEO_CAPABILITIES="video/x-raw, format=YUY2"
    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # My VHS player only has mono output

    TV_NORM="PAL"
    TV_NORM="PAL-I" # PAL-I for South Africa

    gst-launch-1.0 -q \
    v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
  6. rudolfbyker revised this gist Jun 21, 2025. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,8 @@
    - ffmpeg
    - alsa-utils
    - v4l-utils
    - gstreamer1.0-tools
    - gstreamer1.0-plugins-good

    ## Setting up the driver

  7. rudolfbyker revised this gist Nov 26, 2023. 2 changed files with 27 additions and 16 deletions.
    18 changes: 2 additions & 16 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -281,23 +281,9 @@ Input #0, alsa, from 'hw:1':

    ## Capturing

    ### Video only
    When capturing directly using ffmpeg, I could only get "progressive interleaved" video. Interleaving is a very naive deinterlacing algorithm: It simply combines two frames into one by using the odd rows from one and the even rows from the next. This produces a lot of visual artifacts.

    ```shell
    ffmpeg -i /dev/video0 -c copy out.mkv
    ```

    ### Audio only

    ```shell
    ffmpeg -f alsa -i hw:1 -c copy out.wav
    ```

    ### Video and audio

    ```shell
    ffmpeg -i /dev/video0 -f alsa -i hw:1 -c copy -t 10 /home/dolf/videos/tmp.mkv
    ```
    It's better to capture the interlaced video directly (see `capture_gstreamer_raw.sh`) and run it through a more advanced deinterlacing filter like [`nnedi`](https://ffmpeg.org/ffmpeg-all.html#nnedi).

    ## Other useful commands

    25 changes: 25 additions & 0 deletions capture_gstreamer_raw.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/usr/bin/env sh
    # See https://www.linuxtv.org/wiki/index.php/V4L_capturing

    set -eu

    VIDEO_DEVICE=/dev/video0
    VIDEO_CAPABILITIES="video/x-raw, format=YUY2"

    AUDIO_DEVICE="hw:CARD=SAA7134,DEV=0"
    AUDIO_CAPABILITIES="audio/x-raw, channels=1" # My VHS player only has mono output

    TV_NORM="PAL"

    gst-launch-1.0 -q \
    v4l2src device="$VIDEO_DEVICE" do-timestamp=true norm="$TV_NORM" pixel-aspect-ratio=1 \
    ! $VIDEO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    alsasrc device="$AUDIO_DEVICE" do-timestamp=true \
    ! $AUDIO_CAPABILITIES \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! mux. \
    matroskamux name=mux \
    ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 \
    ! fdsink fd=1
  8. rudolfbyker revised this gist Nov 26, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@
    - https://www.linuxtv.org/downloads/v4l-dvb-apis/admin-guide/saa7134-cardlist.html?highlight=saa713
    - https://github.com/torvalds/linux/blob/master/drivers/media/pci/saa7134/saa7134-video.c
    - https://www.linuxtv.org/wiki/index.php/V4L_capturing
    - https://www.linuxtv.org/wiki/index.php/V4L_capturing/script

    ## APT packages to install on fresh Debian

  9. rudolfbyker revised this gist Nov 26, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@
    - https://tvtime.sourceforge.net/cards.html#saa7134
    - https://www.linuxtv.org/downloads/v4l-dvb-apis/admin-guide/saa7134-cardlist.html?highlight=saa713
    - https://github.com/torvalds/linux/blob/master/drivers/media/pci/saa7134/saa7134-video.c
    - https://www.linuxtv.org/wiki/index.php/V4L_capturing

    ## APT packages to install on fresh Debian

  10. rudolfbyker revised this gist Nov 26, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@
    - https://en.wikipedia.org/wiki/VHS
    - https://tvtime.sourceforge.net/cards.html#saa7134
    - https://www.linuxtv.org/downloads/v4l-dvb-apis/admin-guide/saa7134-cardlist.html?highlight=saa713
    - https://github.com/torvalds/linux/blob/master/drivers/media/pci/saa7134/saa7134-video.c

    ## APT packages to install on fresh Debian

  11. rudolfbyker revised this gist Nov 25, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@
    - https://en.wikipedia.org/wiki/List_of_common_resolutions#Analog_systems
    - https://en.wikipedia.org/wiki/VHS
    - https://tvtime.sourceforge.net/cards.html#saa7134
    - https://www.linuxtv.org/downloads/v4l-dvb-apis/admin-guide/saa7134-cardlist.html?highlight=saa713

    ## APT packages to install on fresh Debian

  12. rudolfbyker revised this gist Nov 25, 2023. 1 changed file with 62 additions and 14 deletions.
    76 changes: 62 additions & 14 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,11 @@
    ```
    alias char-major-81 videodev
    alias char-major-81-0 saa7134
    options saa7134 card=109
    ```
    - The card number (109 in this example) is one of these: https://www.linuxtv.org/downloads/v4l-dvb-apis/admin-guide/saa7134-cardlist.html?highlight=saa713 .
    - Mine is a Gigabyte card with a Philips chip, and it said something about a "tiger" on the box, so I guessed it must be "Philips Tiger - S Reference design" in that table, which is 109. It worked.
    - Experiment with different card numbers (rebooting in between changes) until `v4l2-ctl --list-inputs` gives you a sensible output.
    2. Reboot.

    ## Viewing details about the TV card
    @@ -44,7 +48,41 @@ lspci
    ### List Video4Linux devices

    ```shell
    `v4l2-ctl --list-formats-ext`
    v4l2-ctl --list-inputs
    ```

    ```
    ioctl: VIDIOC_ENUMINPUT
    Input : 0
    Name : Television
    Type : 0x00000001 (Tuner)
    Audioset : 0x00000000
    Tuner : 0x00000000
    Standard : 0x0000000000FFBFFF (PAL-B/B1/G/H/I/D/D1/K/M/N/Nc/60 NTSC-M/M-JP/M-KR SECAM-B/D/G/H/K/K1/L/Lc)
    Status : 0x00000102 (no signal, no hsync lock)
    Capabilities: 0x00000004 (SDTV standards)
    Input : 1
    Name : Composite1
    Type : 0x00000002 (Camera)
    Audioset : 0x00000000
    Tuner : 0x00000000
    Standard : 0x0000000000FFBFFF (PAL-B/B1/G/H/I/D/D1/K/M/N/Nc/60 NTSC-M/M-JP/M-KR SECAM-B/D/G/H/K/K1/L/Lc)
    Status : 0x00000000 (ok)
    Capabilities: 0x00000004 (SDTV standards)
    Input : 2
    Name : S-Video
    Type : 0x00000002 (Camera)
    Audioset : 0x00000000
    Tuner : 0x00000000
    Standard : 0x0000000000FFBFFF (PAL-B/B1/G/H/I/D/D1/K/M/N/Nc/60 NTSC-M/M-JP/M-KR SECAM-B/D/G/H/K/K1/L/Lc)
    Status : 0x00000000 (ok)
    Capabilities: 0x00000004 (SDTV standards)
    ```

    ```shell
    v4l2-ctl --list-formats-ext
    ```

    ```
    @@ -74,21 +112,23 @@ v4l2-ctl --all
    ```
    Driver Info:
    Driver name : saa7134
    Card type : UNKNOWN/GENERIC
    Card type : Philips Tiger - S Reference des
    Bus info : PCI:0000:03:01.0
    Driver version : 6.1.55
    Capabilities : 0x85240015
    Capabilities : 0x85250015
    Video Capture
    Video Overlay
    VBI Capture
    Tuner
    Radio
    Read/Write
    Streaming
    Extended Pix Format
    Device Capabilities
    Device Caps : 0x05200005
    Device Caps : 0x05210005
    Video Capture
    Video Overlay
    Tuner
    Read/Write
    Streaming
    Extended Pix Format
    @@ -101,29 +141,37 @@ Media Driver Info:
    Hardware revision: 0x14589003 (341348355)
    Driver version : 6.1.55
    Interface Info:
    ID : 0x03000002
    ID : 0x03000006
    Type : V4L Video
    Entity Info:
    ID : 0x00000001 (1)
    Name : saa7133[0] video (UNKNOWN/GENER
    ID : 0x00000005 (5)
    Name : saa7133[0] video (Philips Tiger
    Function : V4L2 I/O
    Pad 0x0100000a : 0: Sink
    Link 0x0200000e: from remote pad 0x1000009 of entity 'saa713x' (Analog Video Decoder): Data, Enabled
    Pad 0x0100000f : 0: Sink
    Link 0x0200001b: from remote pad 0x100000e of entity 'saa713x' (Analog Video Decoder): Data, Enabled
    Priority: 2
    Frequency for tuner 0: 0 (0.000000 MHz)
    Video input : 0 (Composite: no signal, no hsync lock)
    Tuner 0:
    Name : Television
    Type : Analog TV
    Capabilities : 62.5 kHz multi-standard stereo lang1 lang2 freq-bands
    Frequency range : 44.000 MHz - 958.000 MHz
    Signal strength/AFC : 0%/0
    Current audio mode : mono
    Available subchannels: mono
    Video input : 0 (Television: no signal, no hsync lock)
    Video Standard = 0x000000ff
    PAL-B/B1/G/H/I/D/D1/K
    Format Video Capture:
    Width/Height : 720/576
    Pixel Format : 'YU12' (Planar YUV 4:2:0)
    Pixel Format : 'BGR3' (24-bit BGR 8-8-8)
    Field : Interlaced
    Bytes per Line : 720
    Size Image : 622080
    Bytes per Line : 2160
    Size Image : 1244160
    Colorspace : SMPTE 170M
    Transfer Function : Default (maps to Rec. 709)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization : Default (maps to Limited Range)
    Quantization : Default (maps to Full Range)
    Flags :
    Format Video Overlay:
    Left/Top : 0/0
  13. rudolfbyker revised this gist Nov 11, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    - https://en.wikipedia.org/wiki/Pixel_aspect_ratio
    - https://en.wikipedia.org/wiki/List_of_common_resolutions#Analog_systems
    - https://en.wikipedia.org/wiki/VHS
    -
    - https://tvtime.sourceforge.net/cards.html#saa7134

    ## APT packages to install on fresh Debian

  14. rudolfbyker revised this gist Nov 10, 2023. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -254,3 +254,11 @@ ffmpeg -i /dev/video0 -f alsa -i hw:1 -c copy -t 10 /home/dolf/videos/tmp.mkv
    ```shell
    tail -f tmp.mkv | ffmpeg -i - -f mpegts - | mpv -
    ```

    ### Watch the stream from the TV card directly in the terminal

    Use `mpv` for playback. Use `ffmpeg` to transcode into a format that `mpv` understands. Because we use `mpv`, this even works without installing a desktop environment.

    ```shell
    ffmpeg -i /dev/video0 -f alsa -i hw:1 -c:v libx264 -preset fast -c:a aac -f mpegts - | mpv -
    ```
  15. rudolfbyker created this gist Nov 4, 2023.
    256 changes: 256 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,256 @@
    # Using SAA713x TV Card on Debian

    ## Useful links

    - https://askubuntu.com/questions/348838/how-to-check-available-webcams-from-the-command-line
    - https://www.linuxtv.org/wiki/index.php/Saa7134-alsa
    - https://www.linuxtv.org/wiki/index.php/Philips_SAA7134
    - https://www.linuxtv.org/wiki/index.php/Saa713x_devices
    - https://www.linuxtv.org/wiki/index.php/Saa713x_devices:_Generic_SAA7134_Card_Installation
    - https://trac.ffmpeg.org/wiki/Capture/ALSA
    - https://video.stackexchange.com/questions/33387/vhs-and-capture-what-is-the-real-aspect-ratio
    - https://en.wikipedia.org/wiki/Pixel_aspect_ratio
    - https://en.wikipedia.org/wiki/List_of_common_resolutions#Analog_systems
    - https://en.wikipedia.org/wiki/VHS
    -

    ## APT packages to install on fresh Debian

    - ffmpeg
    - alsa-utils
    - v4l-utils

    ## Setting up the driver

    1. Create a file at `/etc/modprobe.d/saa7134.conf` with the following contents:
    ```
    alias char-major-81 videodev
    alias char-major-81-0 saa7134
    ```
    2. Reboot.

    ## Viewing details about the TV card

    ### List PCI devices

    ```shell
    lspci
    ```

    ```
    03:01.0 Multimedia controller: Philips Semiconductors SAA7131/SAA7133/SAA7135 Video Broadcast Decoder (rev d1)
    ```

    ### List Video4Linux devices

    ```shell
    `v4l2-ctl --list-formats-ext`
    ```

    ```
    ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture
    [0]: 'GREY' (8-bit Greyscale)
    [1]: 'RGBO' (16-bit A/XRGB 1-5-5-5)
    [2]: 'RGBQ' (16-bit A/XRGB 1-5-5-5 BE)
    [3]: 'RGBP' (16-bit RGB 5-6-5)
    [4]: 'RGBR' (16-bit RGB 5-6-5 BE)
    [5]: 'BGR3' (24-bit BGR 8-8-8)
    [6]: 'RGB3' (24-bit RGB 8-8-8)
    [7]: 'BGR4' (32-bit BGRA/X 8-8-8-8)
    [8]: 'RGB4' (32-bit A/XRGB 8-8-8-8)
    [9]: 'YUYV' (YUYV 4:2:2)
    [10]: 'UYVY' (UYVY 4:2:2)
    [11]: '422P' (Planar YUV 4:2:2)
    [12]: 'YU12' (Planar YUV 4:2:0)
    [13]: 'YV12' (Planar YVU 4:2:0)
    ```

    ```shell
    v4l2-ctl --all
    ```

    ```
    Driver Info:
    Driver name : saa7134
    Card type : UNKNOWN/GENERIC
    Bus info : PCI:0000:03:01.0
    Driver version : 6.1.55
    Capabilities : 0x85240015
    Video Capture
    Video Overlay
    VBI Capture
    Radio
    Read/Write
    Streaming
    Extended Pix Format
    Device Capabilities
    Device Caps : 0x05200005
    Video Capture
    Video Overlay
    Read/Write
    Streaming
    Extended Pix Format
    Media Driver Info:
    Driver name : saa7134
    Model : saa7133[0]
    Serial :
    Bus info : PCI:0000:03:01.0
    Media version : 6.1.55
    Hardware revision: 0x14589003 (341348355)
    Driver version : 6.1.55
    Interface Info:
    ID : 0x03000002
    Type : V4L Video
    Entity Info:
    ID : 0x00000001 (1)
    Name : saa7133[0] video (UNKNOWN/GENER
    Function : V4L2 I/O
    Pad 0x0100000a : 0: Sink
    Link 0x0200000e: from remote pad 0x1000009 of entity 'saa713x' (Analog Video Decoder): Data, Enabled
    Priority: 2
    Frequency for tuner 0: 0 (0.000000 MHz)
    Video input : 0 (Composite: no signal, no hsync lock)
    Video Standard = 0x000000ff
    PAL-B/B1/G/H/I/D/D1/K
    Format Video Capture:
    Width/Height : 720/576
    Pixel Format : 'YU12' (Planar YUV 4:2:0)
    Field : Interlaced
    Bytes per Line : 720
    Size Image : 622080
    Colorspace : SMPTE 170M
    Transfer Function : Default (maps to Rec. 709)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization : Default (maps to Limited Range)
    Flags :
    Format Video Overlay:
    Left/Top : 0/0
    Width/Height: 720/576
    Field : Interlaced
    Chroma Key : 0x00000000
    Global Alpha: 0x00
    Clip Count : 0
    Clip Bitmap : No
    Framebuffer Format:
    Capability : Clipping List
    Flags :
    Width : 720
    Height : 576
    Pixel Format : 'BGR3'
    Bytes per Line: 0
    Size image : 0
    Colorspace : SMPTE 170M
    Crop Capability Video Capture:
    Bounds : Left 0, Top 48, Width 720, Height 576
    Default : Left 0, Top 48, Width 720, Height 576
    Pixel Aspect: 54/59
    Selection Video Capture: crop, Left 0, Top 48, Width 720, Height 576, Flags:
    Selection Video Capture: crop_default, Left 0, Top 48, Width 720, Height 576, Flags:
    Selection Video Capture: crop_bounds, Left 0, Top 48, Width 720, Height 576, Flags:
    Streaming Parameters Video Capture:
    Frames per second: 25.000 (25/1)
    Read buffers : 2
    User Controls
    brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128 flags=slider
    contrast 0x00980901 (int) : min=0 max=127 step=1 default=68 value=68 flags=slider
    saturation 0x00980902 (int) : min=0 max=127 step=1 default=64 value=64 flags=slider
    hue 0x00980903 (int) : min=-128 max=127 step=1 default=0 value=0 flags=slider
    volume 0x00980905 (int) : min=-15 max=15 step=1 default=0 value=0 flags=slider
    mute 0x00980909 (bool) : default=0 value=0
    horizontal_flip 0x00980914 (bool) : default=0 value=0
    invert 0x00981960 (bool) : default=0 value=0
    y_offset_odd_field 0x00981961 (int) : min=0 max=128 step=1 default=0 value=0
    y_offset_even_field 0x00981962 (int) : min=0 max=128 step=1 default=0 value=0
    automute 0x00981963 (bool) : default=1 value=1
    ```

    ### List ALSA recording devices

    ```shell
    arecord -l
    ```

    ```
    card 1: SAA7134 [SAA7134], device 0: SAA7134 PCM [SAA7134 PCM]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    ```

    ### Probe with ffmpeg and ffprobe

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

    ```
    [video4linux2,v4l2 @ 0x1554e80] Raw : gray : 8-bit Greyscale :
    [video4linux2,v4l2 @ 0x1554e80] Raw : rgb555le : 16-bit A/XRGB 1-5-5-5 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : rgb555be : 16-bit A/XRGB 1-5-5-5 BE :
    [video4linux2,v4l2 @ 0x1554e80] Raw : rgb565le : 16-bit RGB 5-6-5 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : rgb565be : 16-bit RGB 5-6-5 BE :
    [video4linux2,v4l2 @ 0x1554e80] Raw : bgr24 : 24-bit BGR 8-8-8 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : rgb24 : 24-bit RGB 8-8-8 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : bgr0 : 32-bit BGRA/X 8-8-8-8 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : 0rgb : 32-bit A/XRGB 8-8-8-8 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : yuyv422 : YUYV 4:2:2 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : uyvy422 : UYVY 4:2:2 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : yuv422p : Planar YUV 4:2:2 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : yuv420p : Planar YUV 4:2:0 :
    [video4linux2,v4l2 @ 0x1554e80] Raw : yuv420p : Planar YVU 4:2:0 :
    ```

    ```shell
    ffprobe /dev/video0
    ```

    Intersting: This is the only one showing the resolution!

    ```
    Input #0, video4linux2,v4l2, from '/dev/video0':
    Duration: N/A, start: 2546.446776, bitrate: 124416 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x576, 124416 kb/s, 25 fps, 25 tbr, 1000k tbn
    ```

    ```shell
    ffprobe -f alsa hw:1
    ```

    Note the `hw:N` here. This is what we will use for `ffmpeg`'s `-i` option.

    ```
    Input #0, alsa, from 'hw:1':
    Duration: N/A, start: 1699123043.658554, bitrate: 1024 kb/s
    Stream #0:0: Audio: pcm_s16le, 32000 Hz, 2 channels, s16, 1024 kb/s
    ```

    ## Capturing

    ### Video only

    ```shell
    ffmpeg -i /dev/video0 -c copy out.mkv
    ```

    ### Audio only

    ```shell
    ffmpeg -f alsa -i hw:1 -c copy out.wav
    ```

    ### Video and audio

    ```shell
    ffmpeg -i /dev/video0 -f alsa -i hw:1 -c copy -t 10 /home/dolf/videos/tmp.mkv
    ```

    ## Other useful commands

    ### Watch a video file from the beginning even though it's still being written to

    ```shell
    tail -f tmp.mkv | ffmpeg -i - -f mpegts - | mpv -
    ```