How do I convert videos to H.265/HEVC format in Ubuntu?

25,588

Solution 1

The best solution so far on my system has been:

  1. For Trusty Tahr 14.04 LTS: use an up to date FFmpeg and the most recent x265, which necessitates some compiling and subsequent packaging
  2. For Xenial Xerus 16.04 LTS: simply run:

    sudo apt-get install ffmpeg  libavcodec-extra
    

With either of the previous methods then use the following:

ffmpeg -i input \
   -c:v libx265 -preset slow -x265-params crf=22 \
   -c:a libmp3lame -b:a 128k \
   output.mp4

Note that this creates an mp3 audio stream as well as an h.265 video stream. To create an aac stream the line -c:a libmp3lame -b:a 128k could be replaced with the following:

-c:a aac -strict experimental -b:a 128k

The -strict experimental option will not be required if your copy of FFmpeg was released after December 2015 when development of the native aac encoder matured. Bear in mind that this option will still be required for the repository FFmpeg for Xenial Xerus 16.04 LTS.

References:

Solution 2

Method 01

You can install Internet friendly media encoder:

enter image description here

Run these commands in your Terminal:

sudo add-apt-repository -y ppa:upubuntu-com/multimedia  
sudo apt-get update  
sudo apt-get install ifme

Now you can open the program ifme from Dash.

source

Method 02

Once you compiled the program following the instructions in here or here, first you have to encode the video into YUV format:

avconv -i MyVideo.mp4 MyVideo.yuv

Then you can convert YUV video into x265 format:

./x265 --input-res 640x360 --fps 24000/100 MyVideo.yuv -o MyVideo.h265

Solution 3

This script worked for me:

ffmpeg -i input_file.mpg -pix_fmt yuv420p -f yuv4mpegpipe - |\
     x265-10bit --profile main10 --preset slower --crf 20 --input - --y4m -o output_file.mpg
Share:
25,588

Related videos on Youtube

andrew.46
Author by

andrew.46

The Tao is close, but you look far away. Life is simple yet you look for problems...

Updated on September 18, 2022

Comments

  • andrew.46
    andrew.46 over 1 year

    I see that H.265/HEVC encoding is gathering momentum but under some versions of Ubuntu it is not all that easy to produce H.265 video streams.

    How should I go about using x265, in a manner that integrates with Ubuntu (especially the LTS releases Trusty and Xenial), to produce HEVC video files under Ubuntu?

    References:

    1. x265 HEVC Encoder: The commandline encoder
    2. x265: Videolan site
  • Csabi Vidó
    Csabi Vidó almost 10 years
    Or if you don't like big uncompressed files pipe the output of avconv against x265. (it looks like this for ffmpeg+x264: ffmpeg -i "INPUT" -pix_fmt yuv420p -f yuv4mpegpipe - | x264 --demuxer y4m - --profile High10 --preset slower --crf 20 --video-filter -o "OUTPUT" -)
  • Naveen
    Naveen almost 10 years
    @LiveWireBT: That's cleaver!
  • SuperSluether
    SuperSluether over 8 years
    That's pretty much what I did, except I used the experimental AAC encoder built-in to FFMpeg.
  • andrew.46
    andrew.46 over 8 years
    Interestingly enough the experimental aac encoder is no longer 'experimental' in git FFmpeg from December 2015.
  • andrew.46
    andrew.46 over 8 years
    Added in the option of using the FFmpeg native aac encoder...