Opened 17 months ago

Last modified 16 months ago

#11556 new enhancement

Apply sensible FourCC for H.265 in AVI

Reported by: v0lt Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: avi
Cc: MasterQuestionable Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes

Description

Summary of the bug:
When encoding video with libx265 encoder and saving to AVI, the file has an incorrect header. The biCompression field is zero, which corresponds to BI_RGB (uncompressed RGB). This AVI file does not play and may cause some players to crash.

How to reproduce:

% ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libx265 output.avi

ffmpeg version 2025-04-23-git-25b0a8e295-full_build-www.gyan.dev Copyright (c) 2000-2025 the FFmpeg developers

Yes I understand that saving HEVC video to AVI file is a bad idea. But FFmpeg does not write any warnings or errors for this case.

The error can be fixed by adding the "-vtag HEVC" parameter, but I think it should have happened automatically, as it does for the libx264 encoder.

Change History (10)

comment:1 by MasterQuestionable, 17 months ago

Analyzed by developer: set
Cc: MasterQuestionable added
Component: undeterminedavformat
Keywords: avi added
Summary: Encoding video with libx265 to AVI creates a broken fileApply sensible FourCC for H.265 in AVI
Type: defectenhancement
Version: unspecifiedgit-master

comment:2 by compn, 16 months ago

i dont believe h265 is a codec that should be used with avi. so i'd say this bug is invalid.

x264/h264 likewise should not be used in the avi container format.

there is some information here on why h264 in avi container is bad and should not be used.
https://forum.videohelp.com/threads/381188-is-H264-on-AVI-a-hack

h265 uses many of the other codec technologies that h264 uses. which makes using the avi container for these codecs improper.

comment:3 by Aleksoid1978, 16 months ago

Then you need to prohibit ffmpeg from writing h264/h265 to AVI.

comment:4 by MasterQuestionable, 16 months ago

͏    Incompatible with AVI, primarily for inability to properly present B-frame.
͏    But there are some cases where AVI is still used.
͏    E.g. https://trac.ffmpeg.org/ticket/11530#comment:2
͏    (given lacking Matroska support; and the MP4 undue corruption is to be avoided)

͏    Affects legacy environments mostly.

in reply to:  3 ; comment:5 by compn, 16 months ago

Replying to Aleksoid1978:

Then you need to prohibit ffmpeg from writing h264/h265 to AVI.

it would require us to compile and maintain a list of all incompatible codecs with incompatible containers along with all incompatible colorspaces, incompatible sample rates, bit depths, resolutions, channels, streams, fourcc, isom, tags, subtitles...

it would add quite a bit of LOC to the project and would take up a bunch of developer time. for extremely low benefit. if you make an h265 in avi file and realize it doesnt play in your player, you learn immediately that you goofed. and the only way to output avi is if the user specifies it. user error.

https://ffmpeg.org/ffmpeg-all.html#libx265

if you just wanted to improve the documentation by specifying common containers for lib265 encoder . that can be done. the example in the DOCS already lists .mp4, not .avi output.

in reply to:  5 comment:6 by Kieran Kunhya, 16 months ago

Replying to compn:

Replying to Aleksoid1978:

Then you need to prohibit ffmpeg from writing h264/h265 to AVI.

it would require us to compile and maintain a list of all incompatible codecs with incompatible containers along with all incompatible colorspaces, incompatible sample rates, bit depths, resolutions, channels, streams, fourcc, isom, tags, subtitles...

it would add quite a bit of LOC to the project and would take up a bunch of developer time. for extremely low benefit. if you make an h265 in avi file and realize it doesnt play in your player, you learn immediately that you goofed. and the only way to output avi is if the user specifies it. user error.

https://ffmpeg.org/ffmpeg-all.html#libx265

if you just wanted to improve the documentation by specifying common containers for lib265 encoder . that can be done. the example in the DOCS already lists .mp4, not .avi output.

This is an absurd argument and demeaning to users. We should totally forbid muxing things that are not supported by a container.

comment:7 by MasterQuestionable, 16 months ago

͏    It is partially supported.
͏    With actual usage.
͏    Of its caveat.

͏    "Think for the users, for the users do not think."
͏    Such would be overdone.

comment:8 by v0lt, 16 months ago

Ok. I did more tests with AVI output.

ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v wmv1       output_wmv1.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v wmv2       output_wmv2.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v mpeg4      output_mpeg4.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v msmpeg4v2  output_msmpeg4v2.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v msmpeg4    output_msmpeg4.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libxvid    output_libxvid.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libvpx     output_libvpx.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libvpx-vp9 output_libvpx-vp9.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libaom-av1 output_libaom-av1
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v librav1e   output_librav1e.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libsvtav1  output_libsvtav1.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libx264    output_libx264.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libx265    output_libx265.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libx265 -vtag HEVC output_libx265_vtag_HEVC.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libvvenc   output_libvvenc.avi
ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libvvenc -vtag VVC1 output_libvvenc_vtag_VVC1.avi

And I got these results:

wmv1       - OK
wmv2       - OK
mpeg4      - OK
msmpeg4v2  - OK, warning, clipping 2 dct coefficients to -127..127
msmpeg4    - OK, warning, clipping 2 dct coefficients to -127..127
libxvid    - OK
libvpx     - OK
libvpx-vp9 - OK
libaom-av1 - FAIL, Unable to choose an output format for 'output_libaom-av1'; use a standard extension for the filename or specify the format manually.
librav1e   - OK
libsvtav1  - OK
libx264    - OK
libx265    - broken output file (BI_RGB)
libx265 (vtag HEVC) - OK
libvvenc   - broken output file (BI_RGB)
libvvenc (vtag VVC1) - OK

I checked file playback in ffplay.exe.

I'll quote myself from the first post:

Yes I understand that saving HEVC video to AVI file is a bad idea. But FFmpeg does not write any warnings or errors for this case.

But as we can see, for some encoders (libaom-av1) FFmpeg blocks recording to AVI.(missing extension in command line)

Last edited 16 months ago by v0lt (previous) (diff)

in reply to:  8 ; comment:9 by Gyan, 16 months ago

Replying to v0lt:

Ok. I did more tests with AVI output.

ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p -c:v libaom-av1 output_libaom-av1

And I got these results:

libaom-av1 - FAIL, Unable to choose an output format for 'output_libaom-av1'; use a standard extension for the filename or specify the format manually.

But as we can see, for some encoders (libaom-av1) FFmpeg blocks recording to AVI.

Your AOM attempt lacks the .avi extension in the output filename.

in reply to:  9 comment:10 by v0lt, 16 months ago

Replying to Gyan:

Your AOM attempt lacks the .avi extension in the output filename.

Indeed. It's my mistake.

Note: See TracTickets for help on using tickets.