Opencv-Python: median value with mpg video

import numpy as np
import cv2

cap = cv2.VideoCapture(‘test/Walk1.mpg’)
frame_indices = range(Total_frame)

frames =

for idx in frame_indices:
cap.set(cv2.CAP_PROP_POS_FRAMES, idx)
ret, frame =

median_frame = np.median(frames, axis=0).astype(np.uint8)

while cap.isOpened():

ret, frame =

if cv2.waitKey(42) == ord('q'):


i can calculate median value of frames when the input is mp4 video, but i can’t when the input is mpg video. The error message is as below.

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify ‘dtype=object’ when creating the ndarray.
a = np.asanyarray(a)

i guess ‘np.median’ is not working when the input is mpg video. How can i do for it?