Building my own Video Recorder–Automating Scheduled Streaming Video Recording on Windows 10 image 52

Building my own Video Recorder–Automating Scheduled Streaming Video Recording on Windows 10

My objective: create a mechanism for recording streaming video on my Windows laptop on a preprogrammed timestamp and channel.

My motivation:  show that I can do this (using AutoIt, OBS, Windows Task Scheduler an Windows Sandbox) and create a way around the limitation of my current TV provider (Ziggo in The Netherlands) that does not support recording programs any longer and offers on demand viewing for only a limited number of channels. I have a personal need for an easy way to make a recording of interesting programs and watch them at my convenience.

My code: https://github.com/lucasjellema/autoit-scenarios

Some challenges:

  • streaming video running in the browser is not easy to capture – The problem is that often these players use video overlay for faster, smoother playback of the movie. A video overlay is invisible to Windows capture programs  because it is handled by a special video hardware
  • ensure the right channel is playing on the streaming service
  • run the Windows Sandbox from an AutoIt script
  • play the video in full screen mode and maximize the Windows Sandbox window
  • capture the correct window in the OBS recording session
  • run a task at any time, even when my laptop is hibernating

Capturing streaming video despite the overlay issue can be overcome by running the video inside Windows Sandbox. The downside is that applications running inside the Sandbox are opaque to an AutoIt script running outside the Sandbox – this script cannot act directly on controls – only on positions. That is fine in general – except for when the script is executed with the computer in locked mode. Unfortunately this is the case when the task is run from a sleeping computer – one of my requirements. In this article, I will not realize that requirement: I will get to the point where a task can be scheduled in Windows Task Scheduler and this task will make a perfect recording of the intended video stream – but only if the computer is not in locked mode. In a follow up article I will try to find a solution for that situation (probably by running a script inside the Windows Sandbox).

The final solution in this article looks as follows:

image

The task scheduled in Windows Task Scheduler runs the executable created from the AutoIt script. This script runs the Windows Sandbox app, starts the Edge browser and loads the TV provider’s site. (feel free to substitute with whatever site you want to record video from).

The script then runs OBS (feel free to replace with any other screen recording tool of which there are many). OBS has been configured ahead of time to capture a window called Windows Sandbox as source. The AutoIt script starts recording in OBS – and stops it after the specified duration. It then closes OBS and the Windows Sandbox window.

With this setup, I can schedule the recording task in Windows Task Scheduler:

image

The task runs the executable – recordZiggoChannel.exe – that was compiled from the original AutoIt script:

image

The task definition also comprises of the channel label (for example BBC ONE) and the duration of the intended recording. The task is scheduled to be executed at a specific timestamp. When that time arrives, the task is triggered and the script (turned executable) is invoked.

This script goes through the following stages:

  • run Windows Sandbox
  • start Edge browser
  • navigate to Ziggo Website
  • login, open the desired channel, switch to full screen display
  • maximize the Sandbox window
  • run OBS Studio (Open Broadcaster Software) (in which I have created a Scene ahead of time with a Window Capture source for a window titled Windows Sandbox)

    image
  • start recording in OBS

    SNAGHTML21e9eb4
  • wait for the indicated duration of the recording
  • stop recording in OBS
  • close OBS
  • close the Windows Sandbox window

At this point, the video recording has been created an is available in the designated directory in OBS for videos. The script also write log statements to a local file – recordZiggoChannel.log – and it creates screenshots during its execution – for debugging purposes:

SNAGHTML1b455f7

OBS is then started to record the contents of the Windows Sandbox window:

image

After the specified time, the AutoIt script wakes up after some Sleep() and stops the recording, closes down both OSB and Windows Sandbox, thereby completing the task.

SNAGHTML1be5857

Watch the demo of running the recording task from Windows Task Scheduler. All steps from that point on are automated. Not to the point of high efficiency as will be obvious from watching the video and inspecting the code. Automation was the objective, not speed.

Resources

Sources in this GitHub repository: https://github.com/lucasjellema/autoit-scenarios.

My earlier steps with AutoIt in Scheduling Spotify Playlist using AutoIt – https://technology.amis.nl/frontend/schedule-spotify-good-morning-playlist-using-autoit-and-windows-task-scheduler/ (this article explains how to run an app from the App Store using AutoIt; the Windows Sandbox is an example of such an app

And my first steps with AutoIt (how to get going): https://technology.amis.nl/software-development/automating-actions-on-windows-my-first-steps-with-autoit/

AutoIt on a Locked Workstation – https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F 

On a locked station any window will never be active (active is only dialog with text “Press Ctrl+Alt+Del”). In Windows locked state applications run hidden (behind that visible dialog) and do not have focus and active status. So generally don’t use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc. Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc. Doing so allows you to interact with an application regardless of whether it is active or not. It’s possible to run such a script from scheduler on locked Windows stations.

Programmatically controlling Task Schedules from within AutoIt, using this library: https://www.autoitscript.com/wiki/TaskScheduler

AutoIt Forum thread on running Windows 10 Apps (rather than regular applications): https://www.autoitscript.com/forum/topic/187123-win10-run-windows-store-apps/

How to Make Your PC Wake From Sleep Automatically – https://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/ 

AutoIt executables and malware detection – https://www.autoitscript.com/wiki/AutoIt_and_Malware

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.