Giter VIP home page Giter VIP logo

Comments (4)

sbraz avatar sbraz commented on September 25, 2024

Currently, it is not possible. @JeromeMartinez, any idea how we could implement this? Is there some way to connect a callback function?

from pymediainfo.

JeromeMartinez avatar JeromeMartinez commented on September 25, 2024

No callback function (yet), we have a callback function feature but there is no callback for a progress bar yet.
We have MediaInfo::State_Get(), value is between 0 and 10000, but you need a separate thread for probing the value.

from pymediainfo.

pcroland avatar pcroland commented on September 25, 2024

Could I pipe the file through something that can read how many bytes has been read?

from pymediainfo.

sbraz avatar sbraz commented on September 25, 2024

Yes, the parse method accepts a file-like object so you could create a file-like object that does something every time its read() method is called.
Please take a look at the code if you want to understand how pymediainfo handles file-like objects:

try:
filename.seek(0, 2)
file_size = filename.tell()
filename.seek(0)
except AttributeError: # filename is not a file-like object
file_size = None
if file_size is not None: # We have a file-like object, use the buffer protocol:
# Some file-like objects do not have a mode
if "b" not in getattr(filename, "mode", "b"):
raise ValueError("File should be opened in binary mode")
lib.MediaInfo_Open_Buffer_Init(handle, file_size, 0)
while True:
buffer = filename.read(buffer_size)
if buffer:
# https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfo/File__Analyze.h#L1429
# 4th bit = finished
if lib.MediaInfo_Open_Buffer_Continue(handle, buffer, len(buffer)) & 0x08:
break
# Ask MediaInfo if we need to seek
seek = lib.MediaInfo_Open_Buffer_Continue_GoTo_Get(handle)
# https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfoDLL/MediaInfoJNI.cpp#L127
if seek != ctypes.c_uint64(-1).value:
filename.seek(seek)
# Inform MediaInfo we have sought
lib.MediaInfo_Open_Buffer_Init(handle, file_size, filename.tell())
else:
break
lib.MediaInfo_Open_Buffer_Finalize(handle)

On a side note, I just noticed that pymediainfo only seems to support seekable objects, so I created #132.

from pymediainfo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.