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
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Python Techniques for Text Extraction From Images
  • BigQuery DataFrames in Python
  • OneStream Fast Data Extracts APIs

Trending

  • AI-Driven Test Automation Techniques for Multimodal Systems
  • How to Convert XLS to XLSX in Java
  • The Role of AI in Identity and Access Management for Organizations
  • Agentic AI for Automated Application Security and Vulnerability Management

How to Extract Video Still Frames with MPlayer

By 
Boyan Kostadinov user avatar
Boyan Kostadinov
·
Mar. 04, 08 · News
Likes (0)
Comment
Save
Tweet
Share
23.6K 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

  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Python Techniques for Text Extraction From Images
  • BigQuery DataFrames in Python
  • OneStream Fast Data Extracts APIs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • 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: