May 1, 2016

Fixing PAL speedup and how film and video work

Filed under: Technical — Tags: , , , , — James Bunton @ 12:00 am

I have a large collection of DVDs and I live in Australia. Because of history this means most of them are in ‘PAL’ format. This means they tend to be about 4% faster than they should be, resulting shorter playing times and higher pitched voices and music.

I’m a bit of a purist. This bothers me enough that I must fix it! What follows is a somewhat lengthy explanation of how film/video works, followed by instructions on how to use my fix-pal-speedup script.

How moving pictures are stored and displayed on a screen

The first technology able to do this was film. Simply take 24 photos every second and store them on a reel. To play it back you shine a line through the reel to project the image onto a screen. This means you have 24 frames per second. This tricks your brain into thinking there is actual movement. The resolution is usually very high but is dependent on the optics of the film camera and the chemical process used in the film medium.

Most movies throughout history have been shot on film. Copies are made and distributed on reels to cinemas for playback. Because film is a physical medium it cannot transmitted into your home like with television.

A television camera is fundamentally different to a film camera. Instead of chemically recording an image it converts light into an electrical signal. This signal can be transmitted using radio waves. The frame rate of TV/Video depends on the country of origin, usually based on the local electricity supply. Australia has 240V/50Hz, so we have TV at 25fps (PAL 50 fields per second). In the USA they have 110V/60Hz and they have 30fps (NTSC 60 fields per second).

Technically PAL and NTSC refer to the colour standard, and NTSC is not exactly 60fps. I’m going to ignore these facts because they do not matter for this discussion. However when working with video you must take it into account or you’ll have audio/video sync issues!

Conversions between formats

Prior to the invention of the video tape the only way to record TV was to store it on film. There was this crazy sounding process called Kinescope where a film camera would be placed in front of a TV screen. Later you could project it onto a screen and point a TV camera at it for rebroadcast. Believe it or not this is how big networks like NBC and CBS would take record live TV shows from New York in eastern USA and delay them a few hours for rebroadcast at the right time in Los Angeles in western USA.

This process is obviously going to be lossy because of the technology involved. The invention of the video tape allowed the electrical video signal to be stored on tape directly, making everything much higher quality and easier!

However it turns out it’s also fundamentally difficult to convert between film and TV because they have different frame rates. Somehow you must take the 24 frames per second of film and stretch to PAL 25fps or NTSC 30fps. Film to NTSC conversions use an odd interpolation based approach called telecine. There are plenty of high quality algorithms for reversing this to recover the original 24fps film. Film to PAL conversions are much simpler, they simply play back the film 4% faster.

TV shows can be really messed up

Live TV must always be shot with a video camera because you cannot directly broadcast a film reel.

However many TV series are shot on film and converted to video for editing. Annoyingly this means that a TV may have original source material shot at 24fps (film), 25fps (PAL TV) or 30fps (NTSC TV). Sometimes it may even be a combination, for example lots of 90s scifi, like Star Trek, was shot on film with the special effects done directly on video. So within a single scene you may have a of 24fps film which has been telecined and 30fps video generated from special effects.

Just leave everything in its original format, Bluray is great

These days most LCD TV displays can play back content in any of the common frame rates or resolutions. However the various standards for VHS tapes and DVDs require that content be in a single frame rate. Typically everything is converted to the native frame rate for the region that content is being sold.

So if you’re living in Australia and a local DVD of a TV series originally produced in the US then you’ll be getting a converted video. Similarly the other way around. Anybody buying a film sold anywhere in the world will get a converted frame rate.

Bluray mostly fixes all this by allowing content to be distributed in its native frame rate. However annoyingly media companies don’t make blurays unless they have high definition (720p or 1080p) content. This means it can be very difficult to source clean copies of a TV series.

Also Bluray still doesn’t help for shows that have a master with ‘mixed’ frame rates. Remember the 90s scifis I mentioned earlier with both film and video in the same scenes? The only solution there is to redo all the editing and special effects from the original film, which is very expensive! This has actually been done for the Bluray release of Star Trek The Next Generation.

Film/Video standards around the world

Content Type Country of origin Format
Movie / Film Anywhere in the world 24fps, very high resolution, progressive (not interlaced)
TV PAL regions (UK, AU, etc) 25fps, 720×576 (576i), interlaced
TV NTSC regions (US) 30fps, 720×480 (480i), interlaced

How do I fix the PAL speedup then?

As I mentioned earlier, when converting content from film (24fps) and to PAL (25fps) it is usually sped up by 4%. Converting from a US TV show usually does the same thing because it goes from NTSC (30fps) and is detelecined to 24fps, then sped up to 4%. Happily this means we can usually use the same fix for PAL DVDs of both movies and US TV series.

I have a fix-pal-speedup script which does all the hard work.

Requirements:

  • Bash
  • ffmpeg with libfdk-aac support, you could easily modify the script to use a lower quality codec
  • mkvmerge
  • Input file supported by ffmpeg, must not be variable frame rate or mkvmerge will lose sync when remuxing!

How does it work? Firstly you need some simple maths, this 4% figure I keep using comes from 24 ÷ 25 = 0.96. To undo the speedup we need to slow down both the audio and video by that much.

Fortunately we don’t need to re-encode video stream, we can just tell mkvmerge to create a new file with 24fps in the header instead of 25fps. Each frame will stay on the screen just a little longer. The audio will not be so easy.

The standard for audio is a sample rate of 48000Hz. We need to slow it down by 4%. We can use the same trick as with the video stream by reading only 0.96 * 48000 samples per second, that’s 46080Hz. Fortunately ffmpeg can do this by telling it to to ignore the sample rate from the file header, we specify the input filter asetrate=46080. However we can’t save this non-standard sample rate to a file, the vast majority of players would reject it. So we now must use the ffmpeg resampling output filter to interpolate samples and bring the rate back up to 48000Hz.

Finally we recombine the audio and video into a single file using mkvmerge. The end!

Leave a Reply

Your email address will not be published. Required fields are marked *