What is Transcoding?
Understanding all about transcoding with Plex is a important concept because it is the fundamental reason why media files from Plex can be streamed to so many different devices.The process of transcoding can be both good and bad for a Plex server, but it is a necessary process when managing a media server.
The idea of transcoding is something that is asked about a lot for those that are new to Plex. Why does a file need to be transcoded? When does a file need to be transcoded? How is a file transcoded?
These questions will be answer in this article as I take a deeper dive into transcoding with Plex.
Table of contents
- What is transcoding?
- Start with an explanation of transcoding, and what causes Plex to transcode a file.
- Why does Plex need to transcode?
- An explanation on why Plex would transcode a media file before streaming it to a device.
- How does Plex transcode?
- Explains how Plex transcodes a media file before the media is streamed to the client.
- How to get Plex to not transcode?
- Provides a few options to avoid Plex from transcoding a media file.
What is transcoding?
Before getting into the specifics of transcoding, let me first talk about what exactly is transcoding. It really isn't a complex concept to think about, but it does make it possible for media to be streamed to all devices.
Transcoding is the process of converting media from one format to another so it can be played by a device. In the case of Plex, it will look at the source media file and determine if can be played on the client requesting the file. If it can't be played, Plex will determine what will need to be converted in order for the media file to play on the client.
Why would Plex need to convert a media file? The answer is that there are many different devices that can play media, and each device can be different in both hardware and software.
An example of a powerful media playing device is a desktop. These machines usually have a powerful processor, a graphics card for hardware acceleration, and the ability to play almost every media type available. In addition, they may also have high-resolution displays connected for viewing UHD content.
A mobile device - smartphone or tablet may also have good processors, but lower-powered than desktops. Their screens are smaller, so they may not need to stream high-bitrate movies.
The last example would be an older media device - such as a Roku 3 model. When the Roku 3 came out, it was a great device, but it has been showing it's age recently. The processor is old so it can't stream UHD movies and it is limited to what type of media encodings it can decode.
If a Plex server needs to stream a single media file to all three of the above device types, it may need to transcode (convert) a movie so it can be compatible with all three types of devices.
Why does Plex need to transcode?
I started answer this question in the previous section. Plex would need to transcode a media file so the file can be played on a device.
There are three main criteria Plex will use to determine if a file will need to be transcoded. If the device does not meet the following criteria, Plex will transcode the file:
- 1. Encoded with a compatible codec.
- The device needs to be able to decode the media file associated with the codec used to encode the file. Older devices can't handle codecs such x265 (HEVC/H.265), so for HEVC files, Plex would need to transcode to a compatible codec - such as x264. Codecs apply to both video and audio streams in a file.
- 2. Encoded with a compatible bitrate.
- Some devices are limited to the bitrate that they decode. For example, a Roku 3 is limited to a bitrate of 20 Mbps, so anything higher will cause Plex to transcode the video to a lower bitrate.
- 3. Contains a compatible resolution.
- Trying to play a UHD 4K video on a HD 1080p device is not going to work. Plex would transcode that 4K video to 1080p so it can play on the device.
The above three criteria are controlled by two things: the client profile in Plex for the device, and the quality settings specified in the Plex app on the device. These two things specify the maximum streaming quality for the device, and if the media file exceeds any of the quality settings, Plex will transcode the file.
There is an option, however, that can set to disable transcoding in Plex within the server settings. This option is not recommended to be turned on, though, because it will cause problems with playing the file on a device that needed the file to be transcoded.
How does Plex transcode?
I didn't develop Plex Media Server, so I can't get into specifics on how Plex transcodes a media file. I can talk about what I have seen, and know, about how the transcode process works.
When a client requests to play a file, Plex knows about the file information, such as container, video encoding, audio encodings, bitrate and resolution. You can view the details from the Plex server. When a library is scanned, the file details are determined and stored within the Plex database.
Plex also knows the capabilities of the clients, either through the client profiles, or through what the client sends to Plex regarding the quality settings.
Knowing both what the client can play in terms of quality, and what the media file details are, Plex can determine if the file can be direct played, direct streamed, it needs to be transcoded.
Also stored on the server are various decoders and a few encoders. These are downloaded as needed and are used by Plex to transcode the file. These files are stored on the server in the Plex data directory in the following location:
[PLEX data directory]/Codecs
Plex will use the decoder files to decode the video and audio streams of the media file, and then use the encoders to transcode and encode the stream into a compatible format for the device.
The transcoding process is not persistent, so a media file is decoded and encoded in chunks, and then sent to the client device. The transcoding process stores the necessary files in a directory on the server, by default.
The default transcoding temporary directory is located here:
[PLEX data directory]/Cache/Transcode/Sessions
You can change the temporary directory used by the transcoder in the Plex server settings.
The speed of how quickly Plex can transcode a file is determined by whether Plex uses the CPU or GPU to transcode the file. If Plex uses the CPU, then the CPU usage could rise to 100%, which could slow down the server, and prevent Plex from being able to transcode the file fast enough to be streamed.
The other option is to use the GPU to transcode the file. By using the graphics card, you will be able to transcode multiple files at one time, while also reducing the CPU usage. If you have a supported graphics card in your server, then you should look at using it for transcoding.
Regardless of whether the CPU or GPU is used to transcode, Plex will continue to generate transcoded chunks of the file and send them to the client. Once the file has completed transcoding or the user has stopped streaming, the transcoded chunks are deleted.
How to get Plex to not transcode?
As mentioned above, there are a few criteria Plex uses to determine if a file will need to be transcoded. If any of the criteria is not met, then Plex could choose to transcode the file.
But how can you make Plex not transcode? There are a few options you can look at to help Plex avoid transcoding:
- Provide multiple versions of the media file.
- The best way is to optimize your media files so each one has multiple versions available to stream. Plex will choose the version that closely matches what the client can stream, and then send that file to the client. Having Plex create the optimized versions of each media file makes it easy to provide multiple versions.
- Change the client's quality settings.
- Each client has two quality settings that can be changed: home/local network and remote streaming. For clients that are streaming from the Internet, the remote streaming quality is what will be used, which defaults to 2 Mbps, 720p, which is very low for most media files. If possible, and the upload bandwidth is available, changing the quality settings to something higher could allow Plex to use the original source file without transcoding.
- Disable transcoding in Plex.
- This option is not one I recommend enabling on your Plex server, but is is there, if needed. If you disable transcoding in Plex from the server, then files won't transcode, but that also means the clients may not be able to stream the media.
Out of the options mentioned above, creating optimized versions of your media files, or changing the client's streaming quality settings would be the best ways to avoid transcoding.
Transcoding in Plex makes it possible to stream media to almost any type of client device available. The devices can have a large range of capabilities, that one source media file cannot be streamed to all devices.
With transcoding, Plex manages the streaming complexity by creating a version of the media file that can be streamed to a client device.
Of course, there is the trade-off of more resources, such as CPU, being consumed on the server. To avoid overloading the server, the GPU can be used, or offering multiple versions of the media can help.
Regardless, transcoding is a vital option for Plex to use to stream media when needed.