Thursday, April 9

Console app to keep screensaver from activating

Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Module Module1

    
    Public Enum EXECUTION_STATE As UInteger
        ES_SYSTEM_REQUIRED = &H1
        ES_DISPLAY_REQUIRED = &H2
        ES_CONTINUOUS = &H80000000UI
    End Enum

    
    Private Function SetThreadExecutionState(ByVal esFlags As EXECUTION_STATE) As EXECUTION_STATE
    End Function

    Public Sub ContinuousDisplayRequired()
        SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED Or EXECUTION_STATE.ES_CONTINUOUS Or EXECUTION_STATE.ES_SYSTEM_REQUIRED)
    End Sub

    Dim aTimer As New System.Timers.Timer
    Sub Main()
        Dim CurrentProcess As Process = Process.GetCurrentProcess()
        Dim CopiesOfThisProcess() As Process = Process.GetProcessesByName(CurrentProcess.ProcessName)
        For Each CopyOfThisProcess As System.Diagnostics.Process In CopiesOfThisProcess
            If (CopyOfThisProcess.StartTime <> CurrentProcess.StartTime) Then
                CopyOfThisProcess.Kill() 'Kill all other instances of this process
            End If
        Next CopyOfThisProcess
        Console.WindowLeft = 0
        Console.WindowTop = 0
        Console.WindowWidth = Console.LargestWindowWidth \ 10
        Console.WindowHeight = Console.LargestWindowHeight \ 2
        Console.WriteLine(Now.ToString("yyyy-MM-dd HH:mm:ss"))
        Console.Title = Now.ToString("HH:mm:ss")
        Application.DoEvents()
        aTimer.AutoReset = True
        aTimer.Interval = 1000 '1 second
        AddHandler aTimer.Elapsed, AddressOf TimerIntervalElapsed
        aTimer.Start()
        Console.ReadKey()
    End Sub

    Private Sub TimerIntervalElapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
        aTimer.Enabled = False
        If Now.ToString("HH:mm:ss") > "15:00:00" Then
            End
        End If
        Console.WriteLine(Now.ToString("yyyy-MM-dd HH:mm:ss"))
        aTimer.Interval = GetRandomNumber(60000, 300000) 'Minimum and maximum time to next interval in milliseconds
        Console.Title = DateAndTime.DateAdd(DateInterval.Second, aTimer.Interval \ 1000, Now).ToString("hh:mm:ss")
        'Try
        '    System.Windows.Forms.SendKeys.SendWait("^+{SCROLLLOCK 2}")
        ContinuousDisplayRequired()
        'Catch
        '    Application.Restart()
        'End Try
        aTimer.Enabled = True
        Application.DoEvents()
    End Sub

    Public Function GetRandomNumber(ByVal Min As Integer, ByVal Max As Integer) As Integer
        Static Generator As New System.Random
        Return Generator.Next(Min, Max)
    End Function

End Module

Thursday, September 4

Iterate.bat



REM Make a copy of this batch file before modifying.

SetLocal EnableDelayedExpansion

@echo on

REM When a podcast cover file (bc###.png) is passed to this script, a series of thumbnail files for YouTube are created, each one smaller, until one that is under 2 gigabytes that YouTube will accept, is generated.

REM The thumbnail image files are saved in this folder: C:\Users\livec\Downloads\ 

If Not Exist "%1" Then (Choice /m "File does not exist. Press Ctrl+C")

Title %~nx1

For /l %%i In (1280, -100, 1000) Do (
REM    Echo %%i
	C:\ffmpeg\ffmpeg -y -i "%~dp1%~nx1" -vf scale=%%i:%%i "C:\Users\livec\Downloads\%~n1_%%ix%%i.png"

	Set n="C:\Users\livec\Downloads\%~n1_%%ix%%i.png" 

REM	Echo n = !n!

	for %%f in (!n!) do (
		Set /a FileSize=%%~zf
		Echo %%~nxf  FileSize = %FileSize%
		If !FileSize! LEQ 2097152 (
			GoTo FileLessThan2Megabytes
			)
		)
	)

:FileLessThan2Megabytes

rundll32.exe cmdext.dll,MessageBeepStub
rundll32 user32.dll,MessageBeep

Choice /d N /t 99

EndLocal

ConvertAudioForYouTube.bat


REM Make a copy of this batch file before modifying.

@echo on
Setlocal enableDelayedExpansion

REM An MP3 audio file passed to this script will be converted into an MP4 file with randomly selected static images for uploading to YouTube. These are not true MP4 files, so they can only be played with VLC, but YouTube recognizes them, and converts them to their own formats in very high quality.

REM A 1280x1280 thumbnail file of the cover art for uploading to YouTube is also generated. Sometimes, these files are larger than 2 megabytes, which YouTube will not accept. When that happens, pass the cover file (bc###.png) to the Interate.bat script to generate successively smaller thumbnail files until one is created that is slightly smaller than 2 megabytes.

Set /a MinFileVal = 119
Set /a MaxFileVal = 159
Set /a MinDurationVal = 14
Set /a MaxDurationVal = 19
REM Set /a AudioFileDurationInSeconds = 9999

For /f %%a in ('C:\MediaInfo\MediaInfo.exe --Inform^=General^;%%Duration%% ^"%~1^"') Do Set /a AudioFileDurationInMilliseconds=%%a

Echo AudioFileDurationInMilliseconds = %AudioFileDurationInMilliseconds%

Set /a AudioFileDurationInSeconds = AudioFileDurationInMilliseconds / 1000

Echo AudioFileDurationInSeconds = %AudioFileDurationInSeconds%

Copy nul "C:\Users\livec\Downloads\Images.txt" > nul

Echo file 'F:\Podcast\%~n1.png' >> "C:\Users\livec\Downloads\Images.txt"

Echo duration 5 >> "C:\Users\livec\Downloads\Images.txt"

Echo Filling Images.txt file with timestamps.

Set /a RunningTimeInSeconds = 0
Set /a RndDurationVal = 0
Set /a MaxIterations = AudioFileDurationInSeconds / MinDurationVal

FOR /L %%i in (0,1,%MaxIterations%) do (
    If !RunningTimeInSeconds! GEQ !AudioFileDurationInSeconds! (
	GoTo :ImagesFileFilled
    )
    Set /a CountDown = AudioFileDurationInSeconds - RunningTimeInSeconds
    Title !CountDown!
    Set /a RndFileVal = "!RANDOM! * (!MaxFileVal! - !MinFileVal! + 1) / 32768 + !MinFileVal!"
    set "PaddedVal=0000000000!RndFileVal!"
    set "FormattedVal=bc!PaddedVal:~-3!.png"
    echo file 'F:\Podcast\!FormattedVal!' >> "C:\Users\livec\Downloads\Images.txt"
    Set /a RndDurationVal = "!RANDOM! * (!MaxDurationVal! - !MinDurationVal! + 1) / 32768 + !MinDurationVal!"
    Echo duration !RndDurationVal! >> "C:\Users\livec\Downloads\Images.txt"
    Set /a RunningTimeInSeconds = RunningTimeInSeconds + RndDurationVal 
    REM Echo "Running Seconds: !RunningTimeInSeconds!" >> "C:\Users\livec\Downloads\Images.txt"
)

:ImagesFileFilled

Title %0

REM Due to a quirk, the last image has to be specified twice - the 2nd time without any duration directive
echo file 'F:\Podcast\!FormattedVal!' >> "C:\Users\livec\Downloads\Images.txt"

Type "C:\Users\livec\Downloads\Images.txt"

c:\ffmpeg\ffmpeg.exe -y -i "%~d1%~p1%~n1.png" -vf scale=1280:1280 "%~d1%~p1%~n1_1280x1280.png"

c:\ffmpeg\ffmpeg.exe -safe 0 -y -f concat -i "C:\Users\livec\Downloads\Images.txt" -i "%~1" -i "F:\Podcast\%~n1.vtt" -c:s mov_text -metadata:s:s:0 language=eng -c:a copy -c:v copy -t 9999 -r 30  -movflags faststart "%~d1%~p1%~n1.mp4"

rundll32.exe cmdext.dll,MessageBeepStub
rundll32 user32.dll,MessageBeep

timeout /t 999

endlocal



ConvertVideoForMastodon.bat


REM Make a copy of this batch file before modifying.

Setlocal EnableDelayedExpansion

rem Convert video into a file size acceptable in a Mastodon post.

Set /a MaxFileSizeInMegaBytes = 98

Title %MaxFileSizeInMegaBytes% MG Conversion

Echo MaxFileSizeInMegaBytes = %MaxFileSizeInMegaBytes%

Set /a AudioBitRateInKiloBits = 128

Echo AudioBitRateInKiloBits = %AudioBitRateInKiloBits%

Set /a MaxFileSizeInKiloBytes = MaxFileSizeInMegaBytes * 1000

Echo MaxFileSizeInKiloBytes = %MaxFileSizeInKiloBytes%

Set /a FileSizeInBytes = 0

Set /a FileSizeInBytes = %~z1

Echo FileSizeInBytes = %FileSizeInBytes%

Set /a FileSizeInKiloBytes = FileSizeInBytes / 1024

Echo FileSizeInKiloBytes = %FileSizeInKiloBytes%

If %FileSizeInKiloBytes% EQU 0 (
	Echo File size is too large to fit in 32 bit variable
	Set /a FileSizeInKiloBytes = MaxFileSizeInKiloBytes + 1
	)

If %FileSizeInKiloBytes% LEQ %MaxFileSizeInKiloBytes% (
	Echo %~1
	Echo File is already smaller than %MaxFileSizeInMegaBytes% megabytes.
	Choice /c y /t 999 /d y /m "Press Y to exit."
	Endlocal
	Exit
	)

For /f %%a in ('C:\MediaInfo\MediaInfo.exe --Inform^=General^;%%Duration%% ^"%~1^"') Do Set /a DurationInMilliseconds=%%a

Echo DurationInMilliseconds = %DurationInMilliseconds%

Set /a DurationInSeconds = DurationInMilliseconds / 1000

Echo DurationInSeconds = %DurationInSeconds%

Set /a CenterTimeInSeconds = DurationInSeconds / 2

Echo CenterTimeInSeconds = %CenterTimeInSeconds%

c:\ffmpeg\ffmpeg.exe -ss %CenterTimeInSeconds% -i "%~1" -frames:v 1 -y "%~d1%~p1%~n1_Thumbnail.png"

Set /a MaxFileSizeInMegaBits = 8388 * MaxFileSizeInMegaBytes

Echo MaxFileSizeInMegaBits = %MaxFileSizeInMegaBits%

Set /a TotalBitRateInKiloBits = MaxFileSizeInMegaBits / DurationInSeconds

Echo TotalBitRateInKiloBits = %TotalBitRateInKiloBits%

Set /a TargetBitRateInKiloBits = TotalBitRateInKiloBits - AudioBitRateInKiloBits

Echo TargetBitRateInKiloBits = %TargetBitRateInKiloBits%

If %TargetBitRateInKiloBits% LEQ 0 (
	Echo %~1
	Echo File is too large to convert.
	Choice /c y /t 999 /d y /m "Press Y to exit."
	Endlocal
	Exit
	)

c:\ffmpeg\ffmpeg.exe -i "%~1" -tune film -preset slow -vf fps=30,scale='min(1920,iw)':-2 -vcodec libx264 -b:v %TargetBitRateInKiloBits%k -pass 1 -an -f null null && ^
c:\ffmpeg\ffmpeg.exe -i "%~1" -tune film -preset slow -vf fps=30,scale='min(1920,iw)':-2 -vcodec libx264 -b:v %TargetBitRateInKiloBits%k -pass 2 -ac 1 -b:a %AudioBitRateInKiloBits%k -y -movflags faststart -fs %MaxFileSizeInMegaBytes%M "%~d1%~p1%~n1_4Mastodon.mp4"

REM c:\ffmpeg\ffmpeg.exe -i "%~d1%~p1%~n1_4Mastodon.mp4" -i "%~d1%~p1%~n1_Thumbnail.png" -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic -y "%~d1%~p1%~n1_4MastodonWithThumbnail.mp4"

timeout /t 999

Endlocal


Sunday, October 9

Weather test

Wednesday, September 21

Coldplay Beats It

Sunday, August 7

Going GaGa

Saturday, April 9

Friday, February 11

Hosni Mubarak

♫ If I only had a rein... ♪
Hosni Mubarak
Hosni Mubarak

Saturday, February 5

2 Out Of 3 Ain't Bad

Why do people love grilled cheese sandwiches? Because it's grilled and it's cheese.

Saturday, January 8

Wednesday, January 5

Miss Trailer Trash Contest Intro

I spent one afternoon splicing together pieces of music and video to form a story line to be used as a video introduction for a campy drag show. Here are the results. -Wrecks

Tuesday, January 4

Jockies or Boxers?

Jockies or Boxers?

Sunday, January 2

...

What every IT support person needs: Click here.

Sunday, December 26

Has anybody ever tried one of these? I'm curious to know more.

Saturday, December 25