0

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...

J.M.
  • 472
  • 1
  • 6
  • 15

2 Answers2

0

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.

Mike Versteeg
  • 1,615
  • 14
  • 28
  • For v4l2, framerate is passed back to the capture driver. FFmpeg on its part will not drop or dupe frames. – Gyan Dec 10 '19 at 05:40
  • The reason I'm using -framerate and not -r, is because I'm trying to use the -copyts option, and it works only with -framerate. However, when I'm using -r and -copyts, it somehow ignores the -copyts option. So, is it ok I'm using the -framerate option ? – J.M. Dec 11 '19 at 13:37
0

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.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • I think your last explanation also valid for the -r option, but I'm not exactly understand what is the difference between the two, and why the -framerate option causes me problems after a few hours. – J.M. Dec 11 '19 at 13:47
  • @JosephMatan What are the errors? What version of ffmpeg are you using? – llogan Dec 11 '19 at 18:08
  • That the weird thing... No errors. The frame counter just stops counting, and FPS decrease to 0.0. (I'm using the latest FFmpeg from master) – J.M. Dec 14 '19 at 18:10
  • @JosephMatan Need a process of elimination. The network output may be having an issue. Does outputting to a local, normal file work as expected? If yes, then it problem is likely not the v4l2 input but the UDP output. – llogan Dec 15 '19 at 20:42