VideoWriter Error: No frames were written to this file
    14 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Hello everyone,
I have this code that is supposed to write frames on a video and save it:
function rgb_array = renderDrivingEnv(time, action, xy_pos, xy_dot, xy_dotdot, ...
    yaw, lane_dist, lane_curvature, lane_curvature_derivate, heading_angle, inert_angle, engine_info, rewards, scene_info, folder, baseFileName, saveVideo, impaired, testing, invert_y_and_yaw, train_gail)
    % Define global variables.
    global currentTimeEditField steerEditField accelEditField accelLable decelEditField decelLable rewEditField totRewEditField impLable impEditField belLable belEditField...
           totRewLable rewLable egoVehicle scenario cgVel currentStepEditField writerObj hLineOffset hLineLateralDev hLineSteering hLineYaw gearEditField kmHEditField...
           labLable labEditField hLineImp hPanelPlotImp;
    % inizialize output
    rgb_array = 0;
    %% Create and set Figure Properties.
    figureName = 'Simulation Rendering';
    hFigure = findobj('Type','Figure','Name',figureName);
    if isempty(hFigure)
        % import scenario parameters
        egoVehicle = evalin("base", "egoVehicle");
        scenario = evalin("base", "scenario");
        sampleTime = evalin("base", "sampleTime");
        %% Save scenario plot
        fullFileName = fullfile(folder, baseFileName);
        fig = figure('doublebuffer','off','Visible','Off');
        ax = axes('Parent',fig);
        plot(scenario,'Parent', ax);
        saveas(fig,fullFileName, 'png');
        %% Initialize rendering window
        screenSize = double(get(groot,'ScreenSize'));
        hFigure = figure('Name',figureName);
        hFigure.Position = [screenSize(3)*0.17 screenSize(4)*0.15 screenSize(3)*0.7 screenSize(4)*0.7];
        hFigure.NumberTitle = 'off';
        hFigure.MenuBar = 'none';
        hFigure.ToolBar = 'none';
        train_gail_is = train_gail
        invert_y_and_yaw_is = invert_y_and_yaw
        openRenderView(hFigure, egoVehicle, scenario);
        updateSceneInfo(scene_info);
        %% Set up the movie structure.
        % Create a VideoWriter object to write the video out to a new, different file.
        profile = 'MPEG-4';
        % if isempty(writerObj)
            file_name = fullFileName
            writerObj = VideoWriter(fullFileName, profile);
            writerObj.Quality = 30;
            writerObj.FrameRate = 1/sampleTime;
        % end
        open(writerObj);
        % Need to change from the default renderer to zbuffer to get it to work right.
        % openGL doesn't work and Painters is way too slow.
        set(gcf, 'renderer', 'zbuffer');
    end
    totalframes=VID.NumberOfFrames
    %% Save rendering video
    if saveVideo
        close(hFigure);
        close(writerObj);
        return;
    end
    % Update current simulation time.
    currentTimeEditField.String = strcat(num2str(time(2),'%.2f'),'s');
    currentStepEditField.String = time(2)/time(1);
    % Update Engine Info
    if train_gail
        gearEditField.String = strcat(num2str(engine_info(1),'%d'));
    else
        gearEditField.String = strcat(num2str(engine_info(2),'%d'));
    end
    kmHEditField.String = strcat(num2str(xy_dot(1)*3.6,'%.f Km/h'));
    % Update current action.
    if train_gail
        steerEditField.String = strcat(num2str(action(1),'%.2f'));
    else
        steerEditField.String = strcat(num2str(deg2rad(action(1)),'%.2f'));
    end
    %% Update observation information .
    updateObsInfo(xy_pos, xy_dot,xy_dotdot, yaw, lane_dist, heading_angle, lane_curvature, lane_curvature_derivate, engine_info);
    % Some data collected had Y coordinate and yaw angle inverted
    if invert_y_and_yaw
        egoVehicle.Position = [xy_pos(1) -xy_pos(2) 0];
        egoVehicle.Yaw = -rad2deg(yaw(1));
    else
        egoVehicle.Position = [xy_pos(1) xy_pos(2) 0];
        egoVehicle.Yaw = rad2deg(yaw(1));
    end
    if train_gail
        egoVehicle.Yaw = rad2deg(inert_angle(3));
    end
    if testing
        egoVehicle.Mesh = driving.scenario.truckMesh;
    else
        egoVehicle.Mesh = driving.scenario.carMesh;
    end
    %% Update plots.
    % Ego View
    updatePlots(scenario);
    % Write this frame out to a new video file.
    % pause for frame processing...
    pause(0.1)
    thisFrame = getframe(hFigure);
  	writeVideo(writerObj, thisFrame);
end
Where it runs recurrently the file (entering only once in the "isempty" condition to create the figure)
At the end I get:
Warning: No video frames were written to this file. The file may be invalid.
Anyone know how to debug this? The videos are supposed to be long so I'm taking a really long time to debug...
Thanks.
1 Kommentar
  Walter Roberson
      
      
 am 15 Mär. 2023
				Could you confirm that the save video parameter is false except for the final call?
Antworten (1)
  Sachin
    
 am 15 Mär. 2023
        Based on my understanding, you are getting warning ‘No frames were written to this file’. Here are some points that might be helpful to you:
- Check that fullfile name is correct.
- May be debugger reveals some details. Type this in command window: Then run the code again.
dbstop if caught error
         3. You can suppress warning to check if warning is causing the issues. Refer the following documentation for suppress -   warnings
Thanks 
Sachin
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Prepare Model Inputs and Outputs finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


