Changeset 26865
- Timestamp:
- 02/09/22 05:37:44 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_transient_movie.m
r25502 r26865 42 42 end 43 43 44 %Do we have an output? 45 isavi = 0; 46 isgif = 0; 47 ismp4 = 0; 48 if exist(options,'transient_movie_output'), 49 filename=getfieldvalue(options,'transient_movie_output'); 50 [pathstr,name,ext] = fileparts(filename); 51 if strcmp(ext,'.gif') 52 isgif = 1; 53 elseif strcmp(ext,'.mp4') 54 ismp4 = 1; 55 elseif strcmp(ext,'.avi') 56 isavi = 1; 57 end 58 end 59 if isavi || ismp4 60 vid=VideoWriter([filename(1:end-4),'.avi'],'Motion JPEG AVI'); 61 vid.FrameRate = 2; 62 open(vid); 63 end 64 44 65 %calculate caxis 45 66 if ~exist(options,'caxis'), … … 53 74 end 54 75 76 77 %Process mesh once for all 78 [x y z elements is2d isplanet]=processmesh(md,results(i).(field),options); 79 55 80 %display movie 56 81 nstep=1; … … 60 85 if ~isempty(results(i).(field)), 61 86 %process data 62 [x y z elements is2d isplanet]=processmesh(md,results(i).(field),options);63 87 [data datatype]=processdata(md,results(i).(field),options); 64 88 65 89 clf; 66 titlestring=[field ' at time ' num2str(results(i).time,'%7.2f') ' year'];90 titlestring=[field ' (time ' num2str(results(i).time,'%7.2f') ' yr)']; 67 91 plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options) 68 92 apply_options_movie(md,options,titlestring); 69 93 70 if exist(options,'transient_movie_output'), 71 set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version) 94 %Add grounding line 95 if exist(options,'groundingline') 96 contours=isoline(md, results(i).MaskOceanLevelset,'output','matrix'); 97 hold on 98 plot(contours(:,1),contours(:,2),getfieldvalue(options,'groundingline')); 99 end 100 101 %Add ice front 102 if exist(options,'icefront') 103 contours=isoline(md, results(i).MaskIceLevelset,'output','matrix'); 104 hold on 105 plot(contours(:,1),contours(:,2),getfieldvalue(options,'icefront')); 106 end 107 108 if isgif 109 frame=getframe(gcf); 110 im = frame2im(frame); 111 [imind,cmap] = rgb2ind(im,256); 112 if i==1 113 imwrite(imind, cmap, filename, 'DelayTime',getfieldvalue(options,'transient_movie_time',.5), 'LoopCount',inf) 114 else 115 imwrite(imind, cmap, filename, 'WriteMode','append'); 116 end 117 elseif isavi || ismp4 118 F=getframe(gcf); 119 writeVideo(vid, F); 120 end 121 122 if exist(options,'transient_movie_output') 123 %set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version) 72 124 if nstep==1, 73 125 %initialize images and frame … … 87 139 88 140 %output movie if requested. 89 if exist(options,'transient_movie_output'), 90 filename=getfieldvalue(options,'transient_movie_output'); 91 imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',2),'LoopCount',inf) 141 if isavi || ismp4 142 close(vid); 143 end 144 if ismp4 145 while(~exist([filename])) 146 disp(['Waiting for ' filename ]); 147 pause(1) 148 end 149 filename = filename(1:end-4); 150 command=sprintf('ffmpeg -y -i %s.avi -c:v libx264 -crf 19 -preset slow -c:a libfaac -b:a 192k -ac 2 %s.mp4',filename,filename); 151 system(command); 152 filename = [filename '.mp4']; 153 disp(['Movie saved also as ' filename]); 154 end 155 if isgif 156 imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',.5),'LoopCount',inf) 92 157 end 93 158
Note:
See TracChangeset
for help on using the changeset viewer.