Log in

View Full Version : FFmpeg AVI muxer creates non-compliant Avi files


ProWo
8th July 2022, 09:11
I have noticed that the FFmpeg AVI muxer creates non-compliant Avi files.
Checking these files with AviHex shows errors.
The files still play fine with most software players.
Older hardware players (e.g. DVD players with USB port) can not play them.
If you mux to mkv and then mux this mkv file to AVI with Avidemux, this new Avi file is compliant.
You can check this yourself.
If any of you have contact with the FFmpeg developers, please report this bug so it can be fixed.

TIA
prowo

SeeMoreDigital
8th July 2022, 10:54
In order for your .avi muxes to be "compliant", your audio and video streams need to be encoded in a compliant way (for that container) too!

Given that you have not provided any detailed information about your audio and video streams, it's impossible for anyone to help you!

ProWo
8th July 2022, 12:27
In order for your .avi muxes to be "compliant", your audio and video streams need to be encoded in a compliant way (for that container) too!

Given that you have not provided any detailed information about your audio and video streams, so it's impossible for anyone to help you!

Here is the file info:

General
Complete name : O:\Rip\MainMovie\sample.avi
Format : AVI
Format/Info : Audio Video Interleave
File size : 6.13 MiB
Duration : 38 s 438 ms
Overall bit rate : 1 339 kb/s
Writing application : Lavf59.16.100

Video
ID : 0
Format : MPEG-4 Visual
Format profile : Simple@L3
Format settings, BVOP : No
Format settings, QPel : No
Format settings, GMC : No warppoints
Format settings, Matrix : Default (H.263)
Codec ID : divx
Codec ID/Info : Mainly used by Google
Codec ID/Hint : DivX
Duration : 38 s 438 ms
Bit rate : 882 kb/s
Width : 720 pixels
Height : 480 pixels
Display aspect ratio : 3:2
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.085
Stream size : 4.04 MiB (66%)
Writing library : XviD 74

Audio
ID : 1
Format : AC-3
Format/Info : Audio Coding 3
Codec ID : 00002000-0000-0010-8000-00AA00389B71
Duration : 37 s 984 ms
Bit rate : 448 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 2.03 MiB (33%)
Interleave, duration : 32 ms (0.97 video frame)
Interleave, preload duration : 64 ms


muxed with ffmpeg v5.0.1
Here is the muxed file
https://files.videohelp.com/u/292773/Sample_muxed_with_ffmpeg_to_avi.avi

When the file is played in avidemux, no sound is heard. The audio track is not recognized correctly, probably because it is not muxed correctly.

richardpl
9th July 2022, 09:21
Probably because you try to mux EAC3 codec into avi, and whatever you use does not support that combination at all.
Can you post mediainfo output of avidemux file too?

FranceBB
9th July 2022, 11:14
First of all, the audio should be the last of your concerns: your source is interlaced and you encoded it as progressive! This is a "no, no"!
I can clearly see the fields moving around here:

https://i.imgur.com/FDsSxOO.jpg

while this is as it was supposed to be:

https://i.imgur.com/SnaBf5z.jpg

Given that your mediainfo says "progressive" it means that literally everyone on every TV will see fields instead of frames and the effect will be even more noticeable on recent TVs as they'll upscale the SD image to higher resolutions, thus enlarging those ugly fields.

I would do this in Avisynth on Windows, but since you want to use FFMpeg, I had to use FFMpeg on Fedora 36, so here's the command line you need:


ffmpeg -i "/home/FranceBB/Downloads/sample.avi" -map 0:0 -map 0:1 -map 0:1 -vf "bwdif=mode=0:parity=0:deint=0" -c:v libxvid -vtag XVID -qmin 3 -qmax 4 -preset medium -af loudnorm=I=-24:LRA=14:tp=-2 -ar 48000 -c:a:0 ac3 -b:a:0 384k -c:a:1 libtwolame -b:a:1 192k -ar 48000 "/home/FranceBB/Downloads/SD.avi"


this will produce an xvid file which is truly progressive and it will also encode the audio twice: one in 5.1 AC3 and the other in 2.0 MP2, like it used to be back in the days for those who didn't have Dolby Surround compatible setups.

This is the resulting mediainfo:


General
Complete name : /home/FranceBB/Downloads/SD.avi
Format : AVI
Format/Info : Audio Video Interleave
File size : 5.95 MiB
Duration : 38 s 438 ms
Overall bit rate : 1 298 kb/s
Writing application : Lavf59.16.100

Video
ID : 0
Format : MPEG-4 Visual
Format profile : Simple@L3
Format settings, BVOP : No
Format settings, QPel : No
Format settings, GMC : No warppoints
Format settings, Matrix : Default (H.263)
Codec ID : XVID
Codec ID/Hint : XviD
Duration : 38 s 438 ms
Bit rate : 706 kb/s
Width : 720 pixels
Height : 480 pixels
Display aspect ratio : 3:2
Frame rate : 29.970 (30000/1001) FPS
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.068
Stream size : 3.23 MiB (54%)
Writing library : XviD 69

Audio #1
ID : 1
Format : AC-3
Format/Info : Audio Coding 3
Codec ID : 00002000-0000-0010-8000-00AA00389B71
Duration : 37 s 984 ms
Bit rate : 384 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 1.74 MiB (29%)
Interleave, duration : 32 ms (0.97 video frame)

Audio #2
ID : 2
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 2
Codec ID : 50
Duration : 37 s 992 ms
Bit rate mode : Constant
Bit rate : 192 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Compression mode : Lossy
Stream size : 890 KiB (15%)
Alignment : Aligned on interleaves
Interleave, duration : 24 ms (0.73 video frame)




and this is the encoded sample file (link valid for 7 days): https://we.tl/t-5q2walBFi8

on your TV or whatever you're trying to play it on, it will read the video and the second audio track, thus skipping the 5.1, however on those who have a real Dolby Surround setup OR who use a decently updated player (MPV, MPC-HC with LAV Filters, PotPlayer, VLC etc) will be able to choose which track they wanna listen to and they'll end up on the 5.1 one by default. ;)

SeeMoreDigital
9th July 2022, 11:38
A few seconds or the original source might be helpful...

ProWo
9th July 2022, 13:16
A few seconds or the original source might be helpful...

Here you go with the full information.

1 the Source Videostream
https://files.videohelp.com/u/292773/Sample_Videostream.mkv

2 the Source Audiostream
https://files.videohelp.com/u/292773/Sample_Audiostream.ac3

3 the muxed AVI (with ffmpeg, non compliant)
https://files.videohelp.com/u/292773/Sample_muxed_with_ffmpeg_to_avi.avi

4 the muxed mkv (with ffmpeg, will be loaded later in avidemux and muxed to avi)
https://files.videohelp.com/u/292773/Sample_muxed_with_ffmpeg_to_mkv.mkv

5 the muxed AVI (with Avidemux, from the mkv at 4, compliant)
https://files.videohelp.com/u/292773/Sample_muxed_with_ffmpeg_to_mkv_then_with_avidemux_to_avi.avi

ProWo
9th July 2022, 13:21
First of all, the audio should be the last of your concerns: your source is interlaced and you encoded it as progressive! This is a "no, no"!)

Thanks for hint, but that has nothing to do with the ffmpeg AVI muxer we're talking about here.
By the way, your file is not compliant either.

richardpl
9th July 2022, 14:09
So even if you encode with simple: ffmpeg -i video.file -i audio.file output.avi
It will be non compliant?

ProWo
9th July 2022, 14:18
So even if you encode with simple: ffmpeg -i video.file -i audio.file output.avi
It will be non compliant?
Yes, correct

ProWo
9th July 2022, 14:42
Have opened a new ticket #9826 in the FFmpeg bug tracker.

ProWo
10th July 2022, 16:35
The ffmpeg AVI muxer writes 00002000-0000-0010-8000-00AA00389B71 as Codec ID (for a AC3 5.1 audio file).
If the same ffmpeg muxes the same file to MKV instead, this Codec ID is A_AC3.
Maybe this is the problem ...

filler56789
10th July 2022, 17:14
The ffmpeg AVI muxer writes 00002000-0000-0010-8000-00AA00389B71 as Codec ID (for a AC3 5.1 audio file).

the GUID for "Dolby Digital" audio in a RIFF container (.WAV or .AVI) is
FFFE (for Wave_Format_Extensible) / E06D802C-DB46-11CF-B4D1-00805F6CBBEA.

I had never seen "00002000-0000-0010-8000-00AA00389B71" until yesterday.

nevcairiel
10th July 2022, 23:52
0x2000 is the official TwoCC for AC-3, and here just plugged into the RIFF Base GUID

clsid
11th July 2022, 01:47
The problem seems to be that the RIFF AudioFormat Tag header (strf) in your file is using WAVEFORMATEXTENSIBLE format instead of WAVEFORMATEX.

Some (older) software may not support that.

https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/extensible-wave-format-descriptors

filler56789
11th July 2022, 06:25
The old/original VirtualDub displays the well-known VBR-audio-warning when opening the bad AVI file generated by ffmpeg:
[!] AVI: Variable bitrate (VBR) audio detected. VBR audio in AVI is
non-standard and you may encounter sync errors up to 0ms when attempting
to extract WAV files or playing in some players. If this is a problem, use
Full Processing mode is recommended to decompress or recompress the audio.
(This warning can be disabled in Options, Preferences, AVI. bitrate: 448.0
± 0.0 kbps)

Besides, it doesn't know what "00002000-0000-0010-8000-00AA00389B71" means.

ProWo
11th July 2022, 09:59
The problem seems to be that the RIFF AudioFormat Tag header (strf) in your file is using WAVEFORMATEXTENSIBLE format instead of WAVEFORMATEX.

Some (older) software may not support that.

https://docs.microsoft.com/en-us/windows-hardware/drivers/audio/extensible-wave-format-descriptors

Thanks for the tip. That indeed solved the problem with the AC3 5.1 stream. Replaced FFFE with 2000 (reverse) and audio playback works.

https://files.videohelp.com/u/292773/FFFE.jpg

https://files.videohelp.com/u/292773/2000.jpg

https://files.videohelp.com/u/292773/Differences.jpg

filler56789
11th July 2022, 12:38
Thanks for the tip. That indeed solved the problem with the AC3 5.1 stream. Replaced FFFE with 2000 (reverse) and audio playback works.

Confirming that the ""fixed"" :rolleyes: .AVI now works with VirtualDub.
Anyway, that's a workaround, not a real solution. The TwoCC "0x2000" should be used only for mono and stereo audio, a multichannel stream should always use the TwoCC "0xFFFE" plus the appropriate or correct GUID number. There is no point in messing against what already works only because MichaelSoft loves to invent solutions for problems that don't exist. ;)

https://files.videohelp.com/u/292773/Differences.jpg

Summary: everything is wrong with this file :D

tebasuna51
11th July 2022, 13:01
Besides, it doesn't know what "00002000-0000-0010-8000-00AA00389B71" means.

In the file GSpot27.dat (2007 from https://www.videohelp.com/software/GSpot ) there are a big of Vid CodedID (FourCC) list:
[video codecs]
...
DIVX DivX 4 (OpenDivX) Project Mayo
...
FMP4 FFmpeg/ffdshow ISO MPEG-4 FFmpeg/ffdshow (open source)
...

Maybe old soft can't recognize FMP4 and need DIVX for better compatibility.

Also there are Aud Format (wFormatTag) list:
[audio codecs]
0x0001 PCM Microsoft
0x0003 IEEE FLOAT Microsoft IEEE754
...
0x2000 Dolby AC3 Dolby Labs
...
0xFFFE Extensible wave format

With 0xFFFE the codec is defined with many GUIDS like:
[guids]
{00000001-0000-0010-8000-00AA00389B71} PCM MEDIASUBTYPE_PCM -
{00000003-0000-0010-8000-00AA00389B71} FLOAT MEDIASUBTYPE_IEEE_FLOAT -
...

Seems than GUID's like:
0000[wFormatTag]-0000-0010-8000-00AA00389B71
can be valid also.
For AC3:
00002000-0000-0010-8000-00AA00389B71

Of course for multichannel audio the EXTENSIBLE format is the recommended to include the dwChannelMask in the header.

richardpl
11th July 2022, 13:02
the GUID for "Dolby Digital" audio in a RIFF container (.WAV or .AVI) is
FFFE (for Wave_Format_Extensible) / E06D802C-DB46-11CF-B4D1-00805F6CBBEA.

I had never seen "00002000-0000-0010-8000-00AA00389B71" until yesterday.

Citation needed.

ProWo
11th July 2022, 14:04
Seems than GUID's like:
0000[wFormatTag]-0000-0010-8000-00AA00389B71
can be valid also.
For AC3:
00002000-0000-0010-8000-00AA00389B71

Of course for multichannel audio the EXTENSIBLE format is the recommended to include the dwChannelMask in the header.

This is correct and most players can also play this GUID correctly. Avidemux (latest version) however does not recognize the GUID 00002000-0000-0010-8000-00AA00389B71 and does not play audio.

But the real problem is:
Thousands have old DVD players with USB slots that can only play mpeg1, mpeg2 and mpeg4 video with mp2, mp3 and ac3 audio, as AVI file.
FFmpeg should be able to provide a solution for these users.

However, it only affects AC3 multichannel, the other audioocodecs work (mp2,mp3,ac3 stereo).

ProWo
11th July 2022, 14:29
I suggest an new avi format filter/switch, with which the ffmpeg AVI muxer writes the old audio ID 0x2000, without this filter the new audio ID 0xFFFE is written with the corresponding GUID 0002000-0000-0010-8000-00AA00389B71.
So the downward compatibility is guaranteed and the new features are preserved.

clsid
11th July 2022, 14:51
I have looked at the ffmpeg code and it will only write the extensible data for AC3 when channelmask (or other properties) is non-standard. So a possible workaround could be to modify the channel layout from 5.1 with side channels to 5.1 with back channels. I don't know enough about ffmpeg command line to know if that is possible without re-encoding.

ProWo
11th July 2022, 17:18
I have looked at the ffmpeg code and it will only write the extensible data for AC3 when channelmask (or other properties) is non-standard. So a possible workaround could be to modify the channel layout from 5.1 with side channels to 5.1 with back channels. I don't know enough about ffmpeg command line to know if that is possible without re-encoding.

FFmpeg encodes always Ls and Rs.
Ls and Rs do not mean Left Side and Right Side, but Left Surround and Right Surround.
From this point of view, the Ac3 coding is already correct. The 5.1 (side) written in the AC3 stream by ffmpeg is wrong.

Balling
4th September 2022, 08:13
Someone was banned in google, like Tor :)

I knew this GUID will be there, but still: https://gix.github.io/media-types/

00002000-0000-0010-8000-00AA00389B71

FAST Multimedia AG DVM (Dolby AC-3)