0

I wanted to capture images from a video file using OPEN CV and I found this link https://stackoverflow.com/a/30136402/15916156 here's the code

import os

def video_to_frames(video, path_output_dir):
    # extract frames from a video and save to directory as 'x.png' where 
    # x is the frame index
    vidcap = cv2.VideoCapture(video)
    count = 0
    while vidcap.isOpened():
        success, image = vidcap.read()
        if success:
            cv2.imwrite(os.path.join(path_output_dir, '%d.png') % count, image)
            count += 1
        else:
            break
    cv2.destroyAllWindows()
    vidcap.release()

video_to_frames('../somepath/myvid.mp4', '../somepath/out')

now I want to have the same name, as the video name with concatenated numbers of frames. How should I change the code?

Pegtomous
  • 79
  • 6
  • pls try the options listed in [CAP_PROP_POS_MSEC](https://stackoverflow.com/questions/33311153/python-extracting-and-saving-video-frames) – simpleApp Jan 06 '22 at 14:01

1 Answers1

1

Check string split method where you can break a string using some characters.

For instance video.split('/')[-1] might get you the filename.

Make it equal to filename = video.split('/')[-1] and add it to:

((path_output_dir, filename + '%d.png') % count, image))

pedro_bb7
  • 1,601
  • 3
  • 12
  • 28