图片取帧

def frame_process(vis):
input_path, video_name = vis
out_path = os.path.join(input_path, 'frame')
image_path = os.path.join(out_path, video_name[:-4])
if not os.path.exists(image_path):
os.makedirs(image_path)

im_num = 0
cap = cv2.VideoCapture(os.path.join(input_path, video_name))

while True:
    ret, frame = cap.read()
    if ret:
        cv2.imwrite(image_path + '/' + '{:06d}.jpg'.format(im_num), frame)
        im_num += 1
    else:
        break

if os.path.isfile(root_path):
file_list = [root_path]
else:
file_list = os.listdir(root_path)

vis_list = []
for i in file_list:
if not i.endswith('mp4'):
continue

if os.path.isfile(i):
    data = os.path.split(i)
    vis_list.append(data)
    break

data = (file_list, i)
vis_list.append(data)

for vis in vis_list:
print(vis)
frame_process(vis)

import os

print(os.name,)

print(os.getcwd)

print(os.listdir("../"))

print(os.remove("./hello.py"))

os.remove("./h.py")

print(os.remove("./h.py"))

print(os.rmdir("./test"))

os.system("echo 'this is a string' ")

print(os.path.abspath('./test'))

print(os.path.split('./test/te.py'))

print(os.path.dirname('./test/te.py'))

os.system('cd /data/web/xhs ; mkdir aaa')

BASE_DIR = os.path.dirname(os.path.abspath(file))

MEDIA_ROOT = os.path.join(BASE_DIR,'media')

print(BASE_DIR)

print(MEDIA_ROOT)

print(os.path.abspath(file))

你可能感兴趣的:(图片取帧)