Reputation: 1
I have a video that is over 1 hr long and has 110000+ frames. I am using the code below to analyze facial emotions in the video. However, the entire process takes too long and the estimated timeframe to complete this task is over 34 hrs! My question is the following: is there any way that I can speed up this process (e.g. by skipping frames? Analyzing every 3rd frame?)
Here is the code:
from fer import Video
from fer import FER
import os
import sys
import pandas as pd
location_videofile = "/Users/M/Desktop/videoplayback.mp4"
input_video = Video(location_videofile)
processing_data = input_video.analyze(face_detector, display=False)
Upvotes: 0
Views: 322
Reputation: 1322
Didn't see this explained in fer
's documentation explicitly, but if you look at the source code for the Video
object, analyze
accepts a bunch of keyword arguments. Source code is here https://github.com/justinshenk/fer/blob/master/src/fer/classes.py
and the relevant bit is:
def analyze(
self,
detector, # fer.FER instance
display: bool = False,
output: str = "csv",
frequency: Optional[int] = None,
max_results: int = None,
save_fps: Optional[int] = None,
video_id: Optional[str] = None,
save_frames: bool = True,
save_video: bool = True,
annotate_frames: bool = True,
zip_images: bool = True,
detection_box: Optional[dict] = None
) -> list:
"""Recognize facial expressions in video using `detector`.
Args:
detector (fer.FER): facial expression recognizer
display (bool): show images with cv2.imshow
output (str): csv or pandas
frequency (int): inference on every nth frame (higher number is faster)
max_results (int): number of frames to run inference before stopping
save_fps (bool): inference frequency = video fps // save_fps
video_id (str): filename for saving
save_frames (bool): saves frames to directory
save_videos (bool): saves output video
annotate_frames (bool): add emotion labels
zip_images (bool): compress output
detection_box (dict): dict with bounding box for subimage (xmin, xmax, ymin, ymax)
So looks like you can set use frequency
to sample less frequently, for example to sample every 3rd frame:
processing_data = input_video.analyze(face_detector, display=False, frequency=3)
Upvotes: 1