Uncategorized

## Playing a song as a background process in Windows

Sometimes you ask yourself how to do cool things like playing a song in the background (ie. no visible interface or application) upon login on a Windows box. Being completely unfamiliar with using DOS I wasn’t quite sure how to go about doing this, but apparently it was quite easy. So here I am documenting it for future "reference". This marks my very first time touching the DOS prompt and indeed any sort of commands in Windows, so please excuse the newbie-format of this post.

Everything is done CLI for obvious reasons – we don’t want any interface for them to turn off our song. So we need a command line music player. mplayer is also available as a command line player on Windows, and so it was my first choice. A quick download of a build without an interface and we were ready to play any song with a *.bat file containing mplayer "music.mp3"

The next step is to make it run without the prompt opening up. This is again easily done by executing the bat file via a vbs file with the following content. Creating a shortcut to this vbs file and dumping it in your startup folder is the simplest and most obvious way to make it play on login. Here’s the code:

Set WshShell = CreateObject("WScript.Shell")WshShell.Run chr(34) & "C:\path\to\my\bat\file.bat" & Chr(34), 0Set WshShell = Nothing

Now I wanted to be able to change this song whenever I wanted from a central server. Basically it would check whether or not it needs to update the song, and if it does, delete the existing song and download the new song. This is useful to give a little variety in our fun little player. Some things didn’t work quite as I wanted it to so I have probably used the most horrendous of hacks based on what I could garner from various online references.

It would download that plaintext file’s contents to a tmp file, search in that tmp file for the string we were looking for, and if successful, would delete the existing music file and download the new one to take its place. Unfortunately doing a simple if %getnew%==yes didn’t work (explanations welcome!), so I made do with checking the first 3 characters, which did work. Here’s the final code, with the getnew.txt file including just the single word "yes".

del tmpURL2FILE.EXE http://foobar.com/getnew.txt > tmpset /p getnew= < tmpset _part_name=%getnew:~0,3%if %_part_name%==yes del music.mp3if %_part_name%==yes URL2FILE.EXE http://foobar.com/music.mp3 music.mp3

Tada, and worked flawlessly. Not bad for a couple hours work from scratch and not knowing anything about DOS at all.

In unrelated news, I’m looking for good bagpipe music.

Technical

## Tech Tip #5: Rotate a video by 90 degrees with mencoder

I was recently doing some video editing work where the workflow was something like this: film in portrait, transfer to computer, rotate videos by 90 degrees, sequence together several videos, strip out background noise from entire video. Filming was done with a camera, sequencing was done by Kdenlive (I’ve previously only had experience with Blender’s VSE and I must say I was very happy with this new application), and the noise-stripping was done with Audacity. I must say I’m surprised at how fast this was all accomplished and kudos to all those developers who created these apps.

However one thing I didn’t know how to do was how to rotate the video by 90 degrees. Kdenlive can do it but it ends up being awkwardly stretched and I couldn’t figure out how to unstretch it. Luckily mencoder, which comes with the mplayer package, has got a few tricks up its sleeve.

More for my own records than for anybody else, here’s the command I used:

mencoder -vf rotate=2 -o output.avi -oac pcm -ovc lavc input.mov

As my input file was a .mov some of the sound wasn’t synchronised well after rotating, which was easily fixed by this option -demuxer mov. If you want to rotate clockwise instead of anticlockwise change rotate=2 to rotate=1.