Formats, formats everywhere!

Every programmer reaches the point in their work, when interesting technologies become less of a stimulant for happiness. We start to search for exciting projects that deal with difficult topics, not necessarily related to programming. Once in a while, a mythical domain emerges.

We, at VirtusLab, are lucky to have found such a domain. The project we work on is an advertising platform. We lead the client from placing an order, supervising the entire process of sending an advertisement video to the broadcaster, ensuring that the video meets all standards of a specific TV station, and broadcasts on each receiver correctly.

Sounds trivial, right?

Let’s take a deeper look at the challenges with frame rates.

When 2 x 2 = 3.996

Multiplication is an easy task. Or so they say… It appears to be much more complicated when it comes to frame rates, especially 29.97 fps. Actually, it seems to be as hard as deciding which years are leap years.

Here’s a story of a certain domain-specific problem we had to solve on our journey through lines of code and cups of coffee.

Enjoy!

Why do different frame rates exist?

Our lives would be much easier, if there were a common standard of frame rates. So, why do different frame rates exist? The reason for the variety is simple: The frequency of the electric current.

When video transmission formats were invented, accurate clock circuits did not exist. Creators reused the current that was already “implemented” in electrical sockets and divided it by two. Yeah… if only they were consistent across the globe. Europe used its base clock with 50Hz, and America started using 60Hz. That resulted in 25 fps and 30 fps video standards.

What could go wrong, you might ask?

In short, everything. After introducing colour to film, the 25fps standard kept working fine, while 30fps started to show some issues. Due to track interference of 30 fps, you could choose either colourful video with no audio or black and white with audio.

What’s the solution?

Decrease the frequency by 0,1%. Why not some other value? Because that will work fine.

Is the 29.97 frame rate hard to handle? No way!

It will work fine until you face the next problem: The length of your material. How long is your video in seconds? When dealing with 25 fps, the answer is as simple as the question. A 250 frames long video lasts 10 seconds. Easy, isn’t it? Also, showing time codes as hh:mm:ss:ff is easy.

So let’s take a look at the time code after playing 112 seconds of the video. That’s four full seconds. This means, four seconds times 25 fps is 100 frames and 12 spare frames, which gives us 00:00:04:12.

Let’s apply the same calculations to 30fps this time. How long is my 300 frames video in seconds? 300 divided by 29.97 is 10,010010010…

I believe three coffees are not enough to understand this evil.

Let’s grab another one and ask ourselves a different question.

Can I drop some frames the same way I skip February 29th?

That’s a perfect question. So how can we approach this case? Well, given that a year lasts 365,2425 days in reality and humanity managed to establish a calendar which uses only integer numbers, by dropping a day sometimes, why shouldn’t we do the same thing?

We can, and we should!

We’ll spare you some mathematical nuances and go straight to the formula:

Each second consists of 30 frames, and seconds forming full minutes consist of 28 frames. Unless they make a minute divisible by 10 (10th, 20th, etc.) in which case they have 30 frames.

Still following? Take a sip of coffee and let’s move on.

Now we can go back to our 300 frames example. Does it mean it’s simply 10 seconds? Yes, it is. The time code describes it as 00:00:10;00. Mind that the last separator is a semicolon that represents the time code value in the drop frame format.

Let’s tackle another example. What is the time code duration for a 2400 frames long video? It’s 00:01:20;02, because the last 2 frames were “carried over” from the second that comprised a full minute.

Can it get more difficult?

Of course, it can! There’s still some more coffee left, isn’t it?

What happens if we merge two videos, each represented as 00:00:40;00? Or rather, what would happen according to business people who are unfamiliar with drop frame calculations?

For them, it’s a very simple calculation. Two times forty seconds gives a minute and twenty. So, 00:01:20;00 is the answer!

No, it’s not.

It’s 00:01:20;02 because of the dropped frame. Do not try to explain it to them. Simply implement a calculator that converts time codes to frames, performs calculations, and converts results back to time codes.

Is the joke on NTSC?

Unfortunately, it is. But let’s start with explaining the name NTSC. Originally, it was an acronym of the agency that invented the standard. It was called the National Television System Committee. By using this standard, TV creators had to compensate for the dropped frames.

Their chosen action had some trouble representing a video’s colours by distorting them randomly. Since then, the acronym NTSC also stands for: Never The Same Colour twice.

Can I join you and help tackle the problem?

Yes, of course! At VirtusLab, we use all the above knowledge to a great extent in one of our projects. One of the biggest commercial delivery systems worldwide is obligated to provide clients with perfectly accurate time codes. We are helping them to achieve this goal, regardless of the ad’s format (NTSC, PAL or anything else).

We are also handling a bit more exotic frame rates, such as 23.986fps. The list of challenges is bigger and still growing, though!

Are you up for the challenge to help us solve them all? If so, join the #VLteam!
Apply to VirtusLab👇
👇👇

Authors: Szymon Łabuz, Karol Skóra, Software Engineers at VirtusLab

RAPORT Zarobki w branży IT - Q3 2022

Sprawdź jak wyglądają zarobki w branży IT, na podstawie analizy ogłoszeń 3 686 pracodawców.

POBIERZ RAPORT
Oferty pracy w VirtusLab