Tutorial: Convert Video to HEVC/H.265 and AVC/H.264 in C++

The two most commonly used video compressions are AVC (H.264) and HEVC (H.265). The majority of HD broadcasting, video sharing, mobile streaming, and digital surveillance use either an H.264 or H.265 video compressor. We all remember saving videos to our PCs and how much disk space they would take up as well as how long they would take to upload for sharing. Converting those videos with the LEADTOOLS H.264/AVC compressor will decrease the file size by roughly 30% and converting with the LEADTOOLS H.265/HEVC compressor drops the file size by nearly 60%. You may be thinking, “Well, it’s been saved at a lower bit rate, so the quality must have dropped“. That is not the case though. These compressors will maintain the same visual quality as the original, so there is no need to worry. With everything being recorded at much higher resolutions – 2k and 4k – these days, the H.265 compressor is a better solution than H.264. Many of the online streaming sites have encoded their videos with H.265/HEVC compressors, which helps to greatly reduce lagging and dreaded “buffering” message.

The below code shows how to create an HEVC compression solution in C++. If you want a complete step-by-step tutorial, check out our Convert Video to HEVC/H.265 and AVC/H.264.

HRESULT ConvertFile(IltmmConvert* pConvert, LPCWSTR pszVideoCompressorName, LPCWSTR pszAudioCompressorName) 
   //Set the target format to AVI 
   //Set the Video Compressor 
   IltmmCompressors* pCompressors; 
   SelectCompressor(pCompressors, pszVideoCompressorName); 
   //Set the Audio Compressor 
   SelectCompressor(pCompressors, pszAudioCompressorName); 
   //Run the conversion 
   HRESULT hr = pConvert->StartConvert(); 
   return hr; 

//Method to select the desired compressor based on the name 
void SelectCompressor(IltmmCompressors* pCompressors, LPCWSTR pszCompressorName) 
   long index; 
   BSTR bstrCompressorName = SysAllocString(pszCompressorName); 
   pCompressors->Find(bstrCompressorName, &index); 

Try it out!

To test this for yourself, make sure to get the latest LEADTOOLS Multimedia SDK evaluation for free from our site, if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.


Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

Stay tuned because, as promised in our previous post, “Split Multi-page Image Files”, we’ll be featuring a lot more tutorials that programmers can use to develop applications that directly impact data capture, recognition, exchange, and other pressing business needs.


Developer Advocate

    Find more about me on:
  • linkedin
  • twitter
  • youtube
This entry was posted in Multimedia Imaging, Video Tutorials and tagged , , . Bookmark the permalink.

Leave a Reply

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