Flicker in video
There are plenty of guides on how to avoid flicker, (basically match the frame rate and/or the shutter speed to the frequency of the electrical network), but I couldn't find a good explanation of why the shutter speed method works. So I made my own.
Table of contents
Types of flicker
Flicker is the periodic dimming of a light source. Depending on the frequency with which it dims, on the length of the dark period and on the ratio between the full illumination and the dark period, it can be noticed by the human visual system, or it can even cause health issues, such as headaches. Here is a simple but thorough explanation of the phenomenon: the UPRtek Flicker Handbook.
In this article I'm not worrying about the actual illuminothecnics, I don't design the illumination systems of buildings, I just shoot videos in them. In particular I've had trouble with some VR cameras, because they don't allow you to set an arbitrary frame rate. In video we don't particularly care about the physical properties of the flickering light, we just need to know its frequency. Visibile flicker in video is caused by a mismatch between its frequency and the frequency at which we sample light.
This happens when the primary source of illumination in the scene is producing the flicker. In this example the global flicker is particularly easy to see on the ceiling. Here it's just annoying, but when viewed with a virtual reality headset it's a serious problem. This is made worse by the anatomy of the human eye, because our peripheral vision (with a prevalence of rods over cones) is most sensitive to movement, and therefore to flicker. Flicker is also related to luminance: the more light there is the easier it will be to perceive flicker.
This happens when the primary source is either natural light or in sync with our temporal sampling, but a specific source of light in the scene operates at a different frequency. This is typical of neons and, here in Europe, of computer screens. Our electrical network operates at 50Hz, and screens usually update at 60Hz. In this example you can spot it both on the screen on the left and on the one in the far back.
How to avoid flicker
Avoiding flicker is not that hard, if you know at what frequencies all the light sources operate. First of all you should focus on global flicker, as that is a show stopper. There's plenty of footage with local flicker getting published every day, and most people don't even notice it. Luckily, in most cases all you need to know to avoid global flicker is the frequency of the electrical network of the country you are in, here's the map from Wikipedia.
In most cases your camera will be already set to the correct frame rate, because that's how the PAL and NTSC frame rates were determined. If you are in Europe and your camera is set to PAL, the frame rate will be either 25fps or 50fps, so you don't need to worry. Depending on the hardware or the requirements for your project you might need to work with a different frame rate, or you might be in a different country (and you still need to produce footage in your native frame rate). In that case you should set the shutter speed to a multiple of the frequency of the electrical network.
For example, my VR camera only shoots full resolution at 30fps, which is already sort of low for VR, 25fps would be unusable. In order to use it avoiding flicker I have to set a shutter speed that is an integer multiple of the network frequency.
There are some edge cases I haven't considered yet: for example I'm not quite sure about the details of what happens when a PWM dimmer is employed. Also, you should keep in mind the normal considerations about picking a shutter speed, so mostly the 180° rule for motion blur, footage looks "normal" to most people when the shutter speed is roughly double the frame rate. For example, it's common to use a 1/50s shutter speed with 25fps.
Why it works
There are plenty of sites that have the information in the paragraph above, but what is lacking is an explanation of how it works. It is quite simple, but not entirely intuitive. The function describing the light emitted by the source will have a different shape depending on the specific kind of light source, but it will always have a frequency that is an integer multiple of the frequency of the electrical network.
In this very bad graph, our light source is represented by the blue sine, each frame is 1/30s, approximated to 33ms, and the shutter speed is set to 1/50s, or 20ms. In practice we are sampling light at the beginning of each frame (the yellow areas), but this sampling period is not in sync with the light source. Therefore each sampling period begins at a different point of the sinewave. So, why don't we get a flicker? Because we are exposing for a full period of the sine, and the emitted light will be the same.
Now, what happens if I change the shutter speed? Here it's set to 1/100s, or 10ms. I'm not capturing a full period of the sine, but in practice I still don't get flicker in my video.
How to fix it in post
Generally speaking, people don't become interested in flicker before they accidentally shoot footage with flicker in it, which is exactly what happened to me, as seen in the first example. There are both free solutions, in particular you can find some open source Matlab scripts, and paid solutions. The bad news is that every solution is going to be extremely slow, the good news is that these days they work quite well. Both Flicker Free and Neat Video 5 perform the job, and both are GPU accelerated. Also, they both cost roughly the same. In some cases the global flicker is so bad that it remains visible on flat uniform surfaces. In those cases the only solution I know of is masking it out.