Changes between Version 18 and Version 19 of linux/media

01/05/2021 11:59:59 PM (19 months ago)
Tim Harvey

added section about analog video capture sync


  • linux/media

    v18 v19  
    272 === Setup Script
     272=== Media Controller Setup Script
    273273Because the combinations of sensor, cpu, and board are plentiful we have created a way to create an appropriate pipeline configuration script that needs only to know what sensor you wish to use.
     275By default the script will create a pipeline customized for the particular sensor you are targeting (adv7180 for analog video decoder or tda1997x for HDMI decoder). However you can use the MODE env variable to alter the pipeline mode (see examples below).
    275277** Installation:
    277278The following scripts require GStreamer to be installed, see [wiki:/linux/media#GStreamerCaptureDispalyandStreamExamples here] for instructions. 
    279 Script download:
     280The {{{media-ctl-setup}}} script is already installed on the Gateworks Ubuntu images however if you need to install it manually you can download it from the git repositoroy:
    286 Examples:
    287  * Analog CVBS NTSC capture
     286** Examples:
     287 * Analog Video Decoder:
     288  - CVBS NTSC raw capture:
     290v4l2-ctl --device /dev/v4l-subdev14 --set-standard NTSC
     291MODE=0 ./media-ctl-setup adv7180 > setup
     292source ./setup
     294  - CVBS NTSC hardware de-interlaced capture:
    289296v4l2-ctl --device /dev/v4l-subdev14 --set-standard NTSC
    291298source ./setup
    293  * Analog CVBS PAL capture
     300  - CVBS PAL hardware de-interlaced capture
    295302v4l2-ctl --device /dev/v4l-subdev14 --set-standard PAL
    311318To detect when the input changes on a capture source you can catch the {{{V4L2_EVENT_SOURCE_CHANGE}}} event via the {{{VIDIOC_DQEVENT}}} ioctl - see
     322== Analog Video Capture Sync and determining loss of signal/sync
     323A common issue when capturing analog video via the adv7180 sensor is that the Video does not synchronize properly if the signal is lost and re-acquired. This is because the nature of the adv7180 (and most analog video decoders) is that they start presenting decoded video pixel data before they see a vertical sync indicating the start of a frame. This will confuse the IMX6 capture and cause an image that either continually rolls vertically or appears split horizontally.
     325On stream startup the IMX6 capture driver will throw away the first few frames in order to avoid this problem via a [ patch in the Gateworks kernel].
     327However, if this issue is occurring because your analog video signal is intermittent you must detect the loss of sync and restart capture.
     329This issue appears to be more prevalent if you are using the IMX6 hardware de-interlacer. If you want to try capturing interlaced video to avoid this you can capture 1 field of the video (half height) and resize it to full height as follows:
     331# setup pipeline using MODE0 (raw)
     332MODE=0 media-ctl-setup adv7180 > adv7180_raw
     333. ./adv7180_raw
     334# launch gstreamer
     335gst-launch-1.0 v4l2src device=$DEVICE ! $GST_CONVERT ! video/x-raw,width=640,height=480 ! kmssink can-scale=false
     338If you are wanting to use the hardware de-interlacer you can detect the loss of sync in two possible ways using v4l2 event notifiers (available in 5.4+ kernel):
     339 1. via the adv7180 V4L2_EVENT_SOURCE_CHANGE event is supposed to fire when a source changes status
     340 2. via the imx6 capture driver 'Frame Interval Monitor' which works by using math to determine if it thinks frames are coming in at an inappropriate interval
     342The way you would use these notifiers is to use the VIDIOC_SUBSCRIBE_EVENT ioctl in an application to subscribe to the specific event you want. If you are using gst-launch to create a simple pipeline from userspace you can use the v4l2-ctl wait-for-event, poll-for-event, or --epoll-for-event parameters to wait for or check for an event meaning you would launch the pipeline in the background, wait for an event, then kill and restart the pipeline. I'll give you examples of using gst-launch.
     344For example to catch the V4L2_EVENT_SOURCE_CHANGE from the adv7180 via shell:
     346# setup pipeline
     347media-ctl-setup adv7180 > adv7180_deinterlace
     348. ./adv7180_deinterlace
     349# launch gstreamer in background
     350gst-launch-1.0 v4l2src device=$DEVICE ! $GST_CONVERT ! kmssink &
     351# wait for a V4L2_EVENT_SOURCE_CHANGE event (id=1)
     352v4l2-ctl --device=$DEVICE --wait-for-event=5
     353# now you can kill and restart gstreamer
     356The downside of this is that I the adv7180 does not consistently give you interrupts on signal loss and detection from our experience.
     358The other method is to use the IMX6 capture 'Frame Interval Monitor'. The downside to this is that it can take a bit of tuning and that it only is available on the ipu_csi capture device meaning you can't use the de-interlacer and will get only the even or odd lines (half height)
     360To use the FIM method you would do something like the following steps:
     362# setup pipeline
     363media-ctl-setup adv7180 > adv7180_deinterlace
     364. ./adv7180_deinterlace
     365# enable frame interval monitor
     366v4l2-ctl --device $DEVICE --set-ctrl=fim_enable=1
     367# you may need to adjust fim_num_average/fim_tolerance_min/fim_tolerance_max/fim_num_skip to your liking
     368# launch gstreamer in background
     369gst-launch-1.0 v4l2src device=$DEVICE ! $GST_CONVERT ! kmssink &
     370# wait for a V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR event (id=0x08000001)
     371v4l2-ctl --device=$DEVICE --wait-for-event=0x08000001
     372# now you can kill and restart gstreamer