"Create Video" dialog - "Estimated remaining time" text

This topic has been viewed 4338 times and has 1 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
User avatar
MeekMark
Posts: 1
Joined: Sun Jun 12, 2022 11:20 pm
Country: United States

"Create Video" dialog - "Estimated remaining time" text

Post by MeekMark »

My first post, novice user of Sweet Home. My first design of my house, I got carried away in the "Create Video" dialog. I created lots (maybe 100) of camera locations, which yielded maybe 2,300 frames.

The "Estimated remaining time" when it started sounded fast, maybe 1 hour remaining. Well several hours later, it was maybe 58 minutes remaining and only maybe 50% through the 2,300 frames.

So I hunted down the code, and saw this in[font=courier new] sweethome3d-code-r8307-trunk\SweetHome3D\src\com\eteks\sweethome3d\swing\VideoPanel.java[/font]:

Code: Select all

    this.progressBar = new JProgressBar();
    this.progressBar.setIndeterminate(true);
    this.progressBar.getModel().addChangeListener(new ChangeListener() {
        private long timeAfterFirstImage;

        public void stateChanged(ChangeEvent ev) {
          int progressValue = progressBar.getValue();
          progressBar.setIndeterminate(progressValue <= progressBar.getMinimum() + 1);
          if (progressValue == progressBar.getMinimum()
              || progressValue == progressBar.getMaximum()) {
            progressLabel.setText("");
            if (progressValue == progressBar.getMinimum()) {
              int framesCount = progressBar.getMaximum() - progressBar.getMinimum();
              String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressStartLabel.format");
              progressLabel.setText(String.format(progressLabelFormat, framesCount,
                  formatDuration(framesCount * 1000 / controller.getFrameRate())));
            }
          } else if (progressValue == progressBar.getMinimum() + 1) {
            this.timeAfterFirstImage = System.currentTimeMillis();
          } else {
            // Update progress label once the second image is generated
            // (the first one can take more time because of initialization process)
            String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressLabel.format");
            long estimatedRemainingTime = (System.currentTimeMillis() - this.timeAfterFirstImage)
                / (progressValue - 1 - progressBar.getMinimum())
                * (progressBar.getMaximum() - progressValue - 1);
            String estimatedRemainingTimeText = formatDuration(estimatedRemainingTime);
            progressLabel.setText(String.format(progressLabelFormat,
                progressValue, progressBar.getMaximum(), estimatedRemainingTimeText));
          }
        }
So, I saw it takes a snapshot of the elapsed time in milliseconds for the second image. But what I think is happening (at least in my situation) is the first 100 or so images are pretty basic, viewpoint of just a portion of the exterior.

So here's some (untested) code that would look at the elapsed time of the rendering of the tenth image and use that as the basis of the average time, to calculate the estimated remaining time.

I would imagine that a better implementation would be to use the total number of images being rendered (IE: progressBar.getMaximum() ), and see the elapsed time of an image perhaps 5% into the render, and use that:

Code: Select all

    this.progressBar = new JProgressBar();
    this.progressBar.setIndeterminate(true);
    this.progressBar.getModel().addChangeListener(new ChangeListener() {
        private long timeAfterFirstImage;
		// MeekMark Begin
		private long timeAfter10Images;
		private long timeAfter11Images;
		private long timeEstimate;
		// MeekMark End

        public void stateChanged(ChangeEvent ev) {
          int progressValue = progressBar.getValue();
          progressBar.setIndeterminate(progressValue <= progressBar.getMinimum() + 1);
          if (progressValue == progressBar.getMinimum()
              || progressValue == progressBar.getMaximum()) {
            progressLabel.setText("");
            if (progressValue == progressBar.getMinimum()) {
              int framesCount = progressBar.getMaximum() - progressBar.getMinimum();
              String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressStartLabel.format");
              progressLabel.setText(String.format(progressLabelFormat, framesCount,
                  formatDuration(framesCount * 1000 / controller.getFrameRate())));
            }
          // MeekMark Begin
          } else if (progressValue == progressBar.getMinimum() + 11) {
            this.timeAfter11Images = System.currentTimeMillis();
			this.timeEstimate = timeAfter11Images - timeAfter10Images;
          } else if (progressValue == progressBar.getMinimum() + 10) {
            this.timeAfter10Images = System.currentTimeMillis();
          } else if (progressValue == progressBar.getMinimum() + 1) {
            this.timeAfterFirstImage = System.currentTimeMillis();
			this.timeEstimate = this.timeAfterFirstImage;
          } else {
            // Update progress label once the second image is generated
            // (the first FEW?? can take more time because of initialization process)
            String progressLabelFormat = preferences.getLocalizedString(VideoPanel.class, "progressLabel.format");
			long estimatedRemainingTime = (System.currentTimeMillis() - this.timeEstimate)
                / (progressValue - 1 - progressBar.getMinimum())
                * (progressBar.getMaximum() - progressValue - 1);
          // MeekMark End
		  String estimatedRemainingTimeText = formatDuration(estimatedRemainingTime);
            progressLabel.setText(String.format(progressLabelFormat,
                progressValue, progressBar.getMaximum(), estimatedRemainingTimeText));
          }
        }



Now I'd love to load up Eclipse on my home computer and test it out, but... not enough time...


Thoughts?
User avatar
Daniels118
Posts: 503
Joined: Wed Nov 17, 2021 9:04 pm
Country: Italy

Re: "Create Video" dialog - "Estimated remaining time" text

Post by Daniels118 »

I think the best estimate can be obtained by averaging the elapsed of all frames rendered so far. This has the drawback that the ETA is quite unstable at first, however it gains stability as more frames are included in the average.
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest