It’s been a while since I’ve written anything. Ideally, I need some good inspiration from real life to actually write something. I’ll be sharing a story with you all today.
I’ve observed a common mistake that most juniors make in our industry. They are impatient. They want to jump to action as soon as possible. I cannot stress enough how important it is to be patient and assess the situation first before shooting your gun.
So, here’s what we wanted to do. We made a holographic pyramid. Custom made by us. And we want some way to run a video on loop on it. For this we got a Raspberry Pi 4 1GB model. Which is by the way is a very powerful hardware if you ask me. Our objective was very simple. We want to loop a video whenever we boot up the pi. And since it’s going to be in the form of kiosk, we do not want to manually press buttons to do it. As soon as the system boots up it starts running. Simple.
I explained to the junior that we wish to loop this video as soon as we boot up the pi. And I left to do something else. After an hour I returned to see how it looked and he was still on it. I got very curious as to why it was taking so long. I mean it was probably something like a 10 min task. And it’s not like he was the kind who slacks off. On the contrary he was a very serious type and focused on efficiency. I went ahead and saw him installing a python package and OpenCV. I got curious as to why he needed OpenCV. I initially thought since he has the pi and I was away for too long he wanted to play around with it and see what is possible. But to my horror he replied that he wanted to run the video with OpenCV and a python script. While it is most certainly possible to do so. But that’s like using a canon to kill a mosquito. I immediately stopped him.
I mean. This was really a 10 min task. All we had to do is find a way to run a media player whichever that may be with the said video at the startup of the operating system.
So, what I did was simply look up where is the Autoplay at startup file for Raspbian Buster as I didn’t know. And I wrote a bash script to run the video from the VLC player. Why VLC? Because the pi had it installed. No other particular reason. I referred the bash script to the Autoplay file at OS level. And restarted the PI. And it worked! It took me at best like 10 mins to google and do all of that.
Now why am I sharing this? To flex? Not exactly. I mean those who know it’s nothing to flex about. However, it’s very important to understand why I am sharing this. If I had not stopped him, he would have had it running. That is for sure. But just getting it running will not cut it. There are some major problems that will be ensuing. Firstly, what he was doing was a waste of his precious time. We have all these tools. Python and OpenCV are great tools to work with and strong tools. But just because you are good with one tool doesn’t mean you should force it for everything. You could certainly hammer down a nail with a screwdriver base or a wrench but should you really?
We are engineers not brutes. Our strength lies in our brain, and we should utilize it properly. Before we do something, we should make an analysis first then try to figure out the best tools that we can use to solve the problem and then and only then we should try to solve the problem. If we realize that we do not know the best tool to use to solve the problem we should try to learn the new tool and it will help us grow, instead of trying to hammer down everything with the tools we know. OpenCV is a heavy library that is used for image processing. And it’s compute intensive. Why I mention it I’m coming to it just after a moment. It’s not for rendering videos. There are video players that are optimized to render videos. And I must emphasize optimization because in this case the trouble doesn’t end with just getting the video running.
Let’s move on a bit further. Remember I mentioned OpenCV is compute intensive? Here’s the reason. The video was playing nicely however after 3–4 loops the Pi Hanged. Why? It was overheating. Now if you don’t have the experience you might come to a few wrong conclusions to move forward. For example, you may say the pi itself isn’t good. We need new hardware. Or we need more processing power. Or perhaps a cooling system. We immediately kind of try to figure out the easiest possible solution for us without considering all the possible solutions that we do not know yet. I asked why was the Pi overheating from running a video file? I mean it’s running a whole OS fine. And it can certainly overheat but why particularly from a video file?
Firstly, we have to agree is the processor is busy doing something. It’s playing on a video player. Now it’s either the video player that’s heavy or the video encoding.
It was an MP4 file. And I kind of assumed that the Pi was getting overheated from the decoding it had to do for the video. So I recommended that we convert the video into some other format where it’s more optimized and doesn’t have to go through the encoding. Perhaps a raw video. I mean the pi itself has no other task that running a video. And it’s not going to be any issue if the file itself was larger.
We converted it to .webm format and ran the video. Even after running it for 8 hours straight the pi was no longer overheating.
I can’t help but wonder what would have happened if we used OpenCV for playing an MP4 video.
Now here’s something important lesson for juniors. I’ve seen people getting huge AWS bills. Or vertically scaling a system where their source itself could have been better. Now that memory and processing power have become cheaper, we do not respect it anymore. Once upon a time our ancestors used to write games on 40kb of memory. If you look up super Mario image it’d probably be over 100kb of size but the whole game was fitted into something less than 32KB memory. It’s important that we respect the hardware instead of just slapping in whatever we can.
The takeaway from this is when we are trying to solve a problem, we need to take a step back. And try to understand and analyze it first. And figure out how it’d be best to solve it. Once we are satisfied with our research only then we should jump in. It will save you time. And time is money. Otherwise, you would end up worrying about new problems that shouldn’t even exist in the first place.
Also, in case you are interested in seeing how our Holographic Display look here’s the link.