VisioForge

C# Barcode Scanner for .NET from Live Video

Read QR codes and 1D barcodes in C# from a webcam, an IP camera, the screen or a video file. The barcode detector is a block in a .NET video pipeline, so you can scan the same video you preview, record or stream, on Windows, macOS, Linux, Android and iOS.

A barcode scanner for video, not for scanned documents

Media Blocks SDK .NET and Video Capture SDK .NET read barcodes and QR codes from live video: webcams, IP cameras over RTSP or ONVIF, screen capture and video files. The detector runs inside the video pipeline and raises an event with the barcode type and value whenever it decodes a code in a frame. It is made for applications that already work with video, such as entrance and ticket checks, warehouse and production-line cameras or kiosks. If your input is still images, PDFs or scanned documents, a barcode library for images is the better fit.

Barcode scanning in the two SDKs

Media Blocks SDK .NETVideo Capture SDK .NET
APIBarcodeDetectorBlock in a MediaBlocksPipeline; the OnBarcodeDetected event gives the barcode type, value and timestampVideoCaptureCoreX and VideoCaptureCore: set Barcode_Reader_Enabled and handle OnBarcodeDetected; VideoCaptureCore also takes Barcode_Reader_Type
Barcode typesQR Code, EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF and GS1 DataBar (RSS-14), with UPC-A and UPC-E reported as EAN-13; Data Matrix with DataMatrixDecoderBlockVideoCaptureCoreX: the same set as BarcodeDetectorBlock. VideoCaptureCore: QR Code, Data Matrix, PDF417, Aztec, EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF and RSS-14
Video sourcesAny block with a video output: webcams and capture devices, IP cameras over RTSP and ONVIF, screen capture, video files and network streamsThe capture sources of the engine: webcams and capture devices, IP cameras over RTSP and ONVIF, screen capture
PlatformsWindows, macOS, Linux, Android and iOSVideoCaptureCoreX: Windows, macOS, Linux, Android and iOS. VideoCaptureCore: Windows
EditionOne edition with every block, the barcode detector includedThe barcode reader is in every edition, Standard included; IP camera sources need Professional or Premium

How the scanner works

BarcodeDetectorBlock wraps the zbar barcode detector. It reads each video frame that passes through it and reports the codes it finds.

  • OnBarcodeDetected gives the barcode type, the decoded value and the timestamp of the frame on the pipeline timeline; UPC-A and UPC-E codes are reported as EAN-13
  • InputOutput mode passes the video on to a preview, an encoder or a stream; InputOnly mode only scans, for services without a screen
  • Scanning runs in the same pipeline as preview, recording and streaming, so one camera feed can be recorded and scanned at the same time
  • A code that stays in view is reported again on the following frames, so filter repeats by value in your handler
  • BarcodeDetectorBlock.IsAvailable() tells you before you build the pipeline whether the detector can run on this machine
  • Data Matrix codes are read by a separate block, DataMatrixDecoderBlock, built on libdmtx

Where it is used

Ticket and access control

Check QR codes on tickets and passes at an entrance with a webcam or a tablet camera, and show the live picture to the operator.

Warehouse and production lines

Read barcodes on parcels and parts from fixed IP cameras over RTSP while the same stream is recorded for later review.

Kiosks and self-service terminals

Scan a QR code shown on a phone screen in a WPF, WinUI 3, MAUI or Avalonia application.

Recorded video and screens

Find the barcodes in a video file, or read QR codes shown on the desktop with screen capture.

Code Examples

The first example scans an RTSP camera with Media Blocks SDK .NET; the second turns on the barcode reader of the Video Capture SDK .NET capture engine.

Scan barcodes and QR codes from an RTSP camera

C#

Turn on the barcode reader of a webcam capture

C#

Where the detector sits

The detector is one block in the pipeline. Video passes through it to the rest of the pipeline, and each decoded code arrives as an event.

Webcam, IP camera, screen or file
BarcodeDetectorBlock
Preview, recording or stream

Frequently Asked Questions

How do I scan barcodes from a webcam in C#?▼
With Media Blocks SDK .NET, create a MediaBlocksPipeline, take the camera from DeviceEnumerator.Shared.VideoSourcesAsync(), and connect a SystemVideoSourceBlock to a BarcodeDetectorBlock in InputOutput mode and then to a VideoRendererBlock for the preview. Handle OnBarcodeDetected to get each code. With Video Capture SDK .NET, set Barcode_Reader_Enabled to true on VideoCaptureCoreX and handle the same event.
Can I read QR codes from an IP camera or an RTSP stream?▼
Yes. Create the source with RTSPSourceSettings.CreateAsync and RTSPSourceBlock, or with UniversalSourceBlock and the rtsp:// address, and connect its video output to BarcodeDetectorBlock. ONVIF cameras are read through their RTSP stream.
Can I use it in ASP.NET or a server-side service?▼
Yes. BarcodeDetectorBlock needs no window: in InputOnly mode it scans without rendering, so it runs in a console application, a Windows service or a background service of an ASP.NET Core application, on Windows or Linux. It reads the video that the server itself can open, such as IP camera streams, video files and capture devices attached to the server. It does not capture the camera of a visitor's browser.
Which barcode types does it read?▼
BarcodeDetectorBlock and VideoCaptureCoreX read QR Code, EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar, ITF (Interleaved 2 of 5) and GS1 DataBar (RSS-14). Both report UPC-A and UPC-E as EAN-13: a UPC-A value arrives as 13 digits with a leading 0, and a UPC-E value arrives expanded to its 13-digit form. Data Matrix is read by DataMatrixDecoderBlock. The Windows engine VideoCaptureCore also reads Data Matrix, PDF417 and Aztec, and its Barcode_Reader_Type property selects one type or all of them; in the default Auto mode the event reports the type as Auto.
Does it work on Linux, macOS, Android and iOS?▼
Yes. BarcodeDetectorBlock and VideoCaptureCoreX run on Windows, macOS, Linux, Android and iOS; VideoCaptureCore is Windows-only. On Windows, macOS, Android and iOS the detector comes in the VisioForge.CrossPlatform.Core.* NuGet packages. On Linux the SDK uses the system GStreamer, so call BarcodeDetectorBlock.IsAvailable() to check that the detector is installed. Android, iOS and macOS apps also need camera permission.
Do I get the same barcode more than once?▼
Yes. The detector reports a code in every frame where it decodes it, so a code held in front of the camera arrives many times. Keep the last value and time in your handler and skip repeats within a short window, as the barcode guide shows.
Which license do I need?▼
Media Blocks SDK .NET has one edition, and the barcode detector is part of it. In Video Capture SDK .NET the barcode reader is included in every edition, Standard included; IP camera sources need the Professional or Premium edition. One Video Capture SDK .NET license covers both engines, VideoCaptureCore and VideoCaptureCoreX. Prices are in euros, and VAT is added at checkout where it applies. The 30-day trial is fully functional.

Start scanning barcodes from video in C#

Download the fully functional 30-day trial and run the barcode samples. Depending on the output, a watermark or unregistered notice may appear.

Which SDK and edition

Prices are in euros; VAT is added at checkout where it applies. One license covers both engines of Video Capture SDK .NET.