Pages

Wednesday, April 25, 2012

Video encoding and file conversion tips

Most digital signage users will incorporate video material at some point in their playlists and schedules.  In many cases the bulk of the material will be provided by the client or re-purposed from another source... and that's when things can get messy.

Sometimes, you'll get a video that plays fine on your big old desktop PC so you figure it's fine and you upload it to your players.  Then you find out the clip causes all sorts of problems after looping for hours on your micro fanless PCs and you don't know what's going on.

This is where a little knowledge can go a long way...

So what's the best codec or file format?

I am often asked, "what's the best video format/codec that I should use for my digital signage" and my answer is always... "depends!"

There is no single answer because each situation is different.  You have a wide range of PC and display screen configurations out there so it's impossible to guarantee perfect playback all of the time.

Having said this, there are a few rules you can follow to ensure the best possible outcome and high reliability:

  • MPEG-2 is a good place to start.  It's a decent compromise of quality and performance. This video standard offers decent image quality but WMV9 and H.264 encoded files often look better. Not the most efficient in terms of CPU usage but not the worst either.
  • WMV9 is a good video encoding choice for Windows based PCs.  However the resulting WMV file can be quite CPU intensive at higher resolutions.
  • H.264 will provide really good image quality at a price.  Higher compression rates mean more CPU load.  The faster the PC, the better the results with this one.
  • In some cases, MPEG-1 can still be a viable option so you should test it if nothing else works for you.
Learning about video formats and codecs isn't for the faint of heart. In fact, it sometimes feels a bit like alchemy... part magic and part science. Now you may ask yourself, "Shouldn't my digital signage software take care of all this?".  Well the short answer is... No!  If you plan to display video on your screens, you should have a basic understanding of what's going on behind the scenes.

Digital signage is made up of many components:  PC hardware, TV screens, software, content, etc... And each component can affect the performance or stability of the entire system. If you feed the system bad content, you will get a bad outcome.  It's really that simple.

So let's dive in and learn something...

Lesson #1.  What is a codec?

Raw or uncompressed video files tend to be very big.  These are the files that you get out of a professional quality video camera.  This is the raw footage that is used for editing.  These files are not meant for playback on your PCs.  They are way too large and would require too much storage space and computing power to be useful.  This is where codecs come into play.

A codec is a program designed to compress or decompress a video file.  Videos are encoded to reduce their size and make them playable on a wide range of PCs and consumer devices.  So it's important to know what codec was used when someone hands you a video file.  That's one way you can determine if the content is suitable for your application.  If not, you can go back and specify the codec of your choice or you can ask for the original file and convert the clip yourself.

There are basically two types of codecs.  Those who perform lossy compression (meaning some image and audio data is removed to achieve smaller file sizes) and those who perform lossless compression (very little data is lost).  Lossy codecs are the ones you will encounter at the playback end.  Most videos meant for playback are encoded with lossy codecs.  Lossless codecs are used when archiving files or for high end editing.  They are never used for playback.

Lesson #2. What should I look for in a codec?

A good codec should provide a decent amount of compression while delivering good image quality.  And here's the rub, there are always compromises.  Codec A creates really small files but image quality sucks.  Codec B creates huge files however image quality is amazing. So your answer lies in the middle.  You want a codec that will give you the best of both.  Good compression and good playback quality.

Oh, and one more thing...  You want a codec that manages memory well.  There are codecs that perform amazing feats of compression and deliver high image quality that will deplete a PC's memory in hours.  They consume memory each time the clip is played and never fully release it so eventually the PC runs out of resources and crashes.  This is one of the most common issues you see related to video playback.  

Here are some common codecs you will encounter:
  • DivX - There are 2 flavors of DivX.  One follows the MPEG-4 standard and the other follows the H.264 standard.  This is a proprietary codec.
  • XviD - This is a video codec library that follows the MPEG-4 standard.  It is a free codec.
  • WMV - Windows Media Video is a video compression format that supports several Microsoft codecs. The most common codec you will see used with this format is called WMV9.
  • MPEG - Represents both a series of video formats and standards.  The most common are MPEG-1, -2 and -4.
  • H.264 - Also known as: MPEG-4 or AVC, is probably the most common high definition video codec available.
  • Sorenson Spark - This is a codec used to encode videos delivered in Flash Video format (FLV).  You use the Sorenson Squeeze encoder to generate these types of files.  Note that Squeeze can also transcode to other codecs and formats as well.  

NOTE: These are the most common codecs you will see. I didn't list them all so if you find something else and you're not sure if it applies to your situation... Google it!

Lesson #3. What's a container format.

A container is a file format that can host different types of data (compressed audio and video for example).

Here are some common container formats:

  • AVI - These files can contain audio and video content that are encoded with different codecs.  AVI is not a codec.  It is a container format that is mostly used on PCs.
  • QuickTime (MOV) - The QuickTime format originated on the MAC but it is popular with PCs as well.  You will often see MOV files encoded with the H.264 codec but other codecs can be used.
  • Flash Video (SWF - FLV - F4V) - This is another container format based on Adobe Flash.  This format is mostly used to deliver video on the web.

Don't confuse AVI, QuickTime and Flash Video with codecs because they are not the same thing.  They are containers.


Lesson #4. Bit rates and frame rates, Oh My!!!

To make things interesting, we have a couple more variables that affect playback performance.

  • Bit rate: In digital video, bit rate represents the amount of information, or detail, that is stored per unit of time of a recording. The bitrate depends on several factors (which we won't discuss) but you can read more about it here.

    Bit rates can be expressed in kilobits per second or megabits per second.

    Here are some examples of recommended bit rates for a given video resolution and compression level:
    • 9.8 Mbit/s max: DVD (using MPEG2 compression)
    • 8 to 15 Mbit/s typ: HDTV quality (with bit-rate reduction from MPEG-4 AVC compression)
    • 19 Mbit/s approximate: HDV 720p (using MPEG2 compression)
    • 24 Mbit/s max: AVCHD (using MPEG4 AVC compression)
    • 25 Mbit/s approximate: HDV 1080i (using MPEG2 compression)
    • 29.4 Mbit/s max: HD DVD
    • 40 Mbit/s max: Blu-ray Disc (using MPEG2, AVC or VC-1 compression)

  • Frame rate: Represents the amount of frames that are shown per second.  Without getting too technical, it's recommended to keep your frame rate below 30 frames per second when preparing files for PC playback.  You can go lower that 30FPS (like 24 or 25 fps) but you may see some blurring if your clip features quick motion shots and panning.

    Anything above 30 FPS is a waste of CPU cycles and you won't notice the difference on screen.
    The higher the frame rate, the more the PC's CPU must work.


Lesson #5. What's "transcoding"?

Transcoding refers to the direct data conversion from one encoding method to another.  For example,  whenever you convert a file from a DVD VOB format to WMV you are transcoding the video file.

Here are a couple of things to remember.  Transcoding a compressed video to another compressed format will result in loss of quality and often increase the file size.  It's better to transcode from a lossless (or uncompressed) file to a lossy format.  That way you won't lose too much information and the file will be smaller.

Lesson #6. Why is it a bad idea to use a VOB video file in my digital signage software?

VOB is the standard container format for DVD video.  You will find these files on video DVDs (usually on commercial DVDs). A VOB file can contain much more than just audio and video.  The file can contain subtitles, DVD menus and navigation content. VOB files found on commercial DVDs are usually encrypted and it is illegal to decrypt them.

Unencrypted VOB files can be played by renaming their extension to ".mpg" because these files are a special version of MPEG-2.  However the results may not be great because the files are not optimized for PC playback.  If you are stuck and need to play the content of an unencrypted VOB file, I would first try transcoding it to a more "standard" format like WMV or H.264.

Last but not least. What's the best video resolution for digital signage?

Full HD or 1080p has become a popular video standard for good reason.  A big screen displaying full 1080p video is a thing to behold.  But in terms of digital signage one can ask if the juice is really worth the squeeze...

Consider this:
  • 1080p video really comes into play when you are using large display screens.  Any screen size above 32" is a good candidate for 1080p because the image is so much larger.
  • The 720p HD format is great for screens below 32" because smaller images tend to look sharper. It becomes much more difficult to see the difference between 720p and 1080p below this screen size.
Now, it's pretty difficult to tell which screen resolution is being used on a  42" screen hanging 10' from the floor from any given distance.  So you must ask yourself it's it really worth using 1080p given that video files become exponentially larger and require more PC resources than lower resolution content.

In my opinion, you need to look at the big picture.  What PC hardware are you using or planning to use?  If you use low-cost Atom based PCs with limited resources, why not give yourself an edge and feed it 720p content instead of 1080p?

This isn't to say you can't play 1080p on an Atom box but you put all the chances on your side if you stick with a lower resolution and you get more benefits, such as: 
  • Lower storage requirements.
  • Quicker file downloads/reduced bandwidth usage.
  • Faster transcoding.
  • Opens up the possibility of using WiFi instead of hard wired connections.
  • Etc...

In conclusion...

There are many factors that affect video playback performance and PC stability.  You need to figure out what is the target resolution for your screens and then work beck from that.  Look at your hardware. Test using various file formats for at least 48 hours before settling on a particular file format and codec pairing that works for you.

You need to test... test... and test some more...

Here are a few links to helpful resources:

No comments:

Post a Comment