Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode H265 to hvc1 codec

Tags:

ffmpeg

Here is the info of my source file: enter image description here

I want to keep audio quality and just encode the video track so I use this command:

ffmpeg -i INPUT -c:a copy -c:v libx265 video-h265.mp4

This is the result: enter image description here

But the codec of the video track is hev1 . I want it's hvc1

like image 419
Slim_user71169 Avatar asked Aug 22 '15 03:08

Slim_user71169


2 Answers

Using the latest ffmpeg (N-87630-ge9f9175-tessus or building from HEAD) you can encode to the MP4 version that macOS High Sierra Quicktime requires by using using -tag:v hvc1.

If you have a hev1-based mp4 and you need the container to be hvc1 and you do not want to re-encode it:

ffmpeg -i input-hev1.mp4 -c:v copy -tag:v hvc1 -c:a copy output-hvc1.mp4

Use ffprobe to confirm the change:

From:

~~~~
Stream #0:0(eng): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 720x404, 164 kb/s, 29.97 fps,
~~~~

To:

~~~~
Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, progressive), 720x404, 164 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
~~~~

If you have an older avc1 based mp4, you will need to re-encode it.

ffprobe example (avc1):

Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 960x540 [SAR 1:1 DAR 16:9], 2778 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)

Encoding Example:

ffmpeg 
    -i input.mp4 \
    -c:v libx265 \
    -preset slow \
    -vf scale="720:trunc(ow/a/2)*2" \
    -crf 28 \
    -tag:v hvc1 \
    -c:a aac -b:a 44100 \
    output-hvc1.mp4

The key is the -tag:v hvc1, without that you will end up with an hev1-based container that Quicktime 10.4+ (High Sierra) will not open.

like image 172
SushiHangover Avatar answered Oct 05 '22 01:10

SushiHangover


'hev1'/'hvc1' are code points used to signal different packaging of the stream in the container mp4 file. There is no change in the coding itself. It is possible to round trip between the two modes. Try with mp4box :

mp4box -raw 1 file.mp4 

This will extract the stream into a raw HEVC file.

mp4box -add file_track1.hvc output.mp4

This will reimport the stream using hvc1 if it can.

like image 36
cconcolato Avatar answered Oct 05 '22 00:10

cconcolato