Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

python - playing a video file in pygubu frame and being able to move to specific frames back and forth

I am new to tkinter so I found pygubu as a GUI designer. Now I can browse my video file and a CSV file including specific frames' indices (numbers like 25, 32, ... which is the frame number). what I want to do is to play/pause the video I browsed with a play/pause button as well as to move to the frame indices mentioned in the csv file back and forth with previous and next button. The problem is I don't know why the video is not shown in tkinter frame (no errors just not playing) and I have no idea about this moving in video frames reading the indices from a CSV file with next, previous button. I appreciate your help. and this is my current code:

import os
import pygubu
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import filedialog
import time
import imageio
from PIL import Image, ImageTk
import cv2

PROJECT_PATH = os.path.dirname(__file__)
PROJECT_UI = os.path.join(PROJECT_PATH, "aoigui.ui")
global pause_video

class AoiguiApp:
    def __init__(self, parent):
        self.builder = builder = pygubu.Builder()
        builder.add_resource_path(PROJECT_PATH)
        builder.add_from_file(PROJECT_UI)
        self.mainwindow = builder.get_object('main_frame', parent)
        builder.connect_callbacks(self)
        self.label_entry = builder.get_object('label_entry', parent)
        self.vid_player_win = builder.get_object('vid_player_win', parent)
        self.vidfile = builder.get_variable('vidfile_dir', parent)

    def browse_vidfile(self):
        self.vidfilename = filedialog.askopenfilename(initialdir="/", title="Select A File", filetype=
        (("mp4 files", "*.mp4"), ("all files", "*.*")))

    def browse_infofile(self):
        self.vidfilename = filedialog.askopenfilename(initialdir="/", title="Select A File", filetype=
        (("csv files", "*.csv"), ("all files", "*.*")))

    def generate_video(self):
        video_name = self.vidfilename
        video = imageio.get_reader(video_name)
        def current_time():
            return time.time()

        start_time = current_time()
        _time = 0
        for frame, image in enumerate(video.iter_data()):
            image = Image.fromarray(image)
            image.thumbnail((500, 500), Image.ANTIALIAS)
            image = ImageTk.PhotoImage(image)
            _time += 1 / 24
            run_time = current_time() - start_time
            while run_time < _time:
                run_time = current_time() - start_time
            else:
                if run_time - _time > 0.1:
                    start_time = current_time()
                    _time = 0
            return frame, image

    def play(self):
        global pause_video
        pause_video = False

    def stop(self):
        global pause_video
        pause_video = True

    def next(self):
        pass

    def previous(self):
        pass

if __name__ == '__main__':

    root = tk.Tk()
    root.title('AOI Annotation Tool')
    app = AoiguiApp(root)
    pause_video = True
    app.run()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...