Recording video and audio with AAC audio codec don't play back correctly in Windows Media Player because of wrong audio codec.
-
How to reproduce:
- Build and run the "Camera Example" on Windows
- Switch to "Video" mode
- Settings: Either keep the "Default audio codec" or set to "Advanced Audio Codec (AAC)" - both create the same file format.
- Record a video file and make some noise.
- Play back the video in Windows Media Player (without any additional codecs/packs installed)
- There is no audio!
ffprobe
of the generated file results in:Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video_0004.mp4': [...] Duration: 00:00:04.35, start: 0.000000, bitrate: 3924 kb/s Stream #0:0[0x1](und): Audio: aac (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 54 kb/s (default) [...] Stream #0:1[0x2](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 1280x720, 3905 kb/s, SAR 1:1 DAR 16:9, 30.20 fps, 60 tbr, 30k tbn [...]
Interestingly, reencoding the audio of the generated file using
ffmpeg.exe -i video_0004.mp4 -acodec aac -vcodec copy video_0004_reencoded.mp4
results in a file that plays back correctly in Windows Media Player.The reencoded file's
ffprobe
output is:Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\ChristophNiederberge\Videos\video_0004_reencoded.mp4': [...] Duration: 00:00:04.35, start: 0.000000, bitrate: 3924 kb/s Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 1280x720, 3875 kb/s, SAR 1:1 DAR 16:9, 29.97 fps, 60 tbr, 30k tbn [...] Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 54 kb/s (default) [...]
With the subtle but important difference of having a
aac (LC)
instead of theaac
as audio codec information.Notes:
- This is independent of the container format
- This is independent of the video codec
- This is independent of the audio sample rate (afaik)
- This is independent of the video resolution
- This is independent of the encoding quality or bitrate settings
-
Regarding your notes: it may be independent of all those things but it may be dependent on the compiler toolchain used, the Qt version in use, and the Windows version for both recording and playback.
The Windows component that generated the audio stream provided something odd that Windows Media Player cannot understand.
ffmpeg
produces valid AAC Low Complexity the Windows Media Player does understand. It's unclear what the original stream is. If the original stream was AAC Main Profile thenffprobe
would have reported "Audio: aac (Main) (mp4a / 0x6134706D)...". High Efficiency AAC would be reported as "Audio: aac (HE-AAC) (mp4a / 0x6134706D)" (and less likely to be playable).Does the audio play correctly if extracted from the container?
ffmpeg.exe -i original_video.mp4 -c: copy -vn original_video_audio.m4a