As far as I know, the use of the Framerate option should be used only on an input files (like sequence of images or perhaps a video file that don't have a defined PTS).

However, if I run the command below on my web-cam, the video still streams fine (at least for a few hours from what I've checked till now). Why is that still works? Should I expect that something will get wrong? (maybe later, after a few hours or days of streaming)

ffmpeg -framerate 30 -f v4l2 -copyts -i /dev/video0 -c:v libx264 -r 30 -f mpegts udp://192.168.10.199:1234

EDIT:

After running some more tests, it seems that when I'm running the command like this, the steam get stuck after a few hours:

ffmpeg -framerate 30 -f v4l2 -copyts -i /dev/video0 -c:v libx264 -r 30 -f mpegts udp://192.168.10.199:1234

However, if I run the command like this, it runs for days:

ffmpeg -r 30 -f v4l2 -copyts -i /dev/video0 -c:v libx264 -r 30 -f mpegts udp://192.168.10.199:1234

But I don't understand why...

2

There are 2 best solutions below

2
Mike Versteeg On

The framerate option causes your camera stream to be resampled at a fixed sample rate (here 30 fps). This will inevitably results in doubled and/or missed frames, or even judder. Do not use this option here.

4
llogan On

Some cameras support multiple frame rates and -framerate allows you to choose which frame rate you want. You can list such info with v4l2-ctl:

$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'YUYV' (YUYV 4:2:2)
            Size: Discrete 640x480
                    Interval: Discrete 0.033s (30.000 fps)
                    Interval: Discrete 0.067s (15.000 fps)
                    Interval: Discrete 0.100s (10.000 fps)
                    Interval: Discrete 0.200s (5.000 fps)
            Size: Discrete 352x288
                    Interval: Discrete 0.033s (30.000 fps)
                    Interval: Discrete 0.067s (15.000 fps)
                    Interval: Discrete 0.100s (10.000 fps)
                    Interval: Discrete 0.200s (5.000 fps)

If you choose an invalid frame rate then you'll get a message:

[video4linux2,v4l2 @ 0x556d45e42180] The driver changed the time per frame from 1/12 to 1/10

So the worst that can happen (when using 4vl2 at least) is that your camera simply uses a different, but still supported frame rate.

See the FFmpeg v4l2 input device documentation for more info and additional options.

Be warned that framerate value can change in time because of exposure.