我在使用最新版本的 openCV 打开和阅读 1 分钟的 avi 视频时遇到问题。我用 PuTTY 安装了它,因为我实际上是在虚拟机上工作。 相同的代码适用于 Google Colab
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print(f"Error opening video file: {video_path}")
return
在虚拟机上时我收到此错误:
Unexpected list type. Expected: hdrl. Got: movi.
我用过
(venv) ubuntu@bellizzi:~/data/ecg-fitness_raw-v1.0$ ffprobe /home/ubuntu/data/ecg-fitness_raw-v1.0/10/01/c920-1.avi ffprobe version 3.4.11-0ubuntu0.1 Copyright (c) 2007-2022 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, avi, from '/home/ubuntu/data/ecg-fitness_raw-v1.0/10/01/c920-1.avi':
Metadata:
encoder : Lavf57.56.100
Duration: 00:01:00.00, start: 0.000000, bitrate: 746501 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 746910 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
查看编解码器,它是 openCV 可读的格式。 我检查了视频是否已损坏,但没有。是AVI格式还是其他格式?
提前感谢您的帮助
我检查了视频是否已损坏,但没有。是AVI格式还是其他格式?
提前感谢您的帮助
我将分享更多有关该功能的代码
def process_video(video_path, video_csv_path, face_detector):
try:
# Initialize video capture
cap = cv2.VideoCapture(video_path)
print(video_path)
if not cap.isOpened():
print(f"Error opening video file: {video_path}")
return
rois_list = []
resized_rois = []
# Read the first frame
ret, frame = cap.read()
# List to save face regions frame by frame
face_regions = []
# Calculate the total number of frames in the video
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
frame_rate = cap.get(cv2.CAP_PROP_FPS)
# Limit the number of frames to analyze
max_time_to_analyze_seconds = 15 # Adjust the desired time duration in seconds
max_frames_to_analyze = int(max_time_to_analyze_seconds * frame_rate)
df = pd.read_csv(video_csv_path)
# Filtra il DataFrame per ottenere solo le righe entro i primi tot secondi
df = df[df['milliseconds'] <= max_time_to_analyze_seconds * 1000]
# Create a progress bar
progress_bar = tqdm(total=min(total_frames, max_frames_to_analyze), position=0, leave=True,
desc=f'Processing Frames for {video_path}')
frame_count = 0
while True:
ret, frame = cap.read()
if not ret or frame_count >= max_frames_to_analyze:
break
frame = cv2.resize(frame, (300,200))
# Detect faces in the frame
faces = face_detector(frame, 1)
if faces:
# Use only the first detected face
face = faces[0]
landmarks = landmark_predictor(frame, face.rect)
face_region = extract_face_region(frame, landmarks)
if face_region is not None:
rois_list.append(face_region)
#for i, face_region in enumerate(rois_list):
#plt.figure()
#plt.imshow(face_region)
#plt.show()
progress_bar.update(1)
frame_count += 1
progress_bar.close()
print(f"Video analyzed for {video_path}")
current_dataset = CustomDataset(rois_list, df) # Assuming CustomDataset is defined somewhere in your code
return current_dataset
except Exception as e:
print(f"Error processing video: {video_path}. Error details: {str(e)}")
return None # Returning None to indicate an error
finally:
cap.release()