Quality issue when saving animation on another thread. (with pyqt5 GUI)

24 Views Asked by At

As I care a lot about user experiance, I wanted to keep updating progress bar while main thread save animation. (I plot each frame on main thread. only saving work is on another thread)

However, saving animation on second thread makes result of low quality animation.

(I will attach each gif after work, due to company file security)

class CameraWorker(QObject):
finished = pyqtSignal()

def __init__(self, cam=None, dir=None, fps=None):
    QObject.__init__(self)
    self._cam = cam
    self._dir = dir
    self._fps = fps

def gifsave(self):
    ani = self._cam.animate(blit=True)
    ani.save(self._dir, dpi=150, writer=PillowWriter(fps=self._fps, bitrate=30000))
    self.finished.emit()

plotting code

def draw_phvideo(self):            
        fig = plt.figure()
        
        camera = Camera(fig)

        for targetTime in range_time:
            """ some plotting code """
            camera.snap()
        self.prgBr.setValue(0)
        self.prgBr.setMaximum(0)
        
        # Multi Thread Initialize
        self.thrd_cam = QThread()
        self.wrkr_cam = CameraWorker(camera, fileName[0], fps)
        self.wrkr_cam.moveToThread(self.thrd_cam)

        # Multi Thread Working
        self.thrd_cam.started.connect(self.wrkr_cam.gifsave)
        self.wrkr_cam.finished.connect(self.done_cam)

        # Multi Thread Start
        self.thrd_cam.start()
        
def done_cam(self):
    print("multi thread done")
    self.prgBr.setMaximum(1)
    self.thrd_cam.quit()
    self.thrd_cam.wait()
    self.wrkr_cam.deleteLater()
    self.thrd_cam.deleteLater()
0

There are 0 best solutions below