Encode H265 to hvc1 codec
Solution 1
'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.
Solution 2
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.
Solution 3
Add -tag:v hvc1
as @SushiHangover's answer and -bsf:v hevc_mp4toannexb
to ffmpeg
command(version 3.4 and later). That will create a QuickTime-compatible mov file.
ffmpeg -i input-hev1.mp4 -c:v copy -tag:v hvc1 -bsf:v hevc_mp4toannexb -c:a copy output-hvc1.mov
Slim_user71169
Love programing and love learning from others about Android, J2ME, J2EE, architecture and database,...
Updated on September 17, 2021Comments
-
Slim_user71169 almost 3 years
Here is the info of my source file:
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
But the codec of the video track is hev1 . I want it's hvc1
-
llogan almost 9 yearsWhy do you provide images of text instead of simply copying and pasting it?
-
Slim_user71169 almost 9 yearswhat's the difference?
-
llogan almost 9 yearsText is searchable, can be copied and pasted (often useful for answers), doesn't rely on what I'm assuming is a third-party image host, takes up less space, should be easier and less time consuming for you to do, and it is easier to show the complete console output which you should always provide.
-
-
Slim_user71169 almost 9 yearsYes, I did it. I forget to answer my question by myself, too
-
Whome almost 7 years@cconcolato Is this possible directly in a ffmpeg encoding command without mp4box post-encoding step?
-
Florian over 6 yearsYou can use
brew install ffmpeg --with-x265 --HEAD
to install it using Homebrew. -
SushiHangover over 6 years@Florian I normally do that, but it is broken, there was a pull request to fix it but it was rejected....
-
Florian over 6 yearsThat's strange! I used the command just before I posted it here.
-
Jensie almost 6 yearsDid something change? I did this on High Sierra 10.13.6 and QT 10.4 it still won't play h265. Checked with ffprobe that it indeed was hvc1. My source was an AVI though. Plays fine on VLC. Strange....
-
SushiHangover almost 6 years@Jensie No, nothing changed... via ffprobe does it read
...Video: hevc (Main) (hvc1 .....
? -
AwokeKnowing almost 4 yearsThis really helped me.
-
John almost 4 yearsis that all supposed to be on one line?
-
SushiHangover almost 4 years@AwokeKnowing Glad it did 🍣