Error using VideoWriter/writeVideo (line 344) Frame must be 2560 by 1360 - Help

5 visualizaciones (últimos 30 días)
Hey,
This is my code for writing a video that syncronizes my data plot with the behavior video. I keep getting this error and I dont know how to fix it.
VID = VideoReader('Trial-12.m4v');
%Creat matlab structure to make a new video
v = VideoWriter('ko_base_livetrace.m4v','MPEG-4');
%Frame rate of the video you are reading
fps_vid = VID.frameRate;
%Frame rate of FP data
fps_data = signal.sampling_rate;
%How long you want new video to be
vid_duration = VID.duration;
%Frame rate of created video will be the frame rate of the behavior video
%v.FrameRate = fps_vid/300;
v.FrameRate = (floor((VID.NumberOfFrames/5))+1)/vid_duration;
%Number of frames in this new video
vid_frames = floor(vid_duration * fps_vid);
%Open the new video for writing
open(v);
%Create a structure to hold the FP trace data as needed as you generate frames
dataNeeded = [];
%Create a list of the times to pull from for x-axis of plot.
times= [1/fps_data:1/fps_data:(fps_data*vid_duration)]';
%The time in the behavior video you want to be the start of the new video.
startTime = 0;
%Find which frame this is in the video
frameStart = startTime*fps_vid+1;
%The location in FP data trace will always start from when plotting during
%video (just the start time in the FP data)
minPoint = (startTime)*fps_data + 1;
minD = -2 %floor(min(deltaFTrialTwo(minPoint:vid_duration*fps_data))*100);
maxD = 4 %ceil(max(deltaFTrialTwo(minPoint:vid_duration*fps_data))*100);
%Loop through frame by frame of behavior video, create matlab figure
%displaying that frame of video plus a plot of FP data up to that time
%point. Then save as a frame of new video.
frameCount = 0;
for n = frameStart:5:(frameStart+vid_frames)
%Create new figure
p = figure(1);
set(gcf,'color','w');
%Set the dimensions of the figure to be the size of your monitor
set(p, 'Position', [1 1 1920 980])
%Create new subplot location and fill with current berhavior video
%frame.
subplot('Position',[0.05 0.5 .9 0.6])
imshow(read(VID,n));
%Create new subplot for FP trace
s = subplot(2,1,2);
%Data needed for this frame for FP plot, is all data from minPoint to
%current time.
%THIS IS ALTERED TO SUBTRACT 1 SECOND FROM FP DATA TO ACCOUNT FOR 1S
%DELAY TRACKING START.
dataNeeded = df(minPoint:((n/fps_vid)*fps_data)+ 1);
%Get list of times (in seconds) for labeling x-axis of FP plot
timeNeeded = times(minPoint:((n/fps_vid)*fps_data)+ 1,1);
%Plot the data
plot(timeNeeded,dataNeeded,'k','LineWidth',2);
%Label stuff, change axis limits and font sizes
xlabel('Time (s)');
ylabel('DeltaF/F (%)');
ylim([minD maxD]);
xlim([0 vid_duration]);
set(gca,'fontsize',30)
set(gca,'FontWeight','bold');
%Create an image frame from the figure
A = getframe(figure(1));
%Write the frame to new video
writeVideo(v,A);
frameCount = frameCount + 1;
end
%Close new video
close(v)

Respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by