Python crashes for holistic model on video

Python crashes for holistic model of mediapipe if I am applying the model to a video.
I tried different steps to solve that issue:

  1. Using mediapipe in MacOs and Windows
  2. Use of CPU and GPU delegates
  3. Use of images instead of videos
  4. Conversion of the original MOV to MP4 format
    However, this did not resolve the issue. I wonder whether this issue is related to the file format (MP4/MOV), but cv2 is able to read that and plotting the numpy array results in the expected image.

Thus, I would highly appreciate your support. You can find an example code attached:

My code:

import cv2
import sys
import os
import glob

import numpy as np
import mediapipe as mp  # mediapipe for hand dectection

import plotly.graph_objs as go
from plotly.subplots import make_subplots

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation

import pandas as pd
import plotly.graph_objects as go
import plotly.io as pio
import scipy as sc
from scipy import signal
from mediapipe.tasks import python


BaseOptions =python.BaseOptions
HolisticLandmarker = mp.tasks.vision.HolisticLandmarker
HolisticLandmarkerOptions = mp.tasks.vision.HolisticLandmarkerOptions
VisionRunningMode = mp.tasks.vision.RunningMode

# Create a face landmarker instance with the video mode:
options = HolisticLandmarkerOptions(
    base_options=BaseOptions(model_asset_path="/data/Christian/MoCap/holistic_landmarker.task"),
    min_face_detection_confidence=0.8, 
    min_face_suppression_threshold=0.8, 
    min_face_landmarks_confidence=0.8, 
    min_pose_detection_confidence=0.8, 
    min_pose_suppression_threshold=0.8, 
    min_pose_landmarks_confidence=0.8, 
    min_hand_landmarks_confidence=0.8, 
    output_face_blendshapes=True,
    running_mode=VisionRunningMode.VIDEO)


input_dir = r'/data/video' 

video_files = np.array(glob.glob(os.path.join(input_dir, "**",'*mp4'),recursive=True))
# Set mediapipe model

# Iterate through video_file (words)
for video_file in video_files:

    # Create a directory for the current word
    video_file_path = video_file[:video_file.rfind(os.sep)]
    outputName = video_file[video_file.rfind(
        os.sep)+1:video_file.rfind('video')]
    output_video_path = os.path.join(
        output_dir, video_file[video_file.rfind("/")+1:-4])
    subject = outputName[outputName.rfind(
        "sub-"):outputName.rfind("_ses")]
    session = outputName[outputName.rfind(
        "ses-"):outputName.find("_", outputName.find("_")+1)]

    if not os.path.exists(os.path.join(output_video_path, subject, session)):
        os.makedirs(os.path.join(output_video_path, subject,
                    session, '.video'), exist_ok=True)
        os.makedirs(os.path.join(output_video_path, subject,
                    session, 'motion'), exist_ok=True)

    video_path = os.path.join(video_file_path, video_file)
    
    with HolisticLandmarker.create_from_options(options) as holistic:
        # The landmarker is initialized. Use it here.
        # Read video and calculate duration
        cap = cv2.VideoCapture(video_path)

        # Saving Video-
        fps = int(cap.get(cv2.CAP_PROP_FPS))
        fourcc = cv2.VideoWriter_fourcc(*'mp4v')
        out = cv2.VideoWriter(os.path.join(output_video_path, subject, session, '.video', outputName +
                              'desc-overlayVideo_video.mov'), fourcc, fps, (int(cap.get(3)), int(cap.get(4))))
        # Initialize empty list for keypoints
        keypoints_list = []
        success = 1
        # Iterate through frames in the sequence
        while success:
            # Read video frame
            success, frame = cap.read()
            frame_timestamp_ms = int(cap.get(cv2.CAP_PROP_POS_MSEC))

            # Make detections and draw landmarks
            mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
            results = holistic.detect_for_video(mp_image, frame_timestamp_ms)

Here is the resulting error message:

I0000 00:00:1717520611.283032   68206 gl_context_egl.cc:85] Successfully initialized EGL. Major : 1 Minor: 5
I0000 00:00:1717520611.285679   70364 gl_context.cc:357] GL version: 3.2 (OpenGL ES 3.2 Mesa 23.2.1-1ubuntu3.1~22.04.2), renderer: llvmpipe (LLVM 15.0.7, 256 bits)


Fatal Python error: Aborted


Main thread:
Current thread 0x00007f0e2b8eb440 (most recent call first):
  File "/home/christian.schmitz/.conda/envs/MNI-mocap/lib/python3.8/site-packages/mediapipe/python/packet_getter.py", line 61 in get_proto
  File "/home/christian.schmitz/.conda/envs/MNI-mocap/lib/python3.8/site-packages/mediapipe/tasks/python/vision/holistic_landmarker.py", line 170 in _build_landmarker_result
  File "/home/christian.schmitz/.conda/envs/MNI-mocap/lib/python3.8/site-packages/mediapipe/tasks/python/vision/holistic_landmarker.py", line 535 in detect_for_video
  File "/tmp/ipykernel_68206/2139099985.py", line 103 in <module>


Restarting kernel...
 

New contributor

Christian Schmitz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật