Monday, February 1, 2021

Creating a time-accurate mp4 video out of a collection of photos

Way back when I got married, I asked the attendees to send me their digital photos so I could get various angles of the event.  I got back photos from about 10 different cameras, plus two digital videos.

Using Picasa, it was easy to view all this content in one album, but the first problem was time stamps (these photos were all digital camera photos, with manually-set clocks).  In Picasa, using one reference camera (my own), I then shifted each camera's photos times until it matched mine.  I could now view the photos on my computer in sequence, as long as it was in Picasa.

My photos sat this in state for over 10 years.  Recently, I got the urge to work on my wedding video, but the two non-HD video streams look quite dated. Wouldn't it be nice to insert higher resolution photos into the wedding video at key moments.  But with over 500 photos, it would not be practical to manually place them at the right timestamp my video editing software.

My solution was to turn these photos into a video, with each photo displayed at the right timestamp relative to the very first photo in the stream. From searching around, I couldn't find anyone who had actually done this, hence this article.

I used the exiftool/ffmpeg tools, free to use on multiple OS platforms, but the syntax below is for Windows.

What you need:

Download exiftool and ffmpeg (I won't post a link - they're both popular tools easily findable by the great Google)

Make sure you can download this Excel spreadsheet. You'll need to edit it on your own Excel-capable machine (or upload it to GoogleDocs to perform further editing)

https://1drv.ms/x/s!AgFCNBReexfMnnn_cN0OlyR1yYaK?e=1JvgYJ

Instructions:

From a command prompt, navigate to where your jpg files are stored. Then run:

"<path to>\exiftool.exe" *.jpg -s -DateTimeOriginal -csv > photos.csv

(note - It's possible that the Exif field your camera/photo program uses might populate/prefer a different field from DateTimeOriginal, so change that as appropriate)
Open photos.csv in excel (or whatever program you have for .csv), then copy/paste the two columns into the first two columns of the ToFFMPEG.xlsx file I shared above. All the other columns in ToFFMPEG.xlsx past Column C are calculations - don't modify those. If the number of files you're pasting in exceeds the number of pre-populated formulas in Column C and beyond, just Fill Down those formula rows as well.

Important - sort by Column B, so that the durations will calculate correctly.

Note - the last row in the file will not be able to calculate a duration, so it will just take the duration from cell K2.
The calculations are in Columns D, E, F, and the final results are put in Column C. Copy that column C into your favourite txt editor. You'll see double quotation marks everywhere that weren't in Excel, but are an artifact of copy/paste when there are multiple lines per cell. Delete all of these double quotation marks with a search/replace. Save it as ToFFMpeg.txt . This is the input into FFMPEG.

Then, run the following ffmpeg command:

"<path to>\ffmpeg" -f concat -safe 0 -i ToFFMpeg.txt -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" -pix_fmt yuv420p -c:v libx264 output.mp4

(the above command should be run on a single line, despite how this forum is splitting it across multiple lines)
This will create your mp4 file. Change the 1920:1080 resolution to whatever you need to optimize with your output video.

Limitations: exif data has only per-second granularity. If two photos are taken at the same second, one will have a duration of 0 seconds, and will probably be hidden by the second photo in your output video.

Apparently, ffmpeg has the ability to read and output exif data itself, but as I was already familiar with exiftool, that's what I used.

Here's a screenshot of the photo mp4 stream embedded with two video camera shots in my Movie Studio project:


Saturday, January 23, 2016

170 Floppies for sale! *sold*

*sold*

Gather round, kids, for you are about to hear a tale of patience, and the acceptance of failure.

Once upon a time, hard drives were expensive.  Like, $300 for a 40 megabyte drive expensive.  But a much cheaper alternative existed, in the form of a black round disc.  Problem with this disc is that it was very sensitive to dirt and fingerprints, so it was enclosed inside a 5.25-inch plastic square, and it was called a floppy disc.  It could even be made double sided, so that reading the entire contents of a disc meant you had to flip it over.  In its heyday, it would store 1.2 megabytes, which by today's standards, might store about a minute-long mp3.  But back in those days, where a program's size was measured in kilobytes, that size was plenty.  You kids might have seen this disc, in the form of a Save icon.  Well, take a gander at one of the photographs in this ad, because there it is!


Floppies got smaller and more durable.  In a 3.5-inch format, they'd store 1.44 megabytes.  Sold for as cheap as a dollar a disc retail, they became the most common format for distributing software in a pre-internet era - just package up a floppy of hardware drivers with a network card, and the user would be able to use it right away ("right away" meaning after manually experimenting with IRQ's).  A company called AOL sent out millions of 3.5-inch floppies in the mail with free trials of its online service to become one of the largest dial-up internet providers in the world.

Floppies, however, were manufactured of varying quality, and susceptible to enviromental factors.  Bad sectors would creep up on the cheaper discs over time, irrecoverably trashing the data on the disc.  They were common vectors for viruses which would copy themselves onto the boot sector of the disc, where most computers were programmed to boot from upon bootup, silently infecting the hard disc.  Ambient magnetism could undetectably corrupt data.

Support for USB drives in Windows 95 (and an even better implementation in Windows 98) eliminated the need for a floppy drive, though it would take a few years more before BIOS manufacturers came up with reliable solutions for flashing BIOSes from something other than a floppy.  Apple was the first major computer manufacturer to push the floppy drive out of public usage by not including one in 1998 with their iMac.

Since then, floppies have disappeared the way rotary phones, LP records, and cassette tapes have, replaced by much better technology. And like many of those unused kin, their imagery exists solely as an icon to the tool.


 In a retro kind-of-way, the 170 3.5 inch floppies (and the dozen or so 5.25 inch floppies) might be useful to someone. Maybe you want to stick them on your wall, and spell out your name in pixels.  Maybe you want to attach a few to your fridge with magnets, as a conversation piece.  Maybe you're building a custom water feature that testifies how the disposal culture of technology is eroding our planet's resources.  There are some AOL discs in here too (though they've been erased) that you might want to mail your friends as a joke.

Or maybe you really want to use these to store data.  In which case you're in luck - I've erased/formatted every one of these discs (with the exception of some write-protected driver discs - I leave them as a bookmark into the era that created them) so they're ready for you as a receptacle to your (hopefully replicated elsewhere) data.

What's that?  You don't have a floppy drive?  Well now, here's a bonus for you - act now, and I'll include an internal 3.5" floppy drive and cable!  I know it works because it's the one I used to read/format these discs.  You will need to make sure your computer has a floppy connector (my 5 year old computer still does).

Also included are a few disc carrying cases, as well as a foam shark carrying case!

Asking $20, because the foam shark is so cute!  But feel free to shoot me an offer, or send a sob story of how the floppies remind you of an long-ago-but-not-forgotten error-prone relationship, and how they have inspired you to "chkdsk /f" that relationship so that you can "xcopy a:*.* c: /s" right away and salvage what's left.

Tuesday, February 12, 2013

Orzeszek Ratings bidirectional sync

See here for a background of the problem I was trying to solve.

Orzeszek Ratings is the only tool out there to move your ratings and play counts between iTunes and Windows Media Player (on the same Windows OS computer).  I did encounter a limitation, which was that if a song was played in iTunes, and a different song was played in WMP, Orzeszek Ratings would only permit you to sync in one direction, meaning that metadata would be lost in the opposite direction.  I made a few changes to facilitate a two way sync, and the logic is the following:
Version 1.3 beta (can be downloaded from here) will inspect each song one by one, determining which metadata is the authoritative source by looking at which has the higher play count, and will sync play count, the rating, and the last played date (if applicable) to the non-authoritative source.  IMPORTANT: bidirectional sync will probably not work for you if you've been rating music on one player, but listening to it on another.  Do a unidirectional sync first to bring your ratings over to the other player.

Instructions on use:
Start up Ratings.  Select Bidirectional.  Click Sync.  Click Open Log at any time during operation to see what has been synced.


Here's the change list from version 1.2

  • bidirectional sync (all Settings are disabled, as BiDirectional needs control over all of them)
  • New setting: "Only sync ratings if playcount is higher". When used with a uni-directional sync (it is automatically on for bidirectional), it prevents a less-played song on one player from clobbering the rating of a more-played song in the other player.
  • Ability to sync Last Played Date, but only from WMP to iTunes, as it's a read-only field in WMP
  • New setting: "Only sync LastPlayedDate" if more recent. Prevents WMP from clobbering the iTunes Last Played Date if the iTunes is more recent.
  • logging in a text file to record what exactly is synced
Limitations:
  • If a song has been played in both iTunes and WMP such that the play count has been incremented exactly the same, no sync will happen, even if the ratings are different. My workflow is to sync often enough that I'd be unlikely to listen to the same song in different applications
  • Bidirectional Sync will set the playcount to be the same between the two players as it uses that to determine the direction of future syncs.  Note that the first sync will simply take the greater of the two, which is not the same as the sum of the two. If the sum is important to you, use one of the unidirectional options with "Aggregate and move play counts" first.  After a bidirectional sync, the playcount in both players will then represent the total playcount of the song.
The sync does not touch your files - it only manipulates the respective Music Management System databases, but there is always a risk that it could corrupt what's already there (especially if the process is interrupted somehow by something like your OS crashing).  I strongly recommend you back up the MMS databases prior to your initial sync.  Of course, once your sync has happened, one MMS will effectively be a backup of the other.  All the standard disclaimers apply, and specifically I make no guarantees on the safety of this tool on your system. I've only tested it on a single machine -- mine -- and there is always a chance that you may have that one machine where it fails. That said, I've been running the sync weekly for the last months, and it's been stable for me.  The source code is available in case you wish to scrutinize it.

If you have any feedback on this version, post it in the comments below.

Syncing ratings and play counts between iTunes and Windows Media Player

I have a huge music collection, mostly because I have very diverse musical tastes.  I will give every genre of music a chance.  Organizing it, however, is a bit of a pain.  One day, I will tag my mp3s and make sure their album art is correct.  With a 11,000 song collection, that day will probably never come.  I needed a way to sort out what is actually worth tagging, and rating the music is the best way.  So I began, about 4 years ago, to listen to every song I have and rating it.  I spend very little time on my computer actually listening to music, and the only portable device I had capable of rating the music was a Dell Axim X51v PDA, running Windows Mobile OS.  I'd sync a gig of music onto the device, then listen to the music while commuting to work, giving star ratings to each song.  When that playlist became fully rated, I'd sync a new, unrated set of music.

11,000 songs will still amount to over 700 hours of music, so I'd take some shortcuts...such as allowing myself to tap Next after half the song was over (usually a 1 star).

Anyways, many hours later, my collection is finally fully rated.  I knew leading up to this that I was going to face one critical problem - my music was only rated in Windows Media Player, but my Android device had no way of syncing ratings to it.  I certainly wasn't going to lug around two devices just to listen to music, so I needed a way to get my ratings over from WMP over to iTunes so I can use the iSyncr app to sync to Android.

After much searching for a solution, I came across Orzeszek Ratings, which promises to get ratings from one platform to another.  Hooray!  It worked wonderfully, and now I had ratings in both music management systems.  However, I now had a different problem - I still use WMP as my player of choice at home for its ability to share the library with other DLNA devices.  I might update ratings in iTunes with iSyncr, so I also needed to be able to sync back to WMP, but if I had updated some ratings in WMP (for different songs), the one-way sync of Orzeszek Ratings would overwrite them with the iTunes ratings.  Fortunately, the developer of Orzeszek Ratings has made his software open sourced, meaning I've been able to crack it open and put in a two-way sync feature, which I've been using a few months.  Details are here.

Monday, November 21, 2011

Windows XP is not dead

While you can't buy a Windows XP PC anymore, the 9-year old operating system is far from dead.  Microsoft still supports it, as far as keeping the Windows Update site running.  Also, on non-hyperthreaded/single CPU systems, it is probably the fastest OS.  However, that could still be quite slow, if your PC is exactly as it was when you bought it (256mb ram, 20gb hard drive).  When you first brought that computer home, it probably would've been quite snappy, but 9 years of Windows Updates and memory-hungry browsers have also bogged down the OS.  With all the latest updates, you'll need more hardware.
I had enough parts to rebuild a PC for a friend, and put XP Pro on it.  The original hardware was an Athlon 1600+ (1.4ghz), 512mb ram, 20gb 5200 rpm hard drive.  It worked, but after any kind of extended use, it started madly thrashing to disk.  I decided to put in a few upgrades to see what kind of impact it would have.
Original:
Startup time (from Windows logo until the red shield appeared to indicate a lack of antivirus): 1:03 minute
IE startup: 22 seconds
Chrome startup: 42 seconds
Power off: 43 seconds

Let's bump that up to 1gb of ram to reduce the thrashing:
Startup time: 47 seconds
IE startup: 37 seconds
Chrome: 31 seconds
Power off: 19 seconds

Ok, that's better, but let's substitute for a 7200rpm 40gb drive:
Startup: 36 s
IE: 33 s
chrome: 8.8 s
Power Off: 12 s

So, if you (or possibly your parents) are running XP on anything less than 512 mb of ram on a 5400 rpm drive, you could more than double the performance of the computer just by throwing more ram and upgrading the hard drive.  Of course, sourcing the parts may be a problem (stores stopped carrying IDE drives about 4 years ago), but if you have another dead PC somewhere, you may be able to combine the parts to make something usuable, for free.

Saturday, October 29, 2011

PCI TV tuner card review

TV tuner cards
My father requested me to digitally record a tv show for him recently.  I don't have a PVR, so my only option was to use an analog TV tuner card on the analog RCA-outs of the digital Telus Optik tuner box.

I used an ATI TV Wonder PCI card extensively about five to fifteen years ago, and it worked well.  However, my brother left me two other tuner cards, both newer than my ATI card.  I did try them in the past, but had the bare cards only, without any drivers or identification on the cards themselves (other than the chipset).  I had no success in getting them to work.

Over the years, I eventually found the boxing and drivers, but didn't have a chance to try it out till now.  Here are my findings (which won't be too useful to anybody out there now, unless someone is trying to get old hardware to work)
ATI TV Wonder PCI
Manufactured: 1999
Software: MMC, version 7.9 (newer versions would not properly redraw the video overlay if, for instance, the window were resized).  Also, there'd be odd problems with the record button not showing up.  7.9 is the newest stable version I could get to work.  Features like video-shifting, while present, do not work or could cause the computer to crash.
Driver: tvw-pci-ve-driver-1-11-0-0.exe
Scheduling: Scheduling programs to either watch or record has always been reliable.
Recording options: Once recording, can set a time or duration when it will stop

3DeMON PV951T
Manufactured: 2000
Software: a barebones tv watching and recording software.  No keyboard support.
Driver: On the driver CD are Win2k drivers, which will work with XP.  Caveats: it will greedily use the ATI drivers, which will only provide composite (RCA) and svideo inputs; the tuner itself will be unavailable.  I was using a Windows XP box that I'm going to reghost after this testing, so I made frequent use of System Restore to roll back the system state to prior my ATI driver installations.  Only then could I point the driver search to the CD.
I searched all around the internet for actual working drivers.  It uses a bt878 chipset, which is also what ATI uses, but the generic bt878 drivers I found online don't seem to do the job.
Even after I got the device manager to stop showing yellow exclamation marks, however, I still couldn't get any audio out of this card.  Most PCI tv cards don't provide audio directly to the system; rather, they pass it to the sound card.  With the ATI card, audio passed in through the CD input to the system.  With this card, there's no internal connector, so one must use a 3.5" audio cable to connect the audio-out jack to the line-in jack of the video card.  A bit clumsy, and in this case, not working at all.  There was simply no audio-out, regardless of the drivers I used, regardless of whether I used the 3DeMON TV software or the ATI software (which worked as well since the chipset is similar).
Scheduling: none
Recording options: the TV viewing software sucked so much I didn't bother trying to record.

Leadtek WinFast 2000
Manufactured: 2003
Software: probably the best looking software.  The best feature was the ability to record in whatever aspect ratio was specified.  For instance, if 16:9 was specified, the resulting video would appear in 16:9 (as viewed in VLC).  ATI's would insist on recording the video letterboxed.  The software seems generic enough to work with the ATI hardware.
Driver: I found this on the internet years ago.  XPWHQL.zip  I don't know where you'd find it now.
Recording options: When recording, also has ability to specify how much longer to record for, and whether to shut down the computer when down recording.  The other big plus is time-shifting, which allows you to pause the live program you might be watching, and return to it later (and skip commercials)

The one caveat when recording from the Optik box (from any of these inputs) is that Optik will reset the aspect ratio to 4:3 when it detects an HDMI connection (which happens when you switch your TV to the HDMI input).  This isn't terrible - it's just that the picture quality would be squished in sending to the TV card.  One needs to navigate the Optik menus to switch back to 16:9 aspect ratio.

Phantom power - should we care?

I wanted measure the relative electricity consumption of various devices around the home, especially with regards to the so-called phantom power.  Phantom power is a power draw used by devices that are plugged in, even when they are not actively turned on (like televisions, VCRs which do nothing except for display the time, and computers). You've probably heard the occasional reminder from your power company about the significance of phantom power.  I've wondered just how significant this is to our power usage, so I bought a power metering device from Zellers.  It provides the real-time power usage of any device plugged in.  Here's some data:
Compact fluorescent lamp: 19w
My Windows Mobile PDA on, and charging: 12w
Same, only charging and not on: 1w
24" LCD monitor, on: 22w
same monitor, off: 0w

Yamaha 67 key musical keyboard (on): 7w
Same, off: 3w
PC: 9w when off, 112w when on
laptop (on): 53w

Phone charger (microUSB), nothing plugged in: 0w

Phone charger (microUSB), phone plugged in: 3w

The phantom power of a bunch of devices plugged into my computer power bar 17w
Phantom power of a bunch of devices plugged into my media centre: 22w


BC Hydro charges our home a basic fee, and a variable fee.  The variable is $0.0667 per kWh.  A kWh is the amount of energy used by 1000W for one hour, or 100W for 10 hours.

As far as phantom power on all my devices goes, that's about 40w * 720h = 28.8 kwh , or less than $2, which is basically not all that significant, costwise.


D complains whenever I need to leave the computer on overnight, so I calculated that for 8 hours:
112/1000 * 8 * 0.0667 = $0.06.  For those who leave your computers on 24/7 for the the entire month, this is $5.38.


Where is most of our power going then?
lighting - incandescent bulbs are notoriously inefficient
cooking - there's a reason they're plugged into 240v outlets

We don't use the drier, and seldom use the dishwasher, so none of our power is going there.

As an experiment this month, we've refrained from switching on our home heating (forced air) and will only use  electrical heating (portable space heaters) for our home.  When our next bill comes, we will compare it with the same period last year where we used our home's gas heating (which doesn't work very efficiently anyways in our home) and will compare costs.  I suspect the cost difference will be less than $10 since our regular variable rate for gas is also quite low.  If so, the savings won't be worth the inconvenience of lugging our space heaters around and the temporary pain with leaving our localized warming areas.

**all costs are minus HST**