"""
After moving all the files using the 1_ file, we run this one to extract
the images from the videos and also create a data file we can use
for training and testing later.
"""
import csv
import glob
import os
import os.path
import subprocess
from subprocess import call
def extract_files():
"""After we have all of our videos split between train and test, and
all nested within folders representing their classes, we need to
make a data file that we can reference when training our RNN(s).
This will let us keep track of image sequences and other parts
of the training process.
We'll first need to extract images from each of the videos. We'll
need to record the following data in the file:
[train|test], class, filename, nb frames
Extracting can be done with ffmpeg:
`ffmpeg -i video.mpg image-%04d.jpg`
"""
data_file = []
folders = ['E:/Graduation Project/UCF-101_video_classification-master/data/train/', 'E:/Graduation Project/UCF-101_video_classification-master/data/test/']
for folder in folders:
class_folders = glob.glob(folder + '*')
for vid_class in class_folders:
class_files = glob.glob(vid_class + '/*.avi')
for video_path in class_files:
# Get the parts of the file.
video_parts = get_video_parts(video_path)
train_or_test, classname, filename_no_ext, filename = video_parts
# Only extract if we haven't done it yet. Otherwise, just get
# the info.
if not check_already_extracted(video_parts):
# Now extract it.
src = train_or_test + '/' + classname + '/' + \
filename
dest = train_or_test + '/' + classname + '/' + \
filename_no_ext + '-%04d.jpg'
subprocess.call(["ffmpeg", "-i", src, dest])
# Now get how many frames it is.
nb_frames = get_nb_frames_for_video(video_parts)
data_file.append([train_or_test, classname, filename_no_ext, nb_frames])
print("Generated %d frames for %s" % (nb_frames, filename_no_ext))
运行结果:
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Generated 0 frames for data
'ffmpeg' �����ڲ����ⲿ���Ҳ���ǿ����еij���
一堆这个东西。根据代码最后一行,说明没有成功从视频中提取帧,所以能帮忙看看哪里的问题吗?