FFMPEG and drawtext

Several years ago I wrote a program that consolidates time-lapse pictures into a directory and calls FFMPEG to create a video.

I had been wanting the time-code from when each picture was taken printed on the screen while the video was playing but had not figured out how to get it done until this weekend.

Video TimeCode

Frame from video showing the DateTimeOriginal timecode embedded.

I’d gone down multiple paths in an attempt to get this result before finally getting the drawtext feature to work. My program manually pulled the metadata from the images before feeding them to ffmpg. I’d tried creating both text files and image files for overlaying. none of those got the result that I was looking for.

When I finally got everything working, it seems simple, but the underlying problem has to do with the amount of string escaping required to get the command to work.

Here’s an example command I was issuing to ffmpeg that got the result I was looking for.

ffmpeg.exe -hide_banner -r 30 -i Wim%05d.JPG -vf crop=in_w:3/4*in_h,drawtext=fontfile=C\\:/WINDOWS/Fonts/OCRAEXT.ttf:fontcolor=white:fontsize=160:y=main_h-text_h-50:x=main_w-text_w-50:text=WimsWorld,drawtext=fontfile=C\\:/WINDOWS/Fonts/OCRAEXT.ttf:fontcolor=white:fontsize=160:y=main_h-text_h-50:x=50:text=%{metadata\\:DateTimeOriginal} -s 3840x2160 -pix_fmt yuv420p -n Test-2160p30-cropped.mp4

If you look at the -vf option parameter, I’m cropping my input pictures to 3/4 their original height, then using the drawtext feature twice. First I write the static text to the bottom right of the frame, then I extract metadata from the source image and write it to the bottom left of the frame.

Because I’m calling this from a program, I had extra escaping of the \ character in my code. All of the escaping required a lot of trial and error to get things working. I’m using OCRAEXT as my font, but I could be using any fixed spacing font. because of the fact that the time is changing every frame, it’s important that the font not be proportional to make it easy to read.

Cruise Control at 65mph

Last weekend I went to Seattle, and on the way back had the patience to drive for an entire tank of gas at 65mph. Often on a long drive I’ll have the cruise control set approximately five to ten over the posted speed limit. This time I left the cruise control speed at 65 even after I got to Idaho where the posted speed is 80mph.

A very interesting thing during the drive from Portland to Boise, the trip computer was regularly calculating the range at a number that, when added to the miles already driven, calculated over 600 miles in the tank. The pictures above are showing an estimate of 580 miles in the tank after having already driven 400 miles.

A quick calculation of driving 432 miles at 65mph vs the same distance at 75mph tells me that the faster speed only saves me 53 minutes. This time I arrived home with over a quarter tank of fuel. Previous times I’ve had the low fuel warning light on when I was still 20 miles short of reaching home. If you figure I could have put another 7 gallons of gas in the car at over $2.50 a gallon, I saved about $17.50 for that 53 minutes. It was on a day that I hadn’t planned on doing anything beyond driving point to point, so I think it was worth it. Just the difference in gas price between Idaho and Washington pushed that difference in cost to over $20.

The real calculations below show that I only achieved 22.72 mpg during this stretch, while the computer was displaying 25.0 mpg. The 16.59 in the next column is the average mpg over the entire lifetime of my vehicle.

3/29/2017 11.555  $    29.45 138615 17.40 16.56  $      2.55 201.0 4 50
3/31/2017 21.918  $    63.98 139002 17.66 16.57  $      2.92 387.0 2 194
4/2/2017 21.265  $    61.01 139401 18.76 16.57  $      2.87 399.0 2 200
4/2/2017 5.196  $    14.23 139513 21.56 16.58  $      2.74 112.0 0 112
4/3/2017 19.011  $    48.08 139945 22.72 16.59  $      2.53 432.0 1 432
Oregon I84

Oregon I84

Oregon I84

Oregon I84

Sometime I may have the patience to try driving the stretch at 55mph, which was the law when I was back in university and drove a car that regularly achieved 38mpg. Views like these last pictures are part of what makes the drive itself worthwhile.

Rental Car vs Personal Car

I’ve spent most of the last winter in Boise, but still call the Seattle area home. I own a BMW X5 that turns 15 years old this year. I ordered it from the factory with the options I wanted, and have been happy with it other than the gas mileage, which I understood when I bought it, and the electronics, which are now 15 years old.

A driving trip from Boise to Seattle is 500 miles each way. That means a trip is a minimum of 1000 miles. My X5 gets as much as 19mpg on the highway, and it requires 91 octane or better fuel. A round trip in my vehicle is going to be a minimum of 52 gallons of fuel, plus wear and tear on the vehicle itself.

I did some quick research and figured out that a comfortable sized rental car would include a Ford Focus, and it should get about 38mpg on the highway, and it would probably take regular fuel, which is already 20¢ per gallon cheaper. I’d driven a Focus in Hawaii in the past and liked the way it drove so was interested in trying it out for this purpose.

I’d plugged in my start and several destinations into Google Maps and come up with a distance I’d drive of 1200 miles for estimation purposes. I created a simple spreadsheet with rough details. I was hoping to get as many as 38mpg in my rental car, which meant that I’d get a savings of over $100 towards paying for the rental car.

Rental Car BMW X5
1200 1200 Miles to Drive
38.00 17 Miles per Gallon
31.57895 70.58824 Gallons of Gas
 $       2.57  $     2.79 Average cost of Gas
 $     81.16  $ 196.94 Total Cost of Gas
 $ 115.78 Savings by using a rental car

I rented from Budget. They didn’t have a Focus, but I got a Nissan Sentra that had very nice electronic toys for me to play with, including Bluetooth connectivity for my phone for both music and telephone calls. It also connected to my phone via the USB connection which seemed to have slightly better audio, plus keeping my phone charged the entire time. The rated MPG seemed to be about 5mpg less than the Ford, but you take what you can get.

After the drive, I tallied up my gas receipts in the fashion I keep track of with my X5 normally.

Date Gallons  Total Mileage MPG Average MPG  Dollars/Gallon Miles In Tank
11/3/2016 1.212 2.86 18200  $     2.36
11/3/2016 9.222 23.97 18538 36.65 36.65  $     2.60 338.0
11/8/2016 8.284 20.37 18806 32.35 34.62  $     2.46 268.0
11/8/2016 3.552 2.239 18924 33.22 34.38  $     0.63 118.0
11/8/2016 6.359 16.4 19122 31.14 33.63  $     2.58 198.0
11/9/2016 6.673 15.74 19346 33.57 33.62  $     2.36 224.0

And then I transferred that data into a duplicate table like the first one.

Rental Car BMW X5
1146 1146 Miles to Drive
33.62 16 Miles per Gallon
34.09 71.625 Gallons of Gas
 $       2.31  $     2.53 Average cost of Gas
 $     78.72  $ 181.15 Total Cost of Gas
 $ 102.43 Savings by using a rental car

I didn’t get quite the mileage that I was expecting to get while driving the rental car, and it seemed to go down as I drove it longer. I’m guessing that it was largely related to my being more of a leadfoot the longer I was in the car. I paid $171.78 for the rental car, so the estimated gas savings mean that I paid less than $70 for not having wear and tear on my own vehicle.

Nissan Sentra Instrument Pod

Nissan Sentra Instrument Pod

Nissan Sentra

Nissan Sentra

My First Personalized Luggage

I have been purging things recently and after getting rid of my Samsonite luggage, it was time to get rid of my Skyway luggage as well. While I think of the Samsonite as my first luggage, it was originally my mothers, while this Skyway was purchased for me.

Skyway Side View

Full Case Side View

Skyway Handle

Handle with personalization.

The last time I used this luggage for flying was obviously on a trip to Zurich. It’s also interesting that it has GVA inspection stickers on the slide locks, for when it went through Geneva Switzerland.

This was very nice luggage that I was probably given as I went off to university in 1985. It was the first generation with four wheels that you pulled behind you instead of the two wheel style of the earlier Samsonite. Two wheels rotate, while two wheels stay straight. It had a leash that connected to a hook on one end and could be snapped to the top for storage, or as was generally recommended, disconnected entirely so it wouldn’t get pulled loose in transit.

This design was not a hardside like the Samsonite, but had a sturdy outer fabric. It wasn’t as moisture resistant, but was generally nicer. It had a stiff outer frame, and the sides were softer and somewhat flexible.

I carried this luggage back and forth to Europe with me many times in the early 1990s. A nice feature of this design is the ability to open it on a luggage rack and rummage through the contents. The style of the Samsonite required double the space to open it.  Both of these were before the modern habit of luggage that’s designed to be carried on in the passenger compartment. When I was flying with this I could also carry on a garment bag and have it hung in the closet in the airplane.

The heavy use of this bag over the years has obviously bent the frame around the wheels, causing one to come off entirely, and the others not to sit straight.  Having a combination lock was nice because it could be secured without worrying about having the right key to open it. This was all in the days before TSA. Back then, the only time your bag would be opened for inspection would be in your presence, usually as you were going through international customs.