Example Code

FFMPEG scripting in LabVIEW (.NET)

Code and Documents

Attachment

Overview

"CONVERTING VIDEOS AND AUDIOS HAS NEVER BEEN SO EASY." - And Finally in LabVIEW

How to use "Zeranoe FFmpeg" static 32/64-bit FFmpeg executables with LabVIEW under Windows OS.

FFmpeg examples provided below can be used with any supported sources, i.e DShow devices, network streams, files.

FFmpeg can be used for video analysis and data broadcasting, for more details on how to use FFmpeg refer to https://www.ffmpeg.org/

Description

Attached examples were created in response to question posted at "RTSP over TCP with LabVIEW" thread.

.NET implementation explained:

  • Create process (FFmpeg.exe)
  • Set process parameters
  • Subscribe to process-related Events
  • Use pipes (stdin/pipe0/stdout/pipe1/stderr/pipe2) to move data from FFmpeg to LabVIEW and back

Steps to Implement or Execute Code


  1. Download and install "Zeranoe FFmpeg" latest static build and place into FFMPEG directory.
  2. Folder snapshot:FFMPEG folder.png

  3. Enjoy FFMPEG scripting with LabVIEW

Requirements to Run


Software

  1. LabVIEW 11.0 or later
  2. "Zeranoe FFmpeg" 32/64-bit static build  -  http://ffmpeg.zeranoe.com/builds/
  3. "RTSP over TCP with LabVIEW" library for RTSP examples - https://decibel.ni.com/content/docs/DOC-35217

Hardware

  1. USB (DShow device) or IP camera or video/audio files

Snippets

***SORRY for broken VI's - LabVIEW's snippet tool backfiring... Files inside zip archive are not broken. I will fix snippets later...***


Open DShow device.png

"FFPLAY - Example - DShow device.vi" - opens user specified DShow device.

DShow save to file.png

"FFMPEG - Example - DShow - stream to file.vi" - Saves DShow device data to mp4 container, user can specify duration or cancel recording at any time.

RTSP save to file.png

"FFMPEG - Example - RTSP - stream to file.vi" - Saves RTSP stream to mp4 container, same as above.

LabVIEW-RTSP-FFMPEG.png

"FFMPEG - Example - RTSP-LabVIEW-FFMPEG - stream to file" - Sometimes when FFMPEG fails to establish connection with network device you can relay data with LabVIEW over the pipes (stdin/pipe0 and stdout/pipe1 and stderr/pipe2).

Extract frame to JPEG.png

"FFMPEG - Example - RTSP - Extract frame as JPEG.vi" - Extracts single frame from network stream, passes it over pipe to LabVIEW and saves as JPEG file.

Extract frame to PNG.png

"FFMPEG - Example - RTSP - Extract frame as PNG.vi" - Extracts single frame from network stream, passes it over pipe to LabVIEW and draws it.

Extract frame to PPM.png

"FFMPEG - Example - RTSP - Extract frame as PPM.vi" - Extracts single frame, stamps image with timestamp, frame count and duration. Pipes resulting frame to LabVIEW, converts PPM data to 2D Image array.

More examples would come later...

Update 06/29/2015:

PPM_Movie.png

"FFMPEG - Example - RTSP - Extract frames (PPM).vi" - FFmpeg processes video stream and passes individual frames to LabVIEW.

Update 07/01/2015:

"FFMPEG Examples v1.1.zip" - updated with "yuv420p" and NI Vision Graph examples.

yuv420p.png

"FFMPEG - Example - RTSP - Extract frames (yuv420p) Intensity Graph.vi" - yuv420p to 2D RGB

Note: To improve performance, Intensity graph update rate was reduced to 1/5 of frame rate.

Vision Graph.png

"FFMPEG - Example - RTSP - Extract frames (yuv420p) Vision Graph.vi" - yuv420p to NI Vision Graph

Update 12/30/2015:

With script -f sdl "window name" - you can create FFmpeg rendering window (CPU usage is not great but better than what you can do in LabVIEW)

You can specify size, title, background and window title.

FFmpeg sdl documentation

-Artur

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
niUser1992
Member
Member
on

Hi GriffinRU

How can I use this development using a video file stored in local, instead of a TCP IP streaming? 

Contributors