0

I use the MediaInfo CLI to write up some basic information from groups of video files. I currently use a batch file that runs a MediaInfo CLI template. Here is a template (I call it "template.txt'):

General;%FileSize/String%" & "%Duration/String%\r\n
Video;%BitRate/String%\r\n
Audio;%BitRate/String%

I call on it with a batch file (template.bat):

For %%F IN (*.mp4) do ("C:\Program Files\MediaInfo CLI\MediaInfo.exe" --Inform=file://"F:\template.txt"
"%%F" >"%%~dpnF.txt")

Here is the python command I am attempting to replace the CLI with:

from pymediainfo import MediaInfo

media_info = MediaInfo.parse("events.mp4")
general_track = media_info.general_tracks[0]
video_track = media_info.video_tracks[0]
audio_track = media_info.audio_tracks[0]
print(
    f"{general_track.other_file_size} & {general_track.other_duration}\n"  
    f"{video_track.other_bit_rate}\n"
    f"{audio_track.other_bit_rate}"
)

There is plenty of data I can extract from the template that works fine with pymediainfo but I cannot get any of the 'String' data to work. For example, the pymediainfo equivalent of '%FileSize%' is 'file_size' and those both list the size in bits instead of MiB or GiB. For 1 of the videos I am attempting to write up a .txt file for the %FileSize/String% option in the CLI brings up the listing I am looking for (in this case 812 MiB). When I try using pymediainfo the only options I can find are 'file_size' which is 851764225 or 'other_file_size' which gives you ['812 MiB', '812 MiB', '812 MiB', '812.3 MiB']. Is there any way to select 1 of the 'other_file_size' options instead of all 4? Something like 'other_file_size_1'? I know that does not work, but some way to tell pymediainfo to only use the 1st 812 MiB in this case vs listing all 4. All of the CLI 'String' options seem to have this same issue when using pymediainfo.

I have spent hours searching the internet for a solution but I have not been able to find 1. I am assuming there is a very simple option to choose which data pymediainfo will select, but I cannot find anything about it on the internet. I have run a python command to display all the available pymediainfo data to determine the proper language but again, I can only find the "other_...." which I am hoping there is a way to tell it which 'other' I want to select. Thank you for any assistance

The solution was simple, not sure how I missed it. Just add [#] after the request to inform pymediainfo which data you are looking for. To get the '812 MB' from the previous case, I just tell python I am looking for the 1st data entry that results from the command: {general_track.other_file_size}. To direct python to use the 1st entry, I add [0] to the end of the command: {general_track.other_file_size[0]}.

olpdog
  • 1
  • 4
  • I don't know for pymediainfo, but FYI with [Python binding of MediaInfo](https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfoDLL/MediaInfoDLL.py) you can use the exact same field names than with the CLI, [example](https://github.com/MediaArea/MediaInfoLib/blob/master/Source/Example/HowToUse_Dll.py). – Jérôme Martinez Jun 28 '23 at 06:43

0 Answers0