I am trying to call MediaInfo from within a Visual Basic program in order to obtain the video and audio information about a video file. The intention is to store this data in an access database record linked to the video clip. Does anyone have any info on the format and parameters required to call MediaInfo? Thanks
+ Reply to Thread
Results 1 to 19 of 19
-
-
That would not help as you still could not parse that data to import in to your access db fields.
Easier to write your own code to parse the video header(s) - I did a quick google and found info on mpeg and avi(apparently with full vb code) headers so it should all be out there.
Avi details here (links to vb code):
http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=46648&lngWId=1
Some info in mpeg headers here:
http://www.codeguru.com/forum/showthread.php?t=235226 -
I don't know anything about VB/access, but it should be possible to get mediainfo to report details on a file in a custom format of your choice. Maybe a comma separated list would be suitable? Something like:
video.mp4 , 01:20:00.00 , 16:9 , 640 , 360 , h264 , ac3 , 2 , 44100
which would correspond to:
filename, length, aspect ratio, width, height, video codec, audio codec, audio channels, audio sampling
This document has some formatting examples:
http://umibe.googlecode.com/svn-history/r8/trunk/umibe/resources/MediaInfo/Contrib/CLI_Help.doc
If this is what you're looking for, I can provide some specific examples. Just give a list of what information you want and the way it should be formatted.
There seem to be some bugs with getting mediainfo to format the output which I haven't found a way round. This might be an issue, depending on what you want to do exactly. -
Well let me give the details. I have written an MS-Access VBA application which scans given folders to find video clips and gets the file specific data provided by Windows such as file date, file size, etc. These attributes are stored in a row of the table. However for a video clip database this is not enough. So I am looking for a way to run the MediaInfo utility for the clip concerned and get the video and audio data from MediaInfo to store in the same row. For this purpose I execute the MediaInfo CLI from within the VBA module. Up to this point all runs well. Now I am looking for a way to grab the results that show up at the DOS CMD panel and store them. MediaInfo CLI has an output option that does not work. If I use the output parameter of DOS CMD it creates an empty text file. This is the problem.
-
I really should not reply to this forum before I have my first coffee. So my apologies for the original 'blast' even tho the comments about the links I posted do still seem valid.
I clean forgot about the command-line version but I do wonder if that is the best approach. The .dll can also be accessed (pardon the pun) from within vb (versions 5 and 6) and that should return the data in a form you can then control. -
I considered dll version. It needs to be registered using regsrv32. I tried many times an error message comes and it can not be registered.
ed. -
I took a closer look at the CLI options. The following will give you a full listing of the info of the file saved to [path\]info.txt:
[path\]mediainfo.exe --logfile="[path\]info.txt" [path\]yourmedia.file (do not forget the quote marks)
To restrict the output data it seems you have to manipulate the 'inform' parameter with templates
The output parameter does work but it just outputs hmtl or xml tagged data -
Thanks for the input. In fact I have been working on the CLI version. The syntax below works. The info.txt file contains all the parameters.
"C:\Program Files\MediaInfo_CLI\MediaInfo.exe --logfile=F:\info.txt CVID.avi"
I experimented a lot with a template file, but helas I could not get it to work. If instead you write the parameters one by one with % signs in the command line as a template then it works. In any case the resulting text file contains the necessary data which I can read in VBA and manipulate. If anyone else hits the same problem I can write down the various syntax options that I tried. -
Do you mean the DOS command window literally appears when you run mediainfo from VB? That doesn't seem the best way to do it. I would've thought the only time you'd want to do it that way is when you need to interact with a text based program.
There's got to be a way to run a program from VB in the background and have any output from it stored in a variable for further use. I've never used VB, but with php (completely different I know):
PHP Code:$data = exec("mediainfo --Inform='Video;%DisplayAspectRatio/String%,%Duration/String3%' video.mp4");
echo $data;
http://rosettacode.org/wiki/Execute_a_system_command#Visual_Basic
(no idea if that's the best way to execute a system command)
It looks like Visual Basic is one of the most complicated examples on there
Try putting this in a file called 'template':
Code:Video;%DisplayAspectRatio/String%,%Duration/String3%
C:\Program Files\MediaInfo_CLI\MediaInfo.exe --Inform=file://C:\full\path\to\template --logfile=F:\info.txt CVID.avi
EDIT: you might have to escape the slashes
You should get the aspect ratio and duration separated by a comma.Last edited by intracube; 23rd Oct 2011 at 01:40. Reason: clarification
-
Yes it shows up briefly and disappears.
I do agree with you. I have seen the Rosetta page. It did not bring much towards the solution.
I have tried this proposal. No it does not work. The problem seems to be not the structure of the template file but rather the template file option itself. When an output option such as logfile is present the template file option does not work. In fact this is also mentioned in the CLI help document stored in the contrib folder. -
Hmm, the following syntax works under Linux:
Code:mediainfo --Inform=file:///path/to/template --LogFile=/path/to/logfile video.mp4
Not sure how this should be adapted to work with Windows.
The command above (using the template defined in post #9) creates a file which contains the text:
16:9,00:00:13.400
One bug I've noticed - if the Inform template contains a 'General;' section, it messes up the output. Only 'Video;' and 'Audio;' sections seem to work properly together. -
I got it to work. Here is the command line. This is followed by a space and the path to clip .
"C:\Program Files\MediaInfo_CLI\MediaInfo.exe --Inform=file://F:\VVV.txt --LogFile=F:\info.txt"
VVV.txt contains this: Video;Aspect_Ratio=%DisplayAspectRatio/String%,%Duration/String3%
info.txt contains this: Aspect_Ratio=16:9,00:03:44.800
Template syntax is not consistent and not properly documented. Most of the effort is guesswork. -
Glad you got it working. I might be able to suggest a set of template options if you list what info you want returned, and the formatting.
mediainfo can return many of the details in a number of ways. For example the aspect ratio can be displayed as a ratio 16:9, or floating point 1.778.
Changing your VVV.txt to this:
Code:Video;%DisplayAspectRatio%,%Duration/String3%
Try running:
Code:C:\Program Files\MediaInfo_CLI\MediaInfo.exe --Info-Parameters
I've uploaded the list in case you have problems running this command. -
Thanks a lot. I have now extended the template elements in the file. Only the /n/r parameters to get a new line do not work. The others are OK. I have done some more research on this subject. There are procedures to run a DOS command from VBA and then display results in a msgbox. But in most cases when it is possible to get results in a text file then this approach is preferred. Especially in my case I plan to have around 15 parameters in the result. Even if I go for a text string in a msgbox I shall have to parse the string using string functions to display and store the values properly. Thus a text file as output is satisfactory for the purpose.
-
As I said before Media Info CLI parameter syntax is quite inconsistent. I have the template file as below working:
Video;---Format=%Format%---Duration=%Duration/String%---BitrateMode=%BitRate_Mode%---Bitrate=%BitRate/String%---Width=%Width%---Height=%Height%---Aspect_Ratio=%DisplayAspectRatio/String%---FrameRate=%FrameRate/String%---FrameCount=%FrameCount%---Standard=%Standard%---ScanType=%ScanType/String%---
The logfile is:
---Format=MPEG Video---Duration=4mn 48s---BitrateMode=VBR---Bitrate=9 168 Kbps---Width=720---Height=576---Aspect_Ratio=16:9---FrameRate=25.000 fps---FrameCount=7205---Standard=PAL---ScanType=Interlaced---
Sometimes it creates an empty file. Why? I have not figured out yet. -
re: empty files,
Maybe because of NULLs or other non-standard input. Like the field "Standard" - sure, there's PAL and NTSC. And you could probably put 1080p24, 720p60, ATSC in there, but if the file is 400x300, there's no standard. So what should it output?
[BLANK], "Other", "None", skip the field, or possibly skip the output altogether...
Too bad you can't poll the DLL by each field individually, then you could control the reaction to non-normalized or unavailable output.
Scott -
i don't get it.. what is wrong with importing the DLL inside ms access ? i've done this a few times in ms access--where i wrote several different DLL's in delphi code (math functions) and then imported into access and used those math functions in the delphi dll. course, i was using office 2000 in those tests. if you can't read mediainfo.dll directly inside ms access, then perphaps you can create a front-end dll inside visual basic, and then load that dll inside ms access. you should be able to do the same unless visual basic doesn't create dll's, i don't know since i have/use it. at least one of these methods should work.
-
I tried to register the MediaInfo dlls using regsrv32, but I got an error message. They can not be registered. Try to import them they are refused. The template and logfile at least work and I have a handle on them. I managed to get the whole issue working as planned. Of course any other suggestion that can simplify the code is welcome provided that it works and does not require many hours of debugging.
Similar Threads
-
Edit MediaInfo Info
By thezanny in forum Newbie / General discussionsReplies: 1Last Post: 13th Aug 2011, 04:18 -
Mediainfo File Info tool "Format Profile" wrong info problem
By dabas in forum Newbie / General discussionsReplies: 2Last Post: 9th Mar 2010, 05:07 -
visual basic code
By kudoshinichi in forum ProgrammingReplies: 1Last Post: 21st Jan 2009, 08:30 -
getting mediainfo to display the following info
By philhxc in forum Newbie / General discussionsReplies: 6Last Post: 8th Jan 2009, 06:48 -
Programming FFMPEG (Visual Basic)
By Ace-Of-Spades in forum ProgrammingReplies: 4Last Post: 9th Oct 2007, 06:18