Transcoding is the process of converting an audio or video file from one encoding format to another in order to increase the number of compatible target devices a media file can be played on.
Encoding and transcoding are sometimes used interchangeably, but the two processes, although closely related, are indeed different.
Encoding is the process of compressing video and audio files to be compatible with a single target device. Transcoding, on the other hand, allows for already encoded data to be converted to another encoding format. This process is particularly useful when users use multiple target devices, such as different mobile phones and web browsers, that do not all support the same native formats or have limited storage capacity.
Encoding is a naturally lossy process, meaning that it causes a certain amount of data to be discarded and ultimately decreases audio and video quality. Encoding can use lossless compression, but it results in decreased compression rates and increased media file sizes.
With that in mind, there are three types of transcoding:
There is no such thing as lossy-to-lossless transcoding. Once data and quality have been lost during the encoding or transcoding process they cannot be regained.
Transcoding and encoding should not be confused with transmuxing which only converts the container format such as MP4 and FLV (Flash). On the other hand, video and audio files are compressed by codecs such as VP6 and H.264. However, similar to transmuxing, transcoding can be done using FFmpeg, a popular open source software designed to handle all video and audio formats. Converting any media to a standard H.264 mp4 can be done with a simple command:
ffmpeg -i "sourceVid.mov" "transcodedVid.mp4"
The above command will take sourceVid.mov, which has already been compressed and encoded, decode it, and reformat it into an MP4 file using the H.264 codec. The resulting file will be named transcodedVid.mp4.
You can also setup your own stream and offer different resolutions in real time using FFmpeg. Setting up a stream requires a more complete understanding of the software, but here is a sample command:
ffmpeg -i rtmp://server.ip/app/1080 -vcodec libx264 -preset veryfast -x264opts nal-hrd=cbr:force-cfr=1:keyint=60 -b:v 3000k -maxrate 3000k -bufsize 3000k -s 1280�720 -sws_flags spline -r 30 -acodec copy -f flv rtmp://server.ip/app/720
The above command takes an RTMP stream and encodes it using x264, a H.264 encoder. The additional options included in the command set the bitrate, buffer, framerate, and resolution of your output, which will be in an FLV (Flash) format.
Transcoding is a powerful process that is leveraged by major streaming organizations such as Twitch, which actually uses both FFmpeg and its own TwitchTranscoder to stream video and audio on its platform.
The world’s largest provider of user-generated videos, YouTube, receives over 300 hours of uploads every minute—and it uses transcoding to make those videos available in 5+ different qualities and 5+ different formats. This means the original uploaded content can be transcoded into over 20 versions. YouTube kicks off the encoding and transcoding process as soon as the original upload is complete, which is why new videos are often only available in low-resolution until the higher-res videos are transcoded.
StackPath’s edge compute products do not offer transcoding out of the box. However, users can install software such as FFmpeg on our virtual machines and containers to transcode streams and video/audio. This lets you transcode at the edge and leverage our content delivery network to deliver your transcoded media all around the world in near real time.