zondag, mei 29, 2022

Apple M1 hardware acceleration of H.264 and H.265 encoding

I have a video file that I want to share with some friends. The file is 413,5 MB and contains 29 minutes of video and audio in 1920x1080 resolution in H.264 video codec. The audio is mono, AAC at 32K Hz sample rate.

Like I said, this file is now 413,5 MB, and it could be quite a lot smaller, if only I compressed it a bit, maybe halved the resolution as well 🤔 

I’ve in the past done a lot of video compressions already (wrote about if before as well, even made it to Hacker News by accident). It just never occurred to me that my beloved FFMPEG tool might not be using the best settings out-of-the-box.  

FFMPEG is an incredibly powerful tool, a real “power tool” and it is really easy to “shoot yourself in the foot” with it.

The thing is, you have to specify EVERYTHING. So you are using a new Apple workstation with the very powerful M1 processor, which contains a built-in H.264 and H.265 dedicated encoder/decoder? Good for you, but FFMPEG will not, I repeat, NOT, use it, unless you ask it, kindly, in the command line, every time you do a conversion.

Having said that… the standard settings kind of do make a lot of sense for most situations…

Using M1 dedicated encoder/decoder

For everyone who found this page by just Ducking and wants to know the magical incantations required to make the M1 tango with FFMPEG, here it is:


or, in context:

ffmpeg -i input.mp4 -c:v h264_videotoolbox output_h264_VT.mp4


The conversion is happening at a staggering 7.56x, so a 29 minutes file only takes 3:50 to re-encode! 

Unfortunately, I immediately notice that the video now has visible artifacts… it really looks a lot worse 😢 

We do get a very small file though, it’s only 90,8 MB for half an hour of full-HD video. But like I said, it’s no fun to watch a horrible mangled video like this.

H.265 to the rescue?

Maybe using the newer H.265/HEVC codec will make the video look better?

The full command now reads:

ffmpeg -i input.mp4 -c:v hevc_videotoolbox -tag:v hvc1 output_h265_VT.mp4

  • The option -tag:v hvc1” is added to make sure QuickTime will still recognize the file format… again, don’t ask me why this is necessary. 

Okay… We get a similar compression time of 3:46 minutes. The output file is now 203,5 MB, which is still a 50% reduction from the original. 

There are still artifacts visible in the resulting video file. 🤔 

Now, if we instead use the old-fashioned and laptop boiling method of running the compression over the CPU instead of the dedicated circuitry, maybe the file will be higher quality?

ffmpeg -i input.mp4 -c:v libx265 -tag:v hvc1 output_libx_h265.mp         

40 minutes and a burnt lap later…

Yes, we do have an even smaller file (just 184.6MB now), which also has a better looking video quality 😊 


Hevc_videotoolbox gives you a very fast compression but with an abysmal video quality.
Libx265 will make you wait, for a much better looking and smaller video.

maandag, april 18, 2022

Your internet might be slower than expected, except when you test the speed.

Ask HN: Internet magically gets faster when opening speedtest? | Hacker News

Yes, and, the joke in the industry is that network speed tests are to network performance what the Volkswagen Diesel was to emission tests :).

All carriers implement various types of throttling or rate limiting, for a lot of reasons (anti-ddos, cost control, etc.)

But; universally, they bypass these rate controls such as Cisco PGW ADC (Application Detection and Control) and LTE eNB ABR for wireless as examples, and many others similar features that limit the rate the user actually gets. And in almost all cases, these systems are designed to allow speed tests to bypass the rate limiting.

Commercial Speed tests are in no way a valid or reliable way of understanding the quality of a network service. I am a little surprised that this is breaking news on HN however. I would think this would be pretty well understood by this community?

BTW. Fast.com does is not always immune to this "Volkswagen diesel" effect. The only way to know for sure is to have a VM or bare metal server someplace and do an iperf to it.


vrijdag, april 01, 2022

Hoe kan ik de JW Library app op mijn MacBook Air or Pro of iMac installeren?

Tegenwoordig is het mogelijk om apps die voor de iPhone of iPad gemaakt zijn te gebruiken op je MacBook Air/Pro en iMac, als het tenminste een model van 2020 of later is waar een M1 processor (of nieuwere "ARM" chip) in zit.

Dat klinkt moeilijk, hoe kan ik zien of mijn Mac een M1 chip of nieuwer heeft?

  1. Start je Mac op, en wanneer je bent ingelogd, klik links boven in de hoek op het appel🍏 logo en klik op dan op [Over deze Mac]
  1. Het venster dat nu in beeld komt geef aan wat voor chip er in je pc zit. In mijn geval zien we "Apple M1", maar als een nieuwere Mac hebt kan daar "M1 Pro" of "M3" of iets dergelijks staan… Deze zijn allemaal goed voor ons doel: een iPhone/iPad app installeren en draaien op de Mac. 
  1. Nu we weten dat onze Mac het aankan, gaan de app opzoeken in de App Store. In de App Store typ je de naam van de iPad app die je zoekt. Het kan goed zijn dat je eerste zoekresultaten niet zijn wat je zocht: 
  1. Om iPhone of iPad apps te vinden moet je in de App Store nog klikken op de knop…. [IPhone en iPad-apps]: 
  1. Als laatste stap zoek je nu de app die je wilt installeren en klik op het wolkje-met-de-pijl-naar-beneden symbool, Apples manier om te zeggen "download uit de cloud": 

Wacht een paar seconden… en nu is je app geïnstalleerd 😃 

vrijdag, maart 18, 2022

Preventing burn-out by changing your work ethics.

After reading this article in the Baffler and after reading these HN comments I came up with my own set of rules to prevent burn-out:

I've long suspected that my work ethics shield me from getting a burn-out. These ethics are:
  • work is a way, a tool, a means to an end: to make money. 
  • If work becomes more (a way to meet people, a way to have a higher status, a way to fill time) then it should be culled, cut off, put back in its proper corner.
  • work should not be enjoyed too much. Lest you come into temptation to do more of it than necessary.
  • work should also not be too boring. A little challenge now and again is fine.
  • work should be done diligently (you should do the required tasks, and recommend improvements). Any time your suggestions for improvements are sworded down, you should NOT worry. After all, you only work for money, not for your ego.
  • work should be done honestly (no lying, stealing or cheating).
  • Do not take shit from colleagues. Talk to them about their behavior. No change? Talk to the manager. Still no change? Transfer or quit this job.
  • Do not take shit from managers or your boss. Be open about this and direct: the buck stops here. Period.
  • It helps to have F-you money. I suggest 2-3 years salary is a nice stash. 
  • work should not be done too much (working 2 to 4 days per week seems ideal. I've worked for 3 days a week for years and can highly recommend it).
  • You do not work overtime, not even when paid, unless there is an emergency. If there are more than 1 emergencies per year, then the company's definition of an emergency is wrong. Look for a less toxic company.
  • You do not do any unpaid overtime. Work is for money. No money means no working. It's really that simple. But would you really want to abandon your colleagues/coworkers? No, but it's the task of the shareholders or company owners to chip in, not yours.
  • When fired, give yourself a year sabbatical.
  • In case of being fired, do not take it personally. Were you really under-performing, or was your new manager just not able to appreciate your work? Hint: he was too short-sighted to see your work's true value. 
  • But what if the manager was right? Maybe you do suck at this. It is better to think about such soul-searching things after the sabbatical. When you still agree: look for a whole new kind of work. A different position with fresh perspectives.

zaterdag, maart 12, 2022

Why Modern Movies Suck - They Teach Us Awful Lessons

Een interessant filmpje over de "levenslessen" die je vroeger leerde uit films, vergeleken met wat je er nu uit leert.