ffmpeg-python
ffmpeg-python copied to clipboard
How to get frame and time infomation at the same time while reading video frame by frame?
in_filename = "test.mp4" process1 = ( ffmpeg.input(in_filename) .output(format='rawvideo', pix_fmt='rgb24') .run(capture_stdout=True, capture_stderr=True) ) while True: in_bytes = process1.stdout.read(width * height * 3) if not in_bytes: break in_frame = ( np .frombuffer(in_bytes, np.uint8) .reshape([height, width, 3]) )
There is only frame, how can i get the time information,like "pkt_pts_time" , as the following: { "media_type": "video", "stream_index": 0, "key_frame": 0, "pkt_pts": 205200, "pkt_pts_time": "2.280000", "pkt_dts": 205200, "pkt_dts_time": "2.280000", "best_effort_timestamp": 205200, "best_effort_timestamp_time": "2.280000", "pkt_duration": 21600, "pkt_duration_time": "0.240000", "pkt_pos": "46658", "pkt_size": "1244", "width": 1280, "height": 720, "pix_fmt": "yuvj420p", "pict_type": "P", "coded_picture_number": 9, "display_picture_number": 0, "interlaced_frame": 0, "top_field_first": 0, "repeat_pict": 0, "color_range": "pc", "color_space": "bt709", "color_primaries": "bt709", "color_transfer": "bt709", "chroma_location": "left" },
Hi, I've the same problem to solve. Do you have found the solution? If yes, can you share it please? Thanks
Sorry, I have no idea util now to get frame and time information at the same time.
But I get time information firstly, then get the frame. TThe solution is as follows. At firt, I get time information by the following codes, then get the frames by opencv-python. They can correspond one by one in order. p = subprocess.Popen( "ffprobe -show_frames -select_streams v -of json " + self.job.input.video.path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = p.communicate() p.wait() timestamps = json.loads(out.decode('utf-8'))
May it helps you.
At 2024-02-22 19:28:47, "aimaicai" @.***> wrote:
Hi, I've the same problem to solve. Do you have found the solution? If yes, can you share it please? Thanks
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>