-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo_compute_RAPIQUE_feats.m
111 lines (97 loc) · 3.85 KB
/
demo_compute_RAPIQUE_feats.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
%%
% Compute features for a set of video files from datasets
%
close all;
clear;
% add path
addpath(genpath('include'));
%%
% parameters
algo_name = 'RAPIQUE'; % algorithm name, eg, 'V-BLIINDS'
data_name = 'LIVE_VQA'; % dataset name, eg, 'KONVID_1K'
write_file = true; % if true, save features on-the-fly
log_level = 0; % 1=verbose, 0=quite
if strcmp(data_name, 'KONVID_1K')
root_path = '/media/ztu/Seagate-ztu-ugc/KONVID_1K/';
data_path = '/media/ztu/Seagate-ztu-ugc/KONVID_1K/KoNViD_1k_videos';
elseif strcmp(data_name, 'LIVE_VQC')
root_path = '/media/ztu/Seagate-ztu-ugc/LIVE_VQC/';
data_path = '/media/ztu/Seagate-ztu-ugc/LIVE_VQC/VideoDatabase';
elseif strcmp(data_name, 'YOUTUBE_UGC')
root_path = '/media/ztu/Seagate-ztu-ugc/YT_UGC';
data_path = '/media/ztu/Seagate-ztu-ugc/YT_UGC/original_videos';
elseif strcmp(data_name, 'LIVE_HFR')
root_path = '/media/ztu/Seagate-ztu/LIVE_HFR';
data_path = '/media/ztu/Seagate-ztu/LIVE_HFR';
elseif strcmp(data_name, 'LIVE_VQA')
root_path = '/media/ztu/Seagate-ztu/LIVE_VQA';
data_path = '/media/ztu/Seagate-ztu/LIVE_VQA/videos';
end
%%
% create temp dir to store decoded videos
video_tmp = '/media/ztu/Data/tmp';
if ~exist(video_tmp, 'dir'), mkdir(video_tmp); end
feat_path = 'mos_files';
filelist_csv = fullfile(feat_path, [data_name,'_metadata.csv']);
filelist = readtable(filelist_csv);
num_videos = size(filelist,1);
out_path = 'feat_files';
if ~exist(out_path, 'dir'), mkdir(out_path); end
out_mat_name = fullfile(out_path, [data_name,'_',algo_name,'_feats.mat']);
feats_mat = [];
feats_mat_frames = cell(num_videos, 1);
%===================================================
% init deep learning models
minside = 512.0;
net = resnet50;
layer = 'avg_pool';
%% extract features
% parfor i = 1:num_videos % for parallel speedup
for i = 1:num_videos
progressbar(i/num_videos) % Update figure
if strcmp(data_name, 'KONVID_1K')
video_name = fullfile(data_path, ...
[num2str(filelist.flickr_id(i)),'.mp4']);
yuv_name = fullfile(video_tmp, [num2str(filelist.flickr_id(i)), '.yuv']);
elseif strcmp(data_name, 'LIVE_VQC')
video_name = fullfile(data_path, filelist.File{i});
yuv_name = fullfile(video_tmp, [filelist.File{i}, '.yuv']);
elseif strcmp(data_name, 'YOUTUBE_UGC')
video_name = fullfile(data_path, filelist.category{i}, ...
[num2str(filelist.resolution(i)),'P'],[filelist.vid{i},'.mkv']);
yuv_name = fullfile(video_tmp, [filelist.vid{i}, '.yuv']);
elseif strcmp(data_name, 'LIVE_HFR')
strs = strsplit(filelist.Filename{i}, '_');
video_name = fullfile(data_path,strs{1},[filelist.Filename{i},'.webm']);
yuv_name = fullfile(video_tmp, [filelist.Filename{i}, '.yuv']);
elseif strcmp(data_name, 'LIVE_VQA')
strs = strsplit(filelist.filename{i}, '_');
video_name = fullfile(data_path, [strs{1}(1:2), '_Folder'], filelist.filename{i});
yuv_name = video_name;
end
fprintf('\n\nComputing features for %d sequence: %s\n', i, video_name);
% decode video and store in temp dir
if ~strcmp(video_name, yuv_name)
cmd = ['ffmpeg -loglevel error -y -i ', video_name, ...
' -pix_fmt yuv420p -vsync 0 ', yuv_name];
system(cmd);
end
% get video meta data
width = filelist.width(i);
height = filelist.height(i);
framerate = round(filelist.framerate(i));
% calculate video features
tStart = tic;
feats_frames = calc_RAPIQUE_features(yuv_name, width, height, ...
framerate, minside, net, layer, log_level);
fprintf('\nOverall %f seconds elapsed...', toc(tStart));
%
feats_mat(i,:) = nanmean(feats_frames);
feats_mat_frames{i} = feats_frames;
% clear cache
delete(yuv_name)
if write_file
save(out_mat_name, 'feats_mat');
% save(out_mat_name, 'feats_mat', 'feats_mat_frames');
end
end