Home > vbmeg > functions > tool_box > dynamics_movie > movie > movie_combine.m

movie_combine

PURPOSE ^

Combine two avi files(bottom/right view) into single avi file with a

SYNOPSIS ^

function movie_combine(avi_lr_file, avi_tb_file, output_file, title_str, left_is_left)

DESCRIPTION ^

 Combine two avi files(bottom/right view) into single avi file with a
 title.
 [Usage]
    movie_combine(avi_right_file, avi_bottom_file, output_file[, title_str][,left_is_left]);
 [Input]
    avi_lr_file     : left/right view avi file.
    avi_tb_file     : top/bottom view avi file.
    output_file     : output avi file.
    title_str       : [optional] 
    left_is_left    : =  true : left side is 'L'. : top view
                      = false : left side is 'R'. : bottom view

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function movie_combine(avi_lr_file, avi_tb_file, output_file, title_str, left_is_left)
0002 % Combine two avi files(bottom/right view) into single avi file with a
0003 % title.
0004 % [Usage]
0005 %    movie_combine(avi_right_file, avi_bottom_file, output_file[, title_str][,left_is_left]);
0006 % [Input]
0007 %    avi_lr_file     : left/right view avi file.
0008 %    avi_tb_file     : top/bottom view avi file.
0009 %    output_file     : output avi file.
0010 %    title_str       : [optional]
0011 %    left_is_left    : =  true : left side is 'L'. : top view
0012 %                      = false : left side is 'R'. : bottom view
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 if ~exist('title_str', 'var')
0018     title_str = 'Right View/Bottom View';
0019 end
0020 if ~exist('left_is_left', 'var')
0021     left_is_left = true;
0022 end
0023 
0024 %
0025 % --- AVI Video files
0026 %
0027 if nargin < 2
0028     avi_dir = '\\cbi-data4\cbi-data4\rhayashi\dynamics_movie\face_naive\20151111\parm01\Sub10\movie';
0029     avi_tb_file = fullfile(avi_dir, 'bottom_view.avi');
0030     avi_lr_file   = fullfile(avi_dir, 'right_view.avi');
0031     disp('Example : ');
0032 end
0033 
0034 %
0035 % --- Read Video
0036 %
0037 disp(['avi file(left/right view) : ' avi_lr_file]);
0038 disp(['avi file(top/bottom view): ' avi_tb_file]);
0039 video_right  = VideoReader(avi_lr_file);
0040 video_bottom = VideoReader(avi_tb_file);
0041 
0042 vr_data = read(video_right);
0043 vb_data = read(video_bottom);
0044 
0045 %
0046 % ---- Figure setup
0047 %
0048 disp('Started to play video.');
0049 close all;
0050 h = figure;
0051 set(h, 'Unit', 'pixels');
0052 set(h, 'Position', [100, 200, 1280, 768]);
0053 set(h, 'Menubar', 'none');
0054 set(h, 'Color', 'k');
0055 
0056 
0057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0058 % RightView/BottomView Area
0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0060 h_axes_r = axes;
0061 h_axes_b = axes;
0062 
0063 %%%%%%%%%%%%%
0064 % Title
0065 %%%%%%%%%%%%%
0066 title_font_size = 25;
0067 h_title = axes; axis off;
0068 set(h_title, 'Units', 'pixels', 'Position', [70, 680, 1, 1]);
0069 title(h_title, title_str, 'FontSize', title_font_size, 'Color', [1 1 1], 'HorizontalAlignment', 'left');
0070                 
0071 %%%%%%%%%%%%%
0072 % L/R label
0073 %%%%%%%%%%%%%
0074 if left_is_left
0075     label_strL = 'L';
0076     label_strR = 'R';
0077 else
0078     label_strL = 'R';
0079     label_strR = 'L';
0080 end
0081 label_font_size = 25;
0082 
0083 h_labelL = axes; axis off;
0084 set(h_labelL, 'Units', 'pixels', 'Position', [680,380, 1, 1]);
0085 title(h_labelL, label_strL, 'FontSize', title_font_size, 'Color', [1,1,1], 'HorizontalAlignment', 'left');
0086 
0087 h_labelR = axes; axis off;
0088 set(h_labelR, 'Units', 'pixels', 'Position', [1190, 380, 1, 1]);
0089 title(h_labelR, label_strR, 'FontSize', title_font_size, 'Color', [1,1,1], 'HorizontalAlignment', 'left');
0090 
0091 %%%%%%%%%%%%%%%%
0092 % Create Frames
0093 %%%%%%%%%%%%%%%%
0094 numFrames = get(video_bottom, 'numberOfFrames');
0095 frames(numFrames) = struct('cdata', [], 'colormap', []); % pre-allocate
0096 
0097 
0098 for k=1:numFrames
0099     % plot right view
0100     cla(h_axes_r);
0101     image(vr_data(:, :, :, k), 'Parent', h_axes_r);
0102     set(h_axes_r, 'Unit', 'pixels');
0103     set(h_axes_r, 'Position', [-70, -20, video_right.Width, video_right.Height]);
0104     axis(h_axes_r, 'off');
0105     if nargin <= 2
0106         pause(0.03);
0107     end
0108 
0109     % plot bottom view
0110     cla(h_axes_b); 
0111     set(h_axes_b, 'Unit', 'pixels');
0112     image(vb_data(:, :, :, k), 'Parent', h_axes_b);
0113     set(h_axes_b, 'Position', [550, -20,video_bottom.Width, video_bottom.Height]);
0114     axis(h_axes_b, 'off');
0115     drawnow;
0116     frames(k) = getframe(h);
0117 end
0118 
0119 %
0120 % --- Write AVI file
0121 %
0122 if exist('output_file', 'var') && ~isempty(output_file)
0123     writer = VideoWriter(output_file);
0124     % set Frame Rate, Quality
0125     writer.FrameRate = video_bottom.FrameRate;
0126     writer.Quality   = 100;
0127     open(writer);
0128 
0129     disp('saving video...');
0130     writeVideo(writer, frames);
0131     close(writer);
0132     disp(['avi file(combined): ' output_file]);
0133 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005