Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a command-line utility that I wrote (C++, MinGW32, Windows 10), that displays information for images and videos... I recently found an excellent free library (ZPlay) that handles some of the more complex images such as OGG, MP3, FLAC...

I managed to find code that would parse mp3 files and show me key information (bitrate, play length, etc), but it was quite a bit of work to get it working for all mpeg formats... now I would really like to pull relevant info for mp4 videos, but that is a *ton* of work, far more than mp3 was...

I would really appreciate having access to a video library that would pull relevant info for common video files (mov, mp4, webm, etc) without me needing to grind through deriving the code for each one by hand...

Can anyone suggest any relevant libraries?

What I have tried:

hand-coding each file format manually from specs
Posted
Updated 17-May-23 20:18pm
Comments
Derell Licht 15-May-23 10:34am    
I mistakenly left this post as a "solution", which was *not* my intent at all!!
However, I am removing my later comments about ffmpeg; I will transfer any relevant discussions to the ffmpeg forum(s)… I found build instructions for MinGW on the web and I'm going to try to get the libraries built on my system.

Thank ye all for your ffmpeg advice!!

original post:
ffmpeg is one of the options that I'm looking at, but it seems to offer an exceedingly complex learning curve; it's not intended for Windows, doesn't have MinGW build options, everything is distributed as source code only... The ffprobe utility that comes with it, *does* provide exactly the info that I want, but it is extremely non-trivial to come up with a buildable example program.

I'm really looking for something such as a video equivalent of libzplay;
"Here is the .dll, .lib in mingw format, .h, and a 200-line example program that shows how to output the desired data...

I'm also looking at libVLC ... since that program can definitely play all video files that I could ever care about - and presumably if it can play them, it can also display the file data that I want...
The dll files are available in VLC media player install directory, but I still need to find .h (i.e., API), .lib (in mingw format) and either short, concise example programs, or other usable documentation...

This isn't necessarily a C++ solution - I haven't played with C++ for over a decade - but there is a .NET way to get some video info direct from the OS provided a suitable codec is installed - I use it to get video duration and resolution, using the WindowsAPICodePack in C#:
C#
/// <summary>
/// Gets the display size for a video or image file
/// </summary>
/// <remarks>
/// ShellObject and IShellProperty require the Microsoft Windows API Code Pack:
/// http://msdn.microsoft.com/en-us/library/ff356173(v=vs.110).aspx
/// Add references to both:
///    Microsoft.WindowsAPICodePack.DLL
///    Microsoft.WindowsAPICodePack.shell.DLL
/// </remarks>
/// <param name="filename">Full path to file</param>
/// <returns>The display size for a known video or image file</returns>
public static Size GetDisplaySize(string filename)
    {
    int height = 0;
    int width = 0;
    try
        {
        if (System.IO.File.Exists(filename))
            {
            using (ShellObject so = ShellObject.FromParsingName(filename))
                {
                if (so != null)
                    {
                    string type = (string)so.Properties.GetProperty("System.KindText").ValueAsObject;
                    switch (type)
                        {
                        case "Video":
                            height = Convert.ToInt32(so.Properties.GetProperty(SystemProperties.System.Video.FrameHeight).ValueAsObject);
                            width = Convert.ToInt32(so.Properties.GetProperty(SystemProperties.System.Video.FrameWidth).ValueAsObject);
                            break;
                        case "Picture":
                            height = Convert.ToInt32(so.Properties.GetProperty(SystemProperties.System.Image.VerticalSize).ValueAsObject);
                            width = Convert.ToInt32(so.Properties.GetProperty(SystemProperties.System.Image.HorizontalSize).ValueAsObject);
                            break;
                        case "Music":
                            break;
                        default:
                            break;
                        }
                    }
                }
            }
        }
    catch { }       // Don't care what the problem is, I can't deal with it here!
    if (width > 0 && height > 0) return new Size(width, height);
    return new Size(0, 0);
    }
/// <summary>
/// Gets the play duration for a media file
/// </summary>
/// <remarks>
/// ShellObject and IShellProperty require the Microsoft Windows API Code Pack:
/// http://msdn.microsoft.com/en-us/library/ff356173(v=vs.110).aspx
/// Add references to both:
///    Microsoft.WindowsAPICodePack.DLL
///    Microsoft.WindowsAPICodePack.shell.DLL
/// </remarks>
/// <param name="filename">Full path to file</param>
/// <returns>The display size for a known video or image file</returns>
public static TimeSpan GetDuration(string filename)
    {
    long duration = 0;
    try
        {
        if (System.IO.File.Exists(filename))
            {
            using (ShellObject so = ShellObject.FromParsingName(filename))
                {
                if (so != null)
                    {
                    string type = (string)so.Properties.GetProperty("System.KindText").ValueAsObject;
                    switch (type)
                        {
                        case "Video":
                            duration = Convert.ToInt64(so.Properties.GetProperty(SystemProperties.System.Media.Duration).ValueAsObject);
                            break;
                        case "Picture":
                            break;
                        case "Music":
                            duration = Convert.ToInt64(so.Properties.GetProperty(SystemProperties.System.Media.Duration).ValueAsObject);
                            break;
                        default:
                            break;
                        }
                    }
                }
            }
        }
    catch { }       // Don't care what the problem is, I can't deal with it here!
    if (duration > 0) return new TimeSpan(duration);
    return new TimeSpan(0);
    }
I would think that the CodePack would work in C++ as well.
 
Share this answer
 
Comments
Derell Licht 15-May-23 11:46am    
Well, that is interesting... I don't use .net, but this gives another option to look into for C++ !! Thank ye...
So Derell wrote the ffmpeg is a solution. You have to learn to handle the code, but it has a lot of features and it is some "workhorse" library.
Your tasks are challengig so it is also challenging to get some library to do the job.

tip: the ffmpeg has a lot of example code and also in forums you find a lot of people (like me) who are using that library
 
Share this answer
 
Try MediaInfo:
MediaInfo - Download MediaInfo for Microsoft Windows[^]

It ships with a simple to use Dll interface that can be used to gather information about nearly all video and audio files. In the Zip-File you will find a directory called "Developers" - there you can find sample source code on how to use it properly.
 
Share this answer
 
Comments
Derell Licht 16-May-23 9:44am    
Ahhhh... that's an interesting option... I've already been using MediaInfo to double-check results that my program gives for various formats, but it didn't occur to me to try to extract their library!! I'll pursue that too... Thank ye!!
ffmpeg should be able to do this. Not sure if it supports directly embedding itself within your C++ code, but you should at least be able to run an instance of the binary from your code (with the correct flags) and then parse the output it produces.
 
Share this answer
 
 
Share this answer
 
v2
Comments
Derell Licht 15-May-23 11:44am    
Well, no... I've been programming in C and C++ for almost 40 years now; that's the platform that I am expert in... I'm not really interested in starting over with a new language...
RickZeeland 15-May-23 12:39pm    
Sadly not much on GitHub for C++, but maybe I searched with the wrong keywords ...
crystalhd			
gstreamermm			
libmatroska			
libVLC			
mjpegtools			
OpenH264
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900