moov原子未找到(从youtube视频中提取唯一的面孔)



我得到了下面的错误

Saved 0 unique faces
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000024f505224c0] moov atom not found

试图从YouTube视频中提取独特的面孔,下面的代码旨在下载YouTube视频并提取独特的面孔到一个名为faces的文件夹中。视频和文件夹都是空的。请检查下面的Python代码

import os
import urllib.request
import cv2
import face_recognition
import numpy as np
# Step 1: Download the YouTube video
video_url = "https://www.youtube.com/watch?v=JriaiYZZhbY&t=4s"
urllib.request.urlretrieve(video_url, "video.mp4")
# Step 2: Extract frames from the video
cap = cv2.VideoCapture("video.mp4")
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
frames = []
for i in range(frame_count):
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
ret, frame = cap.read()
if ret:
frames.append(frame)
cap.release()
# Step 3: Detect faces in the frames
detected_faces = []
for i, frame in enumerate(frames):
face_locations = face_recognition.face_locations(frame)
for j, location in enumerate(face_locations):
top, right, bottom, left = location
face_image = frame[top:bottom, left:right]
cv2.imwrite(f"detected_{i}_{j}.jpg", face_image)
detected_faces.append(face_image)
# Step 4: Save the faces as separate images
if not os.path.exists("faces"):
os.makedirs("faces")
known_faces = []
for i in range(len(detected_faces)):
face_image = detected_faces[i]
face_encoding = face_recognition.face_encodings(face_image)[0]
known_faces.append(face_encoding)
cv2.imwrite(f"faces/face_{i}.jpg", face_image)
print("Saved", len(known_faces), "unique faces")

你的文件不是mp4/mov文件

这是一个网页,不是视频文件。

你不能像那样下载一个YouTube网页,然后期望收到一个视频文件。

最新更新