|
| 1 | +=== libav integration with libcamera-vid |
| 2 | + |
| 3 | +`libcamera-vid` can use the ffmpeg/libav codec backend to encode audio and video streams and either save to a local file or stream over the network. At present, video is encoded through the hardware H.264 encoder, and audio is encoded by a number of available software encoders. To list the available output formats, use the `ffmpeg -formats` command. |
| 4 | + |
| 5 | +To enable the libav backend, use the `--codec libav` command line option. Once enabled, the following configuration options are available: |
| 6 | + |
| 7 | +---- |
| 8 | + --libav-format, libav output format to be used <string> |
| 9 | +---- |
| 10 | + |
| 11 | +Set the libav output format to use. These output formats can be specified as containers (e.g. mkv, mp4, avi) or stream output (e.g. h264 or mpegts). If this option is not provided, libav tries to deduce the output format from the filename specified by the `-o` command line argument. |
| 12 | + |
| 13 | +Example: To save a video in an mkv container, the following commands are equivalent: |
| 14 | + |
| 15 | +---- |
| 16 | +libcamera-vid --codec libav -o test.mkv |
| 17 | +libcamera-vid --codec libav --libav-format mkv -o test.raw |
| 18 | +---- |
| 19 | + |
| 20 | +---- |
| 21 | + --libav-audio, Enable audio recording |
| 22 | +---- |
| 23 | + |
| 24 | +Set this option to enable audio encoding together with the video stream. When audio encodding is enabled, an output format that supports audio (e.g. mpegts, mkv, mp4) must be used. |
| 25 | + |
| 26 | +---- |
| 27 | + --audio-codec, Selects the audio codec <string> |
| 28 | +---- |
| 29 | + |
| 30 | +Selects which software audio codec is used for encoding. By default `aac` is used. To list the available audio codecs, use the ``ffmpeg -codec`` command. |
| 31 | + |
| 32 | +---- |
| 33 | + --audio-bitrate, Selects the audio bitrate <number> |
| 34 | +---- |
| 35 | + |
| 36 | +Sets the audio encoding bitrate in bits per second. |
| 37 | + |
| 38 | +Example: To record audio at 16 kilobits/sec with the mp2 codec use `libcamera-vid --codec libav -o test.mp4 --audio_codec mp2 --audio-bitrate 16384` |
| 39 | + |
| 40 | +---- |
| 41 | + --audio-device, Chooses and audio recording device to use <string> |
| 42 | +---- |
| 43 | + |
| 44 | +Selects which ALSA input device to use for audio encoding. The audio device string can be obtained by the following command: |
| 45 | + |
| 46 | +---- |
| 47 | +pi@pi4:~ $ pactl list | grep -A2 'Source #' | grep 'Name: ' |
| 48 | + Name: alsa_output.platform-bcm2835_audio.analog-stereo.monitor |
| 49 | + Name: alsa_output.platform-fef00700.hdmi.hdmi-stereo.monitor |
| 50 | + Name: alsa_output.usb-GN_Netcom_A_S_Jabra_EVOLVE_LINK_000736B1214E0A-00.analog-stereo.monitor |
| 51 | + Name: alsa_input.usb-GN_Netcom_A_S_Jabra_EVOLVE_LINK_000736B1214E0A-00.mono-fallback |
| 52 | +---- |
| 53 | + |
| 54 | +---- |
| 55 | + --av-sync, Audio/Video sync control <number> |
| 56 | +---- |
| 57 | +This option can be used to shift the audio sample timestamp by a value given in microseconds relative to the video frame. Negative values may also be used. |
| 58 | + |
| 59 | +==== Network streaming with libav |
| 60 | + |
| 61 | +It is possible to use the libav backend as a network streaming source for audio/video. To do this, the output filename specified by the `-o` argument must be given as a protocol url, see https://ffmpeg.org/ffmpeg-protocols.html[ffmpeg protocols] for more details on protocol usage. Some examples: |
| 62 | + |
| 63 | +To stream audio/video using TCP |
| 64 | +---- |
| 65 | +libcamera-vid -t 0 --codec libav --libav-format mpegts --libav-audio -o "tcp://0.0.0.0:1234?listen=1" |
| 66 | +---- |
| 67 | + |
| 68 | +To stream audio/video using UDP |
| 69 | +---- |
| 70 | +libcamera-vid -t 0 --codec libav --libav-format mpegts --libav-audio -o "udp://<ip-addr>:<port>" |
| 71 | +---- |
0 commit comments