DeepLabCut / napari-deeplabcut

a napari plugin for labeling and refining keypoint data within DeepLabCut projects
GNU Lesser General Public License v3.0
51 stars 22 forks source link

Cannot extract frames from AVI files #110

Closed GerrikLabra closed 4 months ago

GerrikLabra commented 8 months ago

I am trying to take extract frames from an AVI video I wrote using imageio, in the DLC GUI, but no frames are extracted. Could anyone help?

Here is basically how I write my images

from imageio import get_writer
video_file_path = camera_name + "/recordings/"+file_name+".avi"
writer=get_writer(video_file_path,mode="?")
open_camera()
for i in range (700):
   image_array=camera_grab()
   writer.append_data(cv2.cvtColor(image_array,cv2.COLOR_BAYER_RG2RGB))
close_camera()
writer.close()

Afte having collected about 700 frames at 608x608, I then open the latest version of DeepLabCut, and use the GUI via Anaconda Prompt window, ran as administrator.

opencv-python-4.9.0.80 ffmpeg is 1.4 (DEEPLABCUT) C:\Windows\system32>python -m deeplabcut Loading DLC 2.3.8... Starting GUI... I create my project, and copy the video files to the project folder. The videos are playable in VLC_windows, and windows media player. But the GUI won't extract them, I get this message.

image

Afterwhich, the labeled frame folder has the an empty folder for the video I tried to extract. Any help trying to extract the avi files correctly?

GerrikLabra commented 8 months ago

uploaded wrong video

MMathisLab commented 8 months ago

it looks like the file you are trying to upload is not an AVI but MOV; can you check that the terminal doesn't say any errors? The only classic issue is if you don't give the terminal admin rights, it cannot write to the new folder, or ffmpeg is not installed, but you would get a warning in the terminal!

GerrikLabra commented 8 months ago

Sorry, here is correct video. follow google drive link. https://drive.google.com/file/d/1qw0IAG2lJ_fcPIu7ftGtM9LMqvONSUow/view?usp=sharing

jeylau commented 6 months ago

@GerrikLabra, I looked at your video, and something is wrong with the metadata, as n_frames returns 0. All images are black too: is this the right color conversion cv2.COLOR_BAYER_RG2RGB? Is the image array of type np.uint8? I imagine this could be required by the writer. I am not familiar with the imageio writer, but if you want code that works and is used inside deeplabcut, you could use this class:

from deeplabcut.utils.video_processor import (
    VideoProcessorCV as vp,
) 

clip = vp(
    fname=video,
    sname=output_path,
    codec='mp4v',
    fps=fps,
)
for i in range(700):
    image_array = clip.load_frame()
    clip.save_frame(image_array)