agarciadom / ipwebcam-gst

Simple shell script for using IP Webcam as a V4L2 webcam / sound source
http://xmleye.wordpress.com
621 stars 155 forks source link

feat: add fps option and a default #122

Closed vit-zikmund closed 1 year ago

vit-zikmund commented 1 year ago

In a successful attempt to make this work for Fedora 37 (details), I had to enforce a sensible framerate in order for the negotiation with v4l2sink to work, so why not make it a parameter, too!

Thanks for all the inspiration @agarciadom ;)

agarciadom commented 1 year ago

Thanks for looking into this! Wouldn't you need to declare the new -F / --fps option in the getopt call? I'd assume you'd need something like:

OPTS=`getopt -o ab:Cd:f:F:h:l:i:p:P:stu:vw:x --long audio,adb-path:,no-echo-cancel,device:,flip:,fps:,height:,help,adb-flags:,use-wifi:,port:,password:,no-sync,with-tee,username:,video,width:,no-proxy -n "$0" -- "$@"`
agarciadom commented 1 year ago

I've tried adding the option to getopt, but I don't have time to test the script at the moment. Could you give it a try, with something like -F 20 or --fps 20, for instance?

vit-zikmund commented 1 year ago

Sure thing. I'll try it tomorrow. And thanks for the catch :)

vit-zikmund commented 1 year ago

OK, added a couple checks.

The gst pipeline was pretty picky about the fps format that needs to be fractional. That's silly, so I added a logic that adds /1 to the end of the supplied number. I've also added an error for the case it's not a number and a warning in case the fraction is below 1/1 (e.g. 1/2 for one frame every 2 seconds, which is normally a valid option, but v4l2sink (at least in my case) thinks otherwise).

Regarding the fps adoption, the v4l2loopback driver seems to ignore it (and use 30/1):

$ ./v4l2loopback-ctl get-caps /dev/video4
YUYV:640x480@30/1
#        FPS ^^^^

But the gst pipeline framerate works accordingly, and setting fps to 1/1 does create a 1FPS choppy video.

agarciadom commented 1 year ago

This looks ready to merge now. Time to merge it - thank you for your contribution!

vit-zikmund commented 1 year ago

Thank you for this project! :smile: