parkpow / deep-license-plate-recognition

Automatic License Plate Recognition (ALPR) or Automatic Number Plate Recognition (ANPR) software that works with any camera.
https://platerecognizer.com/
MIT License
523 stars 122 forks source link

Response to the use of ffmpegcv in the code #174

Closed chenxinfeng4 closed 8 months ago

chenxinfeng4 commented 8 months ago

Hi, dear developer. I'm the author of ffmpegcv, I'm searching the usage cases of the ffmpegcv and appreciate your project for recognition software. As the project refer the ffmpegcv, and comment:

video-editor/video_editor.py: grayscale videos are not supported by ffmpegcv

The ffmpegcv supports 'gray scale' already, and it's faster than reading bgr/rgb.

cap = ffmpegcv.VideoCapture(video_path, pix_fmt='gray')
ret, frame = cap.read()
frame.shape #(H,W,1)
frame  = np.squeeze(frame)  #(H,W)

ffmpegcv cap.fps is not reliable calculate FPS

The ffmpegcv and the opencv read the fps from the video properties. Loop the whole video file is not efficient. Would you be more specific in your case?

chenxinfeng4 commented 8 months ago

Try the lastest version of ffmpegcv by pip install git+https://github.com/chenxinfeng4/ffmpegcv.git. It supports more precise video-duration and average-fps.

In [1]: import ffmpegcv

# MKV file. Duration should be 283.682
In [2]: ffmpegcv.video_info.get_info_precise('2024-01-18_09-57-41_cam4.mkv')
Out[2]: VideoInfo(width=2560, height=1440, fps=25.007, count=7094, codec='hevc', duration=283.682)

In [3]: ffmpegcv.video_info.get_info('2024-01-18_09-57-41_cam4.mkv')
Out[3]: VideoInfo(width=2560, height=1440, fps=25.0, count=7094, codec='hevc', duration=283.76)

# identical file in MP4 format. Duration should be 283.682
In [4]: ffmpegcv.video_info.get_info('2024-01-18_09-57-41_cam4.mp4')
Out[4]: VideoInfo(width=2560, height=1440, fps=25.0, count=7094, codec='hevc', duration=283.682)

In [5]: ffmpegcv.video_info.get_info_precise('2024-01-18_09-57-41_cam4.mp4')
Out[5]: VideoInfo(width=2560, height=1440, fps=25.007, count=7094, codec='hevc', duration=283.682)

The ffmpegcv get_info_precise will get the precise duration by calculating the time stamp of the first and last frame WITHOUT DECODING THE STREAM.

cmd = ('ffprobe -v error -select_streams v:0 -show_entries frame=pts_time '
           f' -of default=noprint_wrappers=1:nokey=1 -read_intervals 0%+#1,99999% "{video}"')

Since the get_info_precise would take a bit more time than get_info, so the ffmpeg.VideoCapture will use get_info for general cases. Even though, the get_info_precise is much more effient than looping in opencv.

danleyb2 commented 8 months ago

Hello @chenxinfeng4

  1. We had resolved the gray scale bug by doing an ffmpegcv upgrade
  2. For FPS we are calculating it manually by counting frames for 500ms using fps_cap.get(cv2.CAP_PROP_POS_MSEC) it works okay for RTSP too. Which i don't think reading last frame with fprobe will work

Thanks for your comments.