Streaming video commercial muting script

Post your working scripts, libraries and tools for AHK v1.1 and older
redrum
Posts: 74
Joined: 25 Jan 2015, 22:57

Streaming video commercial muting script

19 Oct 2017, 16:25

For some video that I routinely stream in Internet Explorer, I wrote a script to mute commercials. I'm using imagesearch to search for onscreen images that are displayed during commercials to detect when commercials are playing. The muting/unmuting is accomplished using NirCmd and its muteappvolume command, so this can be used for IE, Chrome, Firefox or pretty much any other app.

Code: Select all

muteOverride:= 0 ; variable used to integrate hotkey override into automatic commercial muting script (see below for explanation)
#Persistent
SetTimer, CommCheck, 3000  ; check every 3 seconds
Return

CommCheck:
IfWinExist, ahk_exe iexplore.exe
{
	CoordMode, Pixel, Screen
	ImageSearch, X, Y, -1620, -850, -330, -780, *20, %commercial1Path%  ; imagesearch for image 1
	if ErrorLevel = 0
	{
		RunWait, D:\Downloads\nircmd\nircmd.exe muteappvolume iexplore.exe 1  ; mute
		muteOverride := 0
	}
	else if ErrorLevel = 1
	{
		CoordMode, Pixel, Screen
		ImageSearch, X, Y, -1620, -850, -1450, -185, *20, %commercial2Path%  ; ; imagesearch for image 2
		if ErrorLevel = 0
		{
			RunWait, D:\Downloads\nircmd\nircmd.exe muteappvolume iexplore.exe 1  ; mute
			muteOverride := 0
		}
		else if (ErrorLevel = 1) && (muteOverride = 0)
		{
			RunWait, D:\Downloads\nircmd\nircmd.exe muteappvolume iexplore.exe 0  ; unmute
		}
	}
	else if ErrorLevel = 2
		MsgBox problem with imagesearch
}
Return
I also built in a hotkey override - sometimes when the content video (i.e., not commercials) is playing, I'll want to mute the app. For example, I want to play a Youtube clip in another browser (Chrome or Firefox), so muting system volume is not a suitable option.

Code: Select all

!+c::  ;toggles mute/unmute for IE 
IfWinExist, ahk_exe iexplore.exe
	RunWait, D:\Downloads\nircmd\nircmd.exe muteappvolume iexplore.exe 2  ; toggle mute/unmute
	if muteOverride = 0
	{
		muteOverride := 1
	}
	else if muteOverride = 1
	{
		muteOverride := 0
	}
return
This works reasonably well. Drawback is it does require the video to NOT be in fullscreen mode as the images I am using to detect commercials are not displayed in fullscreen mode. I would guess the info for those images is being transmitted to IE, so there is probably a way to detect if that info is there. If someone knows how to do this, I'd be very interested.

On a side note, I understand the need for commercials, and I wouldn't have bothered to write this script but for the obnoxious and jarring volume increases for the commercials (i.e., programmed content plays at one volume, commercials play at a higher volume). And since I was writing the script, it was just as easy to mute as it was to lower volume.
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Streaming video commercial muting script

23 Oct 2017, 18:34

If you're interested in dropping the requirement of nircmd, you can adjust volume levels per-application using the functions in my Volume.ahk script.

Once you have all the necessary code, an example of how you might change IE's volume level is like this (in spoiler):
Spoiler

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: OrangeCat and 68 guests