main44gray.m
上传用户:cxsjwj
上传日期:2022-08-09
资源大小:34k
文件大小:6k
源码类别:

matlab例程

开发平台:

Matlab

  1. close all
  2. clc
  3. tic
  4. gray
  5. prinf(resize,long,wide)
  6. startframe
  7. endframe
  8. aviobj = avifile('2.avi','fps',25,'COMPRESSION','None');
  9. %motion Vectors
  10. motionVect=zeros(2,256);
  11. fid=fopen('Qtable2.txt','r');
  12. %array is quantization matrix
  13. array=fscanf(fid,'%e',[8,inf]);
  14. %array=2*array;
  15. array=array;
  16. i = 0;
  17. %flag to tell if B frame was predicted from I or P frame flag=1 P frame
  18. %flag=0 I frame
  19. flag=2;
  20. %GOP is of 10 pictures IBBPBBPBBI
  21. mov=aviread('news.avi');
  22. movinfo=aviinfo('news.avi');
  23. noframe=movinfo.NumFrames;
  24. %mbSize macroblock size used for motion estimation
  25. mbSize = 8;
  26. %p for search area
  27. p = 7;
  28. global I1d P4d P7d I10d B2d B3d B5d B6d B8d B9d
  29. for i=startframe:10:endframe
  30.     i
  31. framedata=aviread('news.avi',i);
  32. I1=frame2im(framedata);
  33. if resize==1
  34.     I1=imresize(I1,[long,wide]);
  35.     end
  36. I1=rgb2gray(I1);
  37. I1=double(I1);
  38. JQ=forwardDCT(I1,array);
  39. bufferI1 = inverseDCT(JQ,array);
  40. c= makeLayers(JQ);
  41. %%calling decoder
  42. identifier=1;
  43. decoder(c,motionVect,identifier,flag);
  44. %%%this loop is for accessing frame from actual movie
  45.     if i~=1
  46.         j=i-round(i/10);
  47.         [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(j,resize,long,wide);
  48.     elseif i==1
  49.         j=i;
  50.         [B2,B3,P4,B5,B6,P7,B8,B9,I10]=GOP(j,resize,long,wide);
  51.     end
  52.         %processing on P4 frame
  53.         [bufferP4,streamP4,motionVect]=compensatedFrame(P4,bufferI1,mbSize,p,array); 
  54.         c= makeLayers(streamP4);
  55.         %calling decoder
  56.         identifier=4;
  57.         %decoder(diffDC,valVectorBase,lenVectorBase,valVectorEnhan,lenVectorEnhan,identifier,flag,motionVect);
  58.         decoder(c,motionVect,identifier,flag);
  59. % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
  60.         
  61.         %for B2    
  62.         [B2t ,motionVect, flag] = bFrameProc(B2,bufferI1,bufferP4,0.5*array,mbSize,p);
  63.         c= makeLayers(B2t);
  64.         
  65.         %calling decoder
  66.         identifier=2;
  67.         decoder(c,motionVect,identifier,flag);
  68.         
  69.         %for B3    
  70.         [B3t ,motionVect ,flag] = bFrameProc(B3,bufferI1,bufferP4,0.5*array,mbSize,p);
  71.         c= makeLayers(B3t);
  72.         
  73.         %calling decoder
  74.         identifier=3;
  75.         decoder(c,motionVect,identifier,flag);
  76.  
  77.         %predicting p7 from p4
  78.         [bufferP7,streamP7,motionVect]=compensatedFrame(P7,bufferP4,mbSize,p,array);
  79.         c= makeLayers(streamP7);
  80.         
  81.         %calling decoder
  82.         identifier=7;
  83.         decoder(c,motionVect,identifier,flag);
  84. %          
  85.         %for B5    
  86.         [B5t motionVect flag] = bFrameProc(B5,bufferP4,bufferP7,0.5*array,mbSize,p);
  87.         c= makeLayers(B5t);
  88.         
  89.         %calling decoder
  90.         identifier=5;
  91.         decoder(c,motionVect,identifier,flag);
  92.    
  93.         %for B6    
  94.         [B6t motionVect flag] = bFrameProc(B6,bufferP4,bufferP7,0.5*array,mbSize,p);
  95.         c= makeLayers(B6t);
  96.         
  97.         %calling decoder
  98.         identifier=6;
  99.         decoder(c,motionVect,identifier,flag);
  100.  
  101.         %processing on I10 frame
  102.         streamI10=forwardDCT(I10,array);
  103.         bufferI10 = inverseDCT(streamI10,array);
  104.         c= makeLayers(streamI10);
  105.         %%calling decoder
  106.         identifier=10;
  107.         decoder(c,motionVect,identifier,flag);
  108. %         
  109.         %for B8    
  110.         [B8t motionVect flag] = bFrameProc(B8,bufferP7,bufferI10,0.5*array,mbSize,p);
  111.         c= makeLayers(B8t);
  112.         
  113.         %calling decoder
  114.         identifier=8;
  115.         decoder(c,motionVect,identifier,flag);
  116.         %for B9    
  117.         [B9t motionVect flag] = bFrameProc(B9,bufferP7,bufferI10,0.5*array,mbSize,p);
  118.         c= makeLayers(B9t);
  119.         
  120.         %calling decoder
  121.         identifier=9;
  122.         decoder(c,motionVect,identifier,flag);
  123.     
  124. %         
  125. %         
  126.         
  127. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  128.         
  129.     
  130.         if i==1
  131.                 imshow(uint8(I1d))
  132.                 aviobj = addframe(aviobj,getframe);
  133.                 clf;
  134.                 
  135.                 imshow(uint8(B2d))
  136.                 aviobj = addframe(aviobj,getframe);
  137.                 clf;
  138.                 
  139.                 imshow(uint8(B3d))
  140.                 aviobj = addframe(aviobj,getframe);
  141.                 clf;
  142.                 
  143.                 imshow(uint8(P4d))
  144.                 aviobj = addframe(aviobj,getframe);
  145.                 clf;
  146.                 
  147.                 imshow(uint8(B5d))
  148.                 aviobj = addframe(aviobj,getframe);
  149.                 clf;
  150.                 
  151.                 imshow(uint8(B6d))
  152.                 aviobj = addframe(aviobj,getframe);
  153.                 clf;
  154.                 
  155.                 imshow(uint8(P7d))
  156.                 aviobj = addframe(aviobj,getframe);
  157.                 clf;
  158.                 
  159.                 imshow(uint8(B8d))
  160.                 aviobj = addframe(aviobj,getframe);
  161.                 clf;
  162.                 
  163.                 imshow(uint8(B9d))
  164.                 aviobj = addframe(aviobj,getframe);
  165.                 clf;
  166.                 
  167.                 imshow(uint8(I10d))
  168.                 aviobj = addframe(aviobj,getframe); 
  169.                 clf;
  170.             else
  171.                 
  172.                 imshow(uint8(B2d))
  173.                 aviobj = addframe(aviobj,getframe);
  174.                 clf;
  175.                 
  176.                 imshow(uint8(B3d))
  177.                 aviobj = addframe(aviobj,getframe);
  178.                 clf;
  179.                 
  180.                 imshow(uint8(P4d))
  181.                 aviobj = addframe(aviobj,getframe);
  182.                 clf;
  183.                 
  184.                 imshow(uint8(B5d))
  185.                 aviobj = addframe(aviobj,getframe);
  186.                 clf;
  187.                 
  188.                 imshow(uint8(B6d))
  189.                 aviobj = addframe(aviobj,getframe);
  190.                 clf;
  191.                 
  192.                 imshow(uint8(P7d))
  193.                 aviobj = addframe(aviobj,getframe);
  194.                 clf;
  195.                 
  196.                 imshow(uint8(B8d))
  197.                 aviobj = addframe(aviobj,getframe);
  198.                 clf;
  199.                 
  200.                 imshow(uint8(B9d))
  201.                 aviobj = addframe(aviobj,getframe);
  202.                 clf;
  203.                 
  204.                 imshow(uint8(I10d))
  205.                 aviobj = addframe(aviobj,getframe);
  206.                 clf;
  207.             end
  208.            
  209. end
  210. aviobj = close(aviobj);
  211. toc