Capture script run on video.

Asked by sdraganov

I would like to capture my sikulix script run on video - would be very helpful when something failed.

I managed to run a video recording with ffmpeg:
https://www.ffmpeg.org/

and the following .bat command launched from sikulix:
D:\ffmpeg.exe -y -rtbufsize 100M -f gdigrab -framerate 30 -offset_x 0 -offset_y 0 -video_size 1920x1200 -draw_mouse 1 -i desktop -c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 28 -pix_fmt yuv420p -movflags +faststart "D:\1.mp4"

The problem is that sikulix App.close() and CMD taskkill commands cannot stop the recorder.
I need to execute CTRL+C command before or after App.close() or taskkill commands - otherwise ffmpeg continues to record.
I know it's possible ti run CTRL+C from sikuli but since my script opens and closes lots of windows I'm afraid that .CMD windows could be out of focus when it's executed. Sikuli App.focus() method also doesn't work with CMD.exe being started by the .bat file.

The other problem that I see in the future is that if something fails and the script doesn't get to the commands that would stop the recorder, the recording will not stop. Is there a way to run a command that would stop the recording if script failed?

I would be happy to hear if someone already get through this and let me know how to do it.
I'm not tied to ffmpeg-software, it's just the first thing I tried, if there is a better solution I would love to try it.

Thanks in advance.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

interesting solution ;-)

I guess, the only way, that makes sense, is to use the video creation as main process and run the scripts, that you want to observe, as subprocesses from within this main process.

# workflow
- start video
- detach scriptrun to subprocess
- track the scriptrun somehow (e.g. with the piped stdout)
- stop the video capture when the subprocess ends (however this might happen)

Revision history for this message
Mical Tech (michaltech) said :
#6

In the example below, I'm trying to capture all the videos in this script. However, I'm only able to capture the first video. I understand this has to do with getElementById and not querySelectorAll, but I'm not sure how to implement it in this script.

var videoId = document.getElementById("wistia_video");
var uniqueVideoId = Array.from(videoId.classList)
  .find((c) => c.startsWith("wistia_async_"))
  .substring(13);
// console.log(uniqueVideoId);

const clickToPlay = document.querySelectorAll('.wistia')[0];

clickToPlay.addEventListener('click', function() {
  const playVideo = clickToPlay.querySelectorAll('.wistia__overlay, .embed-youtube__play');
  Array.from(playVideo).forEach((elem) => elem.remove());

  //supporting scripts
  let wistiaSupportScripts = [
    `https://fast.wistia.com/assets/external/E-v1.js`,
    //adds jsonp file to provide security over requests
    `https://fast.wistia.com/embed/medias/${uniqueVideoId}.jsonp`
  ];

  //loads supporting scripts into head
  for (var i = 0; i < wistiaSupportScripts.length; i++) {
    let wistiaSupportScript = document.createElement("script");
    wistiaSupportScript.src = wistiaSupportScripts[i];
    let complete = false;
    if (!complete && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
      complete = true;
    }

    let wistiaContainers = document.querySelector(".wistia");

    wistiaContainers ? document.getElementsByTagName("head")[0].appendChild(wistiaSupportScript) : console.log("No Wistia videos here.");
  }

  window._wq = window._wq || [];
  _wq.push({
    //globally scoped
    id: uniqueVideoId,
    options: {
      autoPlay: true,
      volume: 0.5
    },

    onReady: function(video) {
      video.bind("play");
    }
  });
});

Copy from https://totoposition.com

Can you help with this problem?

Provide an answer of your own, or ask sdraganov for more information if necessary.

To post a message you must log in.