[vlc-devel] (no subject)

Jérémy VIGNELLES jeremy.vignelles at dev3i.fr
Thu Oct 12 11:17:00 CEST 2017

Use case

I need a way to record permanently a CCTV camera in a rolling buffer of,
say, 1 day. As far as I know, this is not possible currently with VLC.

I have seen the ticket #561, opened 12 years ago, which asks
for a similar feature.

A "cycle" stream output plugin has been implemented, but it works in a
different way : predefine a loop of files and write in them alternatively.

My implementation differs from the "cycle" module in the way that nothing
is overwritten, and it's up to an external hypervisor to retain or remove
files as needed.

How does it work
MPEG-TS is a muxing format in which blocks are normally 188 bytes long
(VLC can do "unaligned" blocks). Starting a file from any of the blocks
gives a valid MPEG-TS stream.

Based on that statement, the idea is to fill a file with blocks, until a
limit is reached, and then switch between files between two blocks.

MPEG-TS also has an option to specify a key, so that the stream can be
encrypted, which is useful when working on sensitive stream, like in CCTV

Configuration parameters
`dst=` in the sout chain specifies the directory to which files are written.

The file name can be formatted using the
`--sout-segments-format` specifier, which takes strftime format as argument

`--sout-segments-max-filesize` limits the file size before
which we need to switch files. Defaults to 94MB, which is a round number
of 188-bytes blocks.

Example usage
vlc -vv --sout="#std{access=segments,mux=ts,dst=/path/to/recording/folder}" \
--sout-segments-format "%Y%m%d%H%M%S.ts" --sout-max-filesize 1880000 \
--sout-ts-crypt-audio --sout-ts-crypt-video --sout-ts-csa-ck 0123456789ABCDEF \

Example replaying
cat /path/to/recording/folder/*.ts | vlc --ts-csa-ck 0123456789ABCDEF -

Or you can just play one by one.


- The file format can only be precise in seconds, due to the way strftime
works. If the max-filesize represents less than 1 second of video, there
is a risk that two files have the same name, and thus, the second
will be overwriting the first one
- Obviously, it does only work with MPEG-TS stream and was optimized for that 
muxer. There is no check that the stream is actually muxed with MPEG-TS.
- There is no guarantee that the first block in a file contains a I-frame.
When replaying, there can be a latency before anything is shown on the screen.

Please send me your (kind) remarks about this code, about my usage example
("You could have done this that way!")...


More information about the vlc-devel mailing list