basler / gst-plugin-pylon

The official GStreamer plug-in for Basler cameras
BSD 3-Clause "New" or "Revised" License
40 stars 10 forks source link

gst-launch-1.0 pylonsrc cam::TriggerSource-FrameStart=Line1 cam::TriggerMode-FrameStart=On #62

Closed lynnqiulin closed 1 year ago

lynnqiulin commented 1 year ago

When I use this command to specify trigger source as hardware trigger from Line3, the pipeline can be controlled to start playing by Line3 signal, however the frame rate won't change according to hardware trigger signal frequency. Could developer confirm whether frame rate can change according to hardware trigger signal from GPIO or not?

lynnqiulin commented 1 year ago

Right now I am using Basler acA1440-220um for animal motion capture. The platform is Linux ARM Ubuntu 20.04 using Rockchip RK3588, setting up the gstreamer pipepline for video encoder and capture. When I use the gstreamer plugin of pylonsrc, I met a problem.

gst-launch-1.0 pylonsrc cam::TriggerSource-FrameStart=Line3 cam::TriggerMode-FrameStart=On ! videoconvert ! mpph265enc ! h265parse ! matroskamux ! filesink location=test_20.mp4 --gst-debug-level=6 2>&1 | tee test20fps.log

Adding more inforamtion. I found the number is fixed in ext/pylon/gstpylonsrc.cpp:614

static const gint preferred_framerate_num = 30;

I changed it to 120fps and recompile, then the result frame rate will change to 120fps, no matter waht the hardware trigger signal frequency is what.

From the gstreamer log below, it shows that TriggerMode and TriggerSource have been set, however after that somewhere in the code still set the AcquisitionFrameRate to 120, rather than to use the triggersource.

34085 0:00:03.143778329 23462 0x5591e9d600 DEBUG GST_PIPELINE parse.l:181:priv_gst_parse_yylex: flex: SPACE: [ ] 34086 0:00:03.143785912 23462 0x5591e9d600 DEBUG GST_PIPELINE parse.l:93:priv_gst_parse_yylex: flex: ASSIGNMENT: cam::TriggerSource-FrameStart=Line3

34128 0:00:03.911054282 23462 0x5591e9d600 LOG GST_PIPELINE gst/parse/grammar.y:423:gst_parse_element_set: parsing property TriggerSource-FrameStart as a _2676_ba02_8_1_3_Trigge rSource 34129 0:00:03.912106885 23462 0x5591e9d600 INFO pylonsrc gstpylonobject.cpp:291:gst_pylon_object_set_pylon_selector: Set Selector-Feature TriggerSelector: FrameStart 34130 0:00:03.924182798 23462 0x5591e9d600 INFO pylonsrc gstpylonobject.cpp:252:gst_pylon_object_set_pylon_feature<int ()(const _GValue), Pylon::CEnumParameter>: Set Feature TriggerSource: Line3

34146 0:00:03.925134779 23462 0x5591e9d600 DEBUG GST_PIPELINE parse.l:181:priv_gst_parse_yylex: flex: SPACE: [ ] 34147 0:00:03.925207694 23462 0x5591e9d600 DEBUG GST_PIPELINE parse.l:93:priv_gst_parse_yylex: flex: ASSIGNMENT: cam::TriggerMode-FrameStart=On

34179 0:00:03.926869284 23462 0x5591e9d600 DEBUG default types.h:84:gst_parse_unescape: unescaping On 34180 0:00:03.926953865 23462 0x5591e9d600 DEBUG pylonsrc gstpylonsrc.cpp:1023:gst_pylon_src_child_proxy_get_child_by_name: Looking for child "cam" 34181 0:00:03.927040489 23462 0x5591e9d600 LOG GST_PIPELINE gst/parse/grammar.y:423:gst_parse_element_set: parsing property TriggerMode-FrameStart as a _2676_ba02_8_1_3_TriggerM ode 34182 0:00:03.928063925 23462 0x5591e9d600 INFO pylonsrc gstpylonobject.cpp:291:gst_pylon_object_set_pylon_selector: Set Selector-Feature TriggerSelector: FrameStart 34183 0:00:03.929238151 23462 0x5591e9d600 INFO pylonsrc gstpylonobject.cpp:252:gst_pylon_object_set_pylon_feature<int ()(const _GValue), Pylon::CEnumParameter>: Set Feature TriggerMode: On

37467 0:00:04.211779351 23462 0x55921beb00 INFO pylonsrc gstpylon.cpp:860:gst_pylon_set_configuration: Set Feature Width: 1440 37468 0:00:04.212763997 23462 0x55921beb00 INFO pylonsrc gstpylon.cpp:864:gst_pylon_set_configuration: Set Feature Height: 1080 37469 0:00:04.214015804 23462 0x55921beb00 INFO pylonsrc gstpylon.cpp:935:gst_pylon_set_configuration: Set Feature AcquisitionFrameRate: 120.000000

thiesmoeller commented 1 year ago

Hi @lynnqiulin,

to set the framerate, you don't have to recompile. Framerate is part of normal gstreamer caps negotiation process. See e.g. https://github.com/basler/gst-plugin-pylon/blob/2fba87f9b329d90adc70e4cac4c6e075a37d2027/README.md?plain=1#L88

The position in the code is the fallback for the case that no framerate is given. ( neither as capsfilter nor by one of the downstream sinks)

--

Gstreamer normally assumes a fixed framerate video stream. In your case of changing the fps by changing the trigger frequency will work, but downstream plugins might 'complain' about framerate issues.

In your setup with a triggered camera, you should set a framerate, that is above your trigger frequency. As the framerate you give will be the maximum framerate the camera can handle.

lynnqiulin commented 1 year ago

Hi @thiesmoeller Thank you for the help.

In my user case, I will first start gstreamer and initial camera with setting saved in user-set, set the camera to hardware trigger, waiting for outside signal to start hardware trigger. So the gstreamer will first start with a framerate but at that time pineline is not set to PLAYING. After that there will be hardware trigger signal. Will this confuse the downstream plugins, or will the downstream plugin's framerate been set to some freqency like 30Hz as 'no framerate is given' and then won't change?

I follow the guide to set framerate on command line as 60Hz which is higher than hardware trigger setting to rate less than 60Hz. However the output file frame rate is still 60Hz. Is there anything not correct with my command or flow?

  1. Case 1: a. command line: gst-launch-1.0 pylonsrc ! "video/x-raw,framerate=60/1" ! videoconvert ! mpph265enc ! h265parse ! matroskamux ! filesink location=FR40TR20.mp4 b. start pwm signal of 20Hz/30Hz/40Hz... c. result frame rate of mp4 file is 60Hz.
  2. Case 2: a. command line: gst-launch-1.0 pylonsrc ! videoconvert ! mpph265enc ! h265parse ! matroskamux ! filesink location=FRNATR20.mp4 b. start pwm signal of 20Hz/25Hz/... c. result frame rate of mp4 file is 30Hz (guess due to setting in ext/pylon/gstpylonsrc.cpp:614 static const gint preferred_framerate_num = 30;)
lynnqiulin commented 1 year ago

I set the frame rate same as trigger frequency, now result frame rate of output file matches. Thank you.