How does python get the details of the file?

for example, the size of a file, creation time, modification time, etc. I know that you can use os.stat to get

but how do I get the other information in the file properties-details?

for example, the width, height and resolution of the picture file; the frame bandwidth, height and rate of the video file; the bit rate of MP3, the artist; how to get these data information?

Apr.11,2021

these properties are unique to multimedia files, so they are not generic stat properties. So you have to call the multimedia parsing library to get this information.

of course, to get picture information, you can use python's PIL class library to get audio information. You can use class libraries like taglib to parse audio and do your own packaging.

Finally, you can use the omnipotent tool for parsing multimedia information mediainfo , which is a cross-platform cli+gui tool that can parse almost all kinds of common multimedia parameters, provide cli interface, and also provide programming interface (for example, potplayer uses this tool to obtain multimedia information). You can find out if there is a wrapper, for python or the command line that invokes it yourself.

of course ffprobe command line tools are fine. To avoid me, I personally recommend mediainfo to do this, which I have used for many years.

Menu