Pandemic Journal, Day 615

I finally finished extracting all of the clips I need for my speech tomorrow. I wanted to avoid using the “Share Screen” option in Zoom, so I planned to use Open Broadcast Studio and set up a scene which would just show me, and another scene which would show a clip; I could fade between them and it would look professional.

I got the video to work easily, but I spent a long time trying to get the audio under control and failed; I even installed a virtual audio router but had no success – I couldn’t get the audio from the clip into Zoom, even though OBS showed that input as active.

I finally gave up, which is ironic since I’m using clips from Galaxy Quest!

Pandemic Journal, Day 614

A few days ago, I wrote about optimizing the process of extracting short segments from a video file to avoid having to copy the entire source video. My improvement was simple, elegant, and wrong – when I looked at the video I created, it didn’t start where I expected; it started and ended early every time. I “fixed” the problem by telling the program to add a little time at the end and by using QuickTime to trim the video by hand, but that seemed silly.

Today I figured out the problem. I’d assumed that when I told ffmpeg to extract a piece of video starting at a particular time, it would do that – but it can’t. It has to back up to the most recent “key frame” in the video, so the starting point will be a little earlier than specified, which threw off the rest of the calculations in the script and gave me a trimmed video that started and ended too early.

So in the end, I wound up writing unnecessary (and ugly) code that did more processing than necessary to extract a clip that I still had to edit manually anyway.

Premature optimization is the root of all evil.

Pandemic Journal, Day 613

I got a message from the Post Office around 8am, telling me that the coffee they didn’t deliver yesterday (“at customer request”) was out for delivery again – and it arrived around 2:30pm. I opened the box to make sure it was what I’d ordered and put it away; I won’t need it for at least a week.

I’d also ordered bagels from New Yorker Bagels for this weekend – they ship FedEx Priority Express, so they were supposed to arrive before 1pm. But at 1pm, they were still “at FedEx location” – but they arrived just before 4pm, in plenty of time for lunch tomorrow.

And I found that I can use QuickTime Player to trim video clips, which means I don’t have to specify precise timing when I run the script I talked about on Wednesday to clip a piece of video from a movie. Trimming a second or two from a 30-second clip is easy in QuickTime; using it to pull a short segment out of a longer video would be much more finicky.

613 days…that’s one per mitzvah. Hard to believe!

Shabbat Shalom!

Pandemic Journal, Day 612

I’ve been ordering coffee from Doka Estate in Costa Rica ever since we visited them last February. The coffee is fresh and good, the pricing is reasonable, and delivery is quick – usually about a week from order to receipt. And it brings back nice memories every time I drink it.

I sent them an order to replenish my supply when I got home from Boston. The first notice I got from the Post Office said it would arrive next Monday. Then I got another notice saying it was in San Jose and I’d get it tomorrow. This morning, the Post Office said it was “out for delivery” and I should expect it today. And this evening, they claimed it had been held at my Post Office “at customer request”, which surprised the customer!

I guess I have a trip to the Post Office in my near future.

Pandemic Journal, Day 611

I spent most of the day working on a talk for Toastmasters; I want to illustrate it with short clips from a movie. There must be an easy way to mark two points in a MP4 file while you’re watching it and copy what’s between them into a new file, but I couldn’t find one – what I did find was this page which had shell scripts that did some computation, then called ffmpeg to perform the actual extraction. The scripts worked as advertised, but I wanted to make two improvements.

The first was to be able to supply sub-second timestamps for clipping; Bash can’t do decimal arithmetic, but the bc command can, and that was an easy change to make.

The other improvement I wanted to make was to avoid having to make a full copy of the source file with “key frames” added at the exact points I wanted to start and end the clip with. The original author was working with short files, but I was working with a full movie that was nearly 2GB in size – making a copy of such a file takes a while, even on a fast machine with an SSD.

I thought about it and came up with a workaround. I extracted a few seconds more than I wanted (without having to add key frames); then I put key frames in at the right points in the extracted video (which required copying it, but only a 10-15MB file, not multiple gigabytes); finally, I extracted the exact part I wanted.

This was easy, but it required multiple calls to bc to do the calculations. And I needed logic in shell script, which is not my strong suit. But I eventually beat it into submission, and it seems to work.

I realized afterwards that it would have been easy to write a short Python program to do the calculations and write out the exact commands I’d need – and there’d be a much better chance of understanding it if I ever had to modify it. But unless I run into yet another problem, I’m going to leave the code alone.

Having elegant code is nice, but going to sleep is better.