Comparing H.265 (HEVC) and H265 video file size
janstechtalk.blogspot.com
janstechtalk.blogspot.com
Also H.264 and H.265 are just formats; there are many encoders of varying quality which can generate such files and each encoder has tons of settings. I don't know which encoder macOS uses but ffmpeg includes state-of-the-art H.264 encoder (x264). Simply reencoding video from H.264 to H.264 using ffmpeg can give you better quality/size ratio than the original file.
> H.264 codec (or MPEG-4 Part 10), once upon a time know in the scene as DIVX.
No, DivX refers to MPEG-4 Part 2 which is a completely different codec.
Poster is referring to the DivX Plus HD codec [1].
MPEG-4 Part 10/H.264/AVC is a different format.
It's actually even more complicated than that. Each encoder has multiple settings on how much CPU to spend on the compression. Live screen recording (which this was) usually has the setting set to spend little CPU and get little compression. So like you said you don't need to change which format you use to get better compression, but you also often don't even need to change what encoder you use, you can just change the compression setting to use extra CPU (which might not be possible on a live recording).
That is incorrect and bothered me enough that I scoured the web trying to find old scene release standards. Fascinatingly, there's a whole Wikipedia article on those[1] and it's still possible to find the original .nfos in strange corners of the internet[2].
But long story short, a DivX release was standardized to DivX 3.11, which was actually a reverse-engineered Microsoft codec and not actually MPEG-4 compatible[3]. But later DivX versions implemented MPEG-4 Part 2[4] -- that is still a completely different thing than MPEG-4 Part 10[5] though, which describes H.264 (but calls it AVC).
[1]: https://en.wikipedia.org/wiki/Standard_(warez) [2]: http://lunamoth.biz/pe.kr/cgi-bin/gm/archives/tdx2k2.nfo [3]: https://en.wikipedia.org/wiki/DivX [4]: https://en.wikipedia.org/wiki/MPEG-4_Part_2 [5]: https://en.wikipedia.org/wiki/Advanced_Video_Coding
I strongly suspect that the difference here is between real-time compression that runs while capturing the screen recording, and less time-constrained offline compression during transcoding.
The original screen capture H.264 files did have a 1 second GOP size. However, the very simplistic ffmpeg commands to make the h.265 & h.264 files that I made used the default GOP settings from ffmpeg. Turns out, the default is 4 seconds. That would easily help get the final file size down.
You mean for a given CRF ("crf" isn't an official term, it's what x264/x265 call their fixed quality mode). "Bitrate" is literally how big the file is.
Filesize is literally how big the file is. Bitrate is how much data can be used over a window of time.
Sure, that's true. Then the only problem is you said "smaller" and not "better looking" above.
Video codecs have lots of options and trade-offs. Its not just quality and file size, but also cpu usage. I suspect the original was encoded in minimize cpu usage while keeping quality constant, and the new one was minimize file size while keeping quality constant and use as much cpu as you want.
Reencoding the same input file as h264 again but using FFmpeg defaults would probably yield similar file size reductions.
This is just a bogus post without knowing what parameters were used to encode the original h264.
I then used that as a source to transcode with x264 crf 23. New filesize 2.0M. ~26%
ffmpeg -i input.mov -c:v libx264 -crf 23 x264.mp4
Next, I used the same 7.5MB source to transcode with x265 crf 28. New filesize 968KB. ~13%
ffmpeg -i input.mov -c:v libx265 -crf 28 x265.mp4
CRF values were taken from [0] which states x265 crf28 should produce same visual quality of x264 crf23, but at half the size. That holds true.
[0]https://trac.ffmpeg.org/wiki/Encode/H.265
Edit: forgot link
So, I don't think the author's post is bogus. They just lose points for not showing their work (not that they did it, but you know).
Edit 2: I have no idea what the author of the post used for encode settings. I picked 2 based on the vendor's claim the 2 settings should look the same at half the bit rate. I easily could have changed the values to lower the bitrate to get from 50% to 94%. I just assumed the reader would be able to make the mental leap
As your comparision found, the majority of the size reduction relative to the original was related to encoding parameters, only 13% was related to codec choice. Of course if you start from the better encoded H.264 file things look better for H.265, but not 94% better.
As a rule of thumb, x265 works better (compared to x264) at lower bitrate / worse quality. You won't be able to achieve "same quality, half size" at higher bitrate easily.
From years of real world experience, h.265 produces much smaller files by being able to use a lower bitrate to achieve the same visual quality has previous h.264. Guess what. H.264 did the same thing to MPEG2. Not really sure why this is so unbelievable.
No one is saying that. Everyone knows H265 is better than H264. Just saying your number is meaningless without either fixing the bitrate or the quality.
The test files that I produced resulted in the h.264/crf23 with a bitrate of 970kbps while the h.264/crf28 result with a bitrate of 800kbps. The h.265 used less bitrate to achieve half the filesize. I have stacked the 2 videos and toggle between the two. There is no visible difference. I have done this experiment. It is up to you to do the same thing to see if you can replicate the results or not. That's science. But it is much easier to just post "no it doesn't" comments on the internet.
All you have is literally one datapoint, 970kbps h264 has "no visible difference" compared with 800kbps h265, and I believe that. But maybe 800kbps h264 also doesn't have visible difference from it. Maybe there is just not much difference to notice from 500 to 1200kbps, for your specific video.
Again, my point is your experiment has too few samples (literally 1 pair). Using that to conclude anything is the exact opposite of "scientific" method. I never say "h265 isn't better than h264" or "your result is wrong"; just your result doesn't prove the former.
If you insist to use just one sample, you could at least use the same bitrate (2-pass if you want to have better rate control) and say "hey, the h265 one is visibly better!", and that would be more convincing.
This experiment was to show that the gains the original post made wasn't solely due to the video being an unchanging desktop. There were enough samples done to show that claim seems to be false, though more data could change that.
Basically, you're misunderstanding the theory tested, and while your complaints would make sense testing a different theory, they don't discount the experimental evidence for the tested theory.
But the question was about using the zip file as a source for streaming, and that will work fine even if you have to spend an extra read to load the directory first.
Regardless, if for some weird reason you really liked the zip compression algorithm (DEFLATE), you would probably just use gzip instead (same compression algorithm, no weird file format with critical metadata at the end). Its also the compression algo used by PNGs.
I could interpret this a couple ways, so let me try to clarify.
If you're talking about the ability to seek around inside the video, it is correct that this will not work well.
If you're talking about seeking to the end of the zip file to read the directory, I don't think that was part of the scenario. My interpretation of the question is that the server has a zip file and has to output a video stream directly from the zip.
If the zip itself is being delivered as a single stream, start to end... I have no idea what kind of scenario this is. There's no zip-streaming protocol out there. Filesystems can give you the end of a zip. HTTP can give you the end of a zip.
> Regardless, if for some weird reason you really liked the zip compression algorithm (DEFLATE), you would probably just use gzip instead (same compression algorithm, no weird file format with critical metadata at the end). Its also the compression algo used by PNGs.
Maybe. You might want windows users to be able to easily extract the video.
But if you're streaming a zip file down the line, can you view the stream as it partially loads, which is possible with certain video formats (esp. if the player can handle missing key frames etc).
I was under the impression that a zip file cannot be partially read and reconstruct partially the contents.
The first distinction is between streaming from the start of a file, without needing any storage space, versus streaming from a random point in the middle of the file. With a zip you can do the former, but you cannot do the latter.
The second distinction is between streaming the zip itself, versus streaming from the zip without needing any storage space. If you stream the zip itself, and don't allow even a single extra read to get the directory, it will be trickier to extract the video on the fly but still probably possible. If you are streaming from the zip then you can read the end then jump to the start and begin streaming, and it will work fine.
If that's a confusing mess, then I guess be more specific. What data does the video player see, and from what protocol?
The end user can buffer the entire video, but that takes too long. So ideally, the player can download the video partially, and start watching while buffering the remaining. (assume the video is in a format that's streamable).
So is it possible to zip the video on the server, and rewrite the http server to serve the zip file directly to the end user, and yet still have the end user be able to partially view the video as a stream, while the zip is still downloading?
> it will be trickier to extract the video on the fly but still probably possible
i think this is what i'm looking for - extract a partial video file from a partially downloaded zip file.
If the user is viewing the video from the start, then there's no problem. There are multiple ways to make this work.
If the user wants to jump into the middle of the video, it won't work.
That's the short answer.
The long answer goes into more detail on how to make it work:
It would be possible to have the http server unzip a megabyte at a time and send it to the client, but you said you want to send the zip to the user so we'll cross out this possibility.
That leaves two ways of doing things.
The easy way is to have the client make an HTTP Range request to get the last 100KB of the zip file, then make a second request to start at the beginning of the zip file. This will let the client act like a completely normal unzipper, and it can start playing immediately.
The hard way is to go into more detail about how a zip file is structured. We don't actually need the directory to start decompressing. A zip file is structured as [file header][file data][file header][file data][file header][file data][directory]. You can just start decompressing the first file in the zip and feeding it into your media decoder. It'll work.
For watching videos from the start, zipping is only be a problem if you put multiple videos into a single zip and use a web server that doesn't support Range requests.
H.265 is obviously going to be a lot better, but compared to doing nothing, even something stupid like RLE compression is going to be helpful.
Edit: You can disagree, but video files do not compress with zip. Feel free to do the experiments on your own time. Zip looks for combinations of letters/sequences. That's not how a video file structured. To make video smaller, smart people created a dedicated type of compressors.
> That's not how a video file structured
You're under the impression that uncompresed raw video does not contain repeated bit patterns??? How do you think it is structured?
Convert to uncompressed YUV420P:
$ ffmpeg -i ed_hd.mp4 elephant_dream_uncompressed.yuv
Compress with zip with default compression (I also tried -9 but it didn't make much difference): $ zip compressed_elephants_dream.zip elephant_dream_uncompressed.yuv
adding: elephant_dream_uncompressed.yuv (deflated 64%)
$ ls -la elephant_dream_uncompressed.yuv compressed_elephants_dream.zip
-rw-r--r-- 1 bawolff bawolff 1961679613 Mar 25 08:54 compressed_elephants_dream.zip
-rw-r--r-- 1 bawolff bawolff 5422809600 Mar 25 08:46 elephant_dream_uncompressed.yuv
1-1961679613/5422809600 = .63826-----
So, 63.8% compression ratio. This is terrible compared to any lossy video codec obviously, but its hardly nothing.
i would expect even better ratio if the source contained mostly solid colours like a screencast
yay, you proved a RAW video can be zipped. you're right, i'm wrong. i have to ask though, why? what in the world is this trying to achieve? this has to be one of the worst ideas for making video smaller and useable.
The only case i could see is in high-end video editing or archiving where you need lossless compression, but even then there are lossless formats that provide better compression ratio (i assume), and more importantly better random access which would probably be important to that use case.
That being said, H265 definitely does improve filesizes.
[0] https://developer.nvidia.com/video-encode-and-decode-gpu-sup... [1] https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardwar...
But I don't think desktops are the problem anyway as opposed to laptops/tablets. Desktop cpus are perfectly capable of decoding h265 in real time without acceleration
I don't think the steam hardware survey is a good sample of the wider computer market though - the majority of people using youtube/netflix/etc on x86 devices are probably using Intel laptop chips with integrated graphics, not $500+ dedicated GPUs.
(Although presumably this is probably becoming less true over time, those low end users are moving more and more to mobile devices and smart TVs/chromecast/console, leaving workstation/gaming systems to be a larger percentage of the market)
On the Apple end of things, h265 hardware decode has been supported since the A9 (iPhone 6S, introduced 2015)
They also list hardware decode support on Macs as of Intel 6th gen CPUs (Skylake, introduced 2015).
The mobile market I have no idea about.
EDIT: I was wrong about AMD - see replies.
Ryzen 4750U on a T14 reporting in:
vainfo: VA-API version: 1.10 (libva 2.10.0)
vainfo: Driver version: Mesa Gallium driver 20.3.4 for AMD RENOIR (DRM 3.40.0, 5.11.4-arch1-1, LLVM 11.1.0)
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc
mpv also reports "Using hardware decoding (vaapi)." when I try to play an HEVC file.Most smartphone has also HEVC decode in the past 4 years.
Basically the adoption hurdle has nothing to do with Hardware. Only the two A in FAANG are supportive of JVET or MPEG standard. Others prefer their "patent free" ( cough ) AV1 codec.
Also, I’m not criticizing the authors English (which is much better than my Dutch), but some of those mistakes were almost poetic:
> Some more Ducking made me aware that using '-tag:v hvc1' in FFmpeg creates files that QuickTime can eat.
Same applies to H.264.
I think the main reason for OP’s observation, the codecs optimized for real time streaming (including the hardware codecs inside GPUs) don’t have enough time (both CPU time, and maximum allowed encoder latency) to achieve what ffmpeg does when asked to re-encode a video clip from hard drive.
Converting video from a lossy format to another lossy format with these settings will significantly degrade the quality. For a desktop recording that could be problematic, still frames could be unreadable.
Going from a lossless video file to both h264 and h265 will typically have h265 files about 30% smaller at the same quality, but this comes with significant tradeoffs for transcoding time. And there is some nuance to getting the best quality, generally there are more resources on how to do this with h264. And h265 hardware support isn't quite universal, many older mobile devices do not support it for instance.
...but you still have to record-and-save it in H.264 first then reload into QuickTime, and for some reason the H.265 quality isn't great. This is still the case even when using GPU VideoToolbox via ffmpeg/Handbrake, and it's something I've never figured out why.
As an aside, for more serious recordings (and if you don't want to use paid software), I recommend using OBS instead, as it gives you a lot more recording flexibility that the native macOS screen recorder lacks.
Maybe i'm wrong, but the comparision is stupid without having ffmpeg re-encode the video with the same codec. Otherwise its just apples to oranges.
Can you please share the full ffmpeg syntax used for converting the H.264 files to H.265?
-preset slower
# You control the tradeoff between video encoding speed and compression
# efficiency with the -preset options.
# ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow.
# Default is medium.> "what if I convert my screen recordings from H.264 to H.265?" Well, two things happend: My files shrink to 6% (not a type)
Sounds like the difference can be huge.
Sorry for my lame English. I really should not write blogs after midnight... Anyways, a lot of you are asking for what command-line options I used for FFMPEG.
So here it is:
ffmpeg -i input1.mov -c:v libx265 -tag:v hvc1 output1.mp4
- The use of the term "Ducked" instead of "searched" or "looked up" which is clearly forced and I guess trying to promote DuckDuckGo. - "Brew.SH" The program is called Homebrew and it is odd to capitalize the website like that. I have never seen someone say Duck.COM. - FFMPEG should be FFmpeg - photos.app should be Photos.app like Terminal.app that he mentioned earlier. - macOS is capitalized a different way literally every time is used.
For any one of these I wouldn't have thought twice, people make up new capitalization for names all the time. It seems to give the writing a condescending tone (helped by comments like "command line for non-Appleonians").
With the current title, I thought maybe there were 2 formats that differed in name only by a dot, and that this post was about clearing up that confusion between the nearly identical names.
typoception
Knowing this makes it less annoying to do it as you don’t have 4 keys combinations.
199x called, it wants its human interface guidelines back
I feel like it's the year of 4K. Greater than 24 inch, 4K monitors and 4k TV's are getting somewhat standard/affordable.
But looking at EZTV only around 18% of torrents are released as H265, which is disappointing.
I wonder which hardware accelerates h265 encoding on Linux.
Sorry for my lame English. I really should not write blogs after midnight... Anyways, a lot of you are asking for what command-line options I used for FFMPEG.
So here it is:
ffmpeg -i input1.mov -c:v libx265 -tag:v hvc1 output1.mp4
I have paid h265 on the windows store for 1 symbolic dollar and I'm sure you can find a license for cheaper, people should respect the media they consume not using h265 for regular video consumers is nonsensical. And no vp9 is inferior and av1 too in addition to the absence of hardware acceleration for av1. H266 has been released last summer, I can't wait for it to become widespread and push the boundaries of the user experience.