DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • OneStream Fast Data Extracts APIs
  • Reversing an Array: An Exploration of Array Manipulation
  • Protect Your Invariants!
  • Migrating From Sakila-MySQL to Couchbase - ETL

Trending

  • What You Must Know About Rate Limiting
  • Breaking Free From the Cloud With Kamal: Just Enough Orchestration for Your Apps
  • The Stairway to Apache Kafka® Tiered Storage
  • How to Configure Istio, Prometheus and Grafana for Monitoring

How to Extract Video Still Frames with MPlayer

Boyan Kostadinov user avatar by
Boyan Kostadinov
·
Mar. 04, 08 · News
Like (0)
Save
Tweet
Share
22.86K Views

Join the DZone community and get the full member experience.

Join For Free

While working on a video content management system, I was in need of capturing frames from video files so they can be used as a preview for video. The system already had some code in place but it only worked for video encoding in Windows Media format (.wmv extension). That would not do, I thought, not in this day and age when we have so many file formats and video codecs. So I need to able to:

  1. Capture video frames from within .NET code
  2. Capture images from all kinds of different video formats
  3. Not reinvent the wheel while satisfying #1 and #2


Enter MPlayer

Stolen directly from the Information page of MPlayer, "MPlayer is a movie player which runs on many systems (see the documentation). It plays most MPEG/VOB, AVI, Ogg/OGM, VIVO, ASF/WMA/WMV, QT/MOV/MP4, RealMedia, Matroska, NUT, NuppelVideo, FLI, YUV4MPEG, FILM, RoQ, PVA files, supported by many native, XAnim, and Win32 DLL codecs. You can watch VideoCD, SVCD, DVD, 3ivx, DivX 3/4/5 and even WMV movies..". To add my own description, MPlayer is an open source command line video player.


So What

Metallica has an old song called "So What", great tune for the metal heads in all of us. The answer is simple, MPlayer can do a lot more than play video. It can capture images, stream video over http and even transcode video from one format to another (but the last feature is grounds for another article).


Putting It Together

You will need:

  • 1 download of MPlayer Windows executable from http://www.mplayerhq.hu/design7/dload.html
  • 1 download of the MPlayer Windows binary codecs package from http://www.mplayerhq.hu/design7/dload.html
  • 1 MPlayer .NET wrapper provided in this article


Setup

  1. Extract the mPlayer executable (mplayer.exe)
  2. Extract the mPlayer codecs in a directory called "codecs" in the same directory as the mPlayer executable
  3. Add a reference to the mPlayerWrapper project or compiled DLL


Usage

  • Capture with default arguments

    in C#
    // Specify the path to the video filestring videoFilePath = @"drive letter:\path\to\myVideo.mpg";// Declare the mplayer instance with the mplayer executable residing in the// same directory as your executablemPlayerWrapper mPlayerInstance = new mPlayerWrapper();// Capture framesmPlayerInstance.captureFrames(videoFilePath);    

    in VB.NET
    ' Specify the path to the video filedim videoFilePath As String = "drive letter:\path\to\myVideo.mpg"' Declare the mplayer instance with the mplayer executable residing in the' same directory as your executabledim mPlayerInstance As new mPlayerWrapper()' Capture framesmPlayerInstance.captureFrames(videoFilePath)    

    This will capture 12 frames with 5 second interval between each frame and put them in the same directory as your video file. The filename of each frame will be "myVideo_thumb01.jpg" to "myVideo_thumb12.jpg". Each frame will be scaled to 270x200.
  • Capture arguments
    • mPlayerPath - sets the path where the mPlayer executable (mplayer.exe) is located. The default is in the same directory as your code is executing.
    • currentFilePath - sets the file path to the video file you are using
    • cleanOutputDirectory - deletes all the "jpg" images in the capture output directory before capturing
    • captureInterval - sets the interval at which frames will be captured. Only applicable if using a time interval capture method (as outlined below)
    • numberOfFramesToCapture - the number of frames to be captured
    • captureExactNumberOfFrames - tells the wrapper to attempt to capture the exact number of frames as specified by the "numberOfFramesToCapture" property. This can be used if a file has too few frames but you still want to capture an exact number
    • useTimeSeekToCapture - used to set the wrapper method of capture to seeking through the file instead of capturing a frame at an interval
    • thumbnailPrefix - the prefix to be used when creating the filenames for captured frames. The default is the name of the video with "_thumb" append to it as in "myVideo_thumb01.jpg"
    • capturedFrameWidthHeight - the width:height that each frame will be scaled to. The default is 270:200
    • scaleCapturedFrames - used in conjunction with the "capturedFrameWidthHeight" property to scale down the captured frames. Set to true by default
  • Capture in a different output directory
    in C#
    // Specify the path to the video filestring videoFilePath = @"drive letter:\path\to\myVideo.mpg";// Specify the output directorystring outputPath = @"drive letter:\path\to\output directory";// Declare the mplayer instance with the mplayer executable residing in the// same directory as your executablemPlayerWrapper mPlayerInstance = new mPlayerWrapper();// Capture framesmPlayerInstance.captureFrames(videoFilePath, outputPath);    

    in VB.NET
    ' Specify the path to the video filedim videoFilePath As String = "drive letter:\path\to\myVideo.mpg"' Specify the output directorydim outputPath As String = @"drive letter:\path\to\output directory"' Declare the mplayer instance with the mplayer executable residing in the' same directory as your executabledim mPlayerInstance As new mPlayerWrapper()' Capture framesmPlayerInstance.captureFrames(videoFilePath, outputDirectory)    
  • Using distinct capture methods:
    1. captureFramesWithInterval - by default captures a frame every 5 seconds with up to 12 frames
    2. captureFramesWithTimeSeek - by default captures 1 frame each second with up to 12 frames by seeking through the file


Bonus

  • getFileProperties - returns a SortedList of video and audio properties for the file
  • getAudioProperties - returns a SortedList of audio properties for the file
  • getVideoProperties - returns a SortedList of video properties for the file


Downloads

mPlayerWrapper: http://blog.tech-cats.net/examples/dotnet/mPlayerWrapper.dll
mPlayerWrapper Source: http://blog.tech-cats.net/examples/dotnet/mplayerWrapper-v0.2.zip

Frame (networking) Extract

Published at DZone with permission of Boyan Kostadinov, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • OneStream Fast Data Extracts APIs
  • Reversing an Array: An Exploration of Array Manipulation
  • Protect Your Invariants!
  • Migrating From Sakila-MySQL to Couchbase - ETL

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: