clc ;
clear ;

fname = 'Bal256x192_8views_t0.yuv' ;
%fid = fopen('Bal256x192_compare_final.yuv','w') ;
index = 1 ;
for i = 1 : 7
    [Y U V] = read_ith_GOP_keyframe(i-1,1,256,192,fname) ;
    Y_img = [Y Y] ;
    U = imresize(U, 2, 'bilinear');
    V = imresize(V, 2, 'bilinear');
    U_img = [U U] ;
    V_img = [V V] ;
    frame(:,:,1) = Y_img ; frame(:,:,2) = U_img ; frame(:,:,3) = V_img ;
    frame_rgb = ycbcr2rgb(frame/255);
    M(index)=im2frame(frame_rgb);
    index = index + 1 ;
%    s = ['load novel_view_' num2str(i+30) ' ;'] ;
    s = ['load optimized_view_' num2str(i+1000) ' ;'] ;
    eval(s) ;
    Y_img = [Y nv_from1and2_Y] ;
    nv_from1and2_U = imresize(nv_from1and2_U, 2, 'bilinear');
    nv_from1and2_V = imresize(nv_from1and2_V, 2, 'bilinear');
    U_img = [U nv_from1and2_U] ;
    V_img = [V nv_from1and2_V] ;
    frame(:,:,1) = Y_img ; frame(:,:,2) = U_img ; frame(:,:,3) = V_img ;
    frame_rgb = ycbcr2rgb(frame/255);
    M(index)=im2frame(frame_rgb);
    index = index + 1 ;
end
[Y U V] = read_ith_GOP_keyframe(7,1,256,192,fname) ;
Y_img = [Y Y] ;
U = imresize(U, 2, 'bilinear');
V = imresize(V, 2, 'bilinear');
U_img = [U U] ;
V_img = [V V] ;
frame(:,:,1) = Y_img ; frame(:,:,2) = U_img ; frame(:,:,3) = V_img ;
frame_rgb = ycbcr2rgb(frame/255);
M(index)=im2frame(frame_rgb);
avi_filename = 'Bal256x192_fps8.avi' ;
movie2avi(M, avi_filename, 'compression', 'none', 'fps',8);
avi_filename = 'Bal256x192_fps1.avi' ;
movie2avi(M, avi_filename, 'compression', 'none', 'fps',1);
avi_filename = 'Bal256x192_fps10.avi' ;
movie2avi(M, avi_filename, 'compression', 'none', 'fps',10);
avi_filename = 'Bal256x192_fps12.avi' ;
movie2avi(M, avi_filename, 'compression', 'none', 'fps',12);



