Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't extract last 2 frame #7

Open
4 tasks done
timothyhalim opened this issue Aug 3, 2022 · 2 comments
Open
4 tasks done

Can't extract last 2 frame #7

timothyhalim opened this issue Aug 3, 2022 · 2 comments
Labels
bug Something isn't working.

Comments

@timothyhalim
Copy link

Get started

Description

Hi @cainmagi

When I try to extract last 2 frames of a video it return None

Here is the code used :

from PySide2.QtWidgets import QWidget, QLabel, QVBoxLayout, QApplication, QSlider
from PySide2.QtGui import QImage, QPixmap
from PySide2.QtCore import Qt

import mpegCoder
mpegCoder.setGlobal(dumpLevel=0)

class Player(QWidget):
    def __init__(self, parent=None):
        super(Player, self).__init__(parent)
        self._layout = QVBoxLayout(self)
        self.image = QLabel()
        self.slider = QSlider(Qt.Horizontal)
        self.slider.valueChanged.connect(self.extract_frame)
        self._layout.addWidget(self.image)
        self._layout.addWidget(self.slider)
        self.frames = []
        self.open_file()
        
    def close(self):
        self.decoder.clear()
        return super(Player, self).close()
        
    def open_file(self):
        self.decoder = mpegCoder.MpegDecoder()
        self.decoder.setParameter(nthread=4)
        opened = self.decoder.FFmpegSetup(r"30.mp4")
        
        if opened:
            duration = self.decoder.getParameter("duration")
            fps = self.decoder.getParameter("avgFrameRate")
            frameCount = duration*fps
            print("Video frame count is", frameCount)
            self.slider.setRange(0, frameCount-1) # -1 since start from 0
        
        self.extract_frame(0)
    
    def extract_frame(self, frame):
        print(frame)
        p = self.decoder.ExtractFrame(frame, 1)
        
        data = p[0].data
        height = p[0].shape[0]
        width = p[0].shape[1]
        channel = p[0].shape[2]
        pixmap = QPixmap.fromImage(QImage(data, width, height, channel*width, QImage.Format_RGB888))
        self.image.setPixmap(pixmap)
        
        
if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    p = Player()
    p.show()
    app.exec_()

You can change the frame by changing the slider

Here is the video used, 10sec/300frame video @30fps
the time code should be from 00:00 to 09:29
beeping every 1 sec/ 30 frame

30.mp4

Not really sure if this is a bug or if I'm doing something wrong

To Reproduce

  1. Run the code
  2. Change the slider
  3. Error occur when extracting last 2 frame

Traceback

No response

Behaviors

  1. The expected behaviors: able to extract every frame of the video
  2. The actual behaviors: unable to extract last 2 frame of the video

Screenshots

No response

OS

Windows 10

Python version

3.9

numpy version

1.23.1

mpegCoder version

3.2.4

Additional context

No response

@timothyhalim timothyhalim added bug Something isn't working. to be solved This issue or PR is waiting for the response. labels Aug 3, 2022
@cainmagi
Copy link
Owner

cainmagi commented Aug 3, 2022

I am quite sure that this is a bug. When mpegCoder returns a None, it means the video has reached the last frame. In my expectation, it should read the 00:00:09:29 picture, and return a None after that. However, actually it reaches the None output after the 00:00:09:27 picture. It means that there are several frames that are not read. Currently, I have no idea why this bug happens, so I could not provide you with a solution instantly. Please give me a few weeks to tackle this problem. Recently I do not have plenty of time on this project but I think this issue may take me a long while to solve.

@cainmagi cainmagi removed the to be solved This issue or PR is waiting for the response. label Aug 3, 2022
@timothyhalim
Copy link
Author

ok thanks! @cainmagi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants