ffmpeg et support du codec Dolby AC-4

L'UltraHD débarque sur la TNT française en DVBT2 avec son lot de nouveaux codecs: HEVC/H265 pour la vidéo, EAC-3 et AC-4 pour l'audio. Oui mais L'AC-4, codec propriétaire de Dolby, n'est pas encore bien supporté par les outils classiques comme ffmpeg. Voyons comment tenter d'y remédier 🧑‍💻.

ffmpeg natif nous confirme qu'il ne connait pas l'AC-4 (ni en encodage, ni en décodage).

en v4 : rien du tout

1ffmpeg-4.4.4-std -hide_banner -codecs | grep ac4
2# rien

en v6.1 : reconnu mais pas décodable

1ffmpeg-6.1-std -hide_banner -codecs | grep ac4
2 ..A.L. ac4                  AC-4

L'histoire de ce support par ffmpeg est ancien, son implémentation est compliquée, pour des raisons par seulement techniques je pense.

Le ticket ouvert depuis des années: https://trac.ffmpeg.org/ticket/8349

Un fichier d'exemple AC-4 dont nous allons nous servir : https://trac.ffmpeg.org/raw-attachment/ticket/8349/atsc3.ts

On tente un transcodage vers du AAC plus classique

1ffmpeg-4.4.4-std -i atsc3.ts -vn test-4.4.4.aac
2Input #0, mpegts, from 'atsc3.ts':
3  Duration: 00:00:10.04, start: 13664.044767, bitrate: 1296 kb/s
4  Program 3
5  Stream #0:0[0x31]: Video: hevc (Main 10) ([36][0][0][0] / 0x0024), yuv420p10le(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 29.97 tbc
6  Stream #0:1[0x32](eng): Data: bin_data (AC-4 / 0x342D4341)
7Output #0, adts, to 'test-4.4.4.aac':
8Output file #0 does not contain any stream

Le codec non supporté est considéré comme bin_data. Le transcodage ne marche pas, ffmpeg ne trouve aucune piste audio exploitable.

On va recompiler ffmpeg et y appliquer un patch proposé par https://github.com/pliu6 qui permettrait le support de ce codec (en décodage uniquement).

Utilisation de mon script maison de compilation, choix de la version actuelle 6.1

1git clone https://github.com/aerogus/ffmpeg-compile
2cd ffmpeg-compile
3cp conf.ini.dist.sh conf.ini.sh
4./run.sh

Vérifiez déjà si ffmpeg est bien compilé dans ./bin/<plateform>/ffmpeg

Ensuite appliquons le patch suivant : https://github.com/FFmpeg/FFmpeg/compare/master...pliu6:FFmpeg:master

les fichiers modifiés sont

  • libavcodec/Makefile
  • libavcodec/ac4dec.c
  • libavcodec/ac4dec_data.h
  • libavcodec/allcodecs.c
  • libavcodec/kbdwin.h

On relance la compilation

1ffmpeg-6.1-ac4 -hide_banner -codecs | grep ac4
2 D.A.L. ac4                  AC-4

Cette fois l'AC-4 est reconnu (Décodage seulement)

Retentons un transcodage

 1ffmpeg-6.1-ac4 -i atsc3.ts -vn test-6.1-ac4.aac
 2Input #0, mpegts, from 'atsc3.ts':
 3  Duration: 00:00:10.04, start: 13664.044767, bitrate: 1296 kb/s
 4  Program 3
 5  Stream #0:0[0x31]: Video: hevc (Main 10) ([36][0][0][0] / 0x0024), yuv420p10le(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn
 6  Stream #0:1[0x32](eng): Audio: ac4 (AC-4 / 0x342D4341), 48000 Hz, 5.1(side), fltp
 7Stream mapping:
 8  Stream #0:1 -> #0:0 (ac4 (native) -> aac (native))
 9[aac @ 0x5da2140] Using a PCE to encode channel layout "5.1(side)"
10Output #0, adts, to 'test-6.1-ac4.aac':
11  Metadata:
12    encoder         : Lavf60.16.100
13  Stream #0:0(eng): Audio: aac (LC), 48000 Hz, 5.1(side), fltp, 394 kb/s
14    Metadata:
15      encoder         : Lavc60.31.102 aac
16[ac4 @ 0x5728280] overread:08.14 bitrate= 257.6kbits/s speed=4.06x
17[out#0/adts @ 0x59ffd80] video:0kB audio:461kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.672057%
18size=     464kB time=00:00:09.96 bitrate= 381.5kbits/s speed= 4.3x
19[aac @ 0x5da2140] Qavg: 187.299

Cette fois notre transcodage AC-4 vers AAC a fonctionné

Mediainfo

À noter que mediainfo arrive bien à extraire les métadonnés du codec AC-4 depuis un certain temps 👍

  1General
  2ID                                       : 1 (0x1)
  3Complete name                            : atsc3.ts
  4Format                                   : MPEG-TS
  5File size                                : 1.55 MiB
  6Duration                                 : 9 s 977 ms
  7Overall bit rate mode                    : Variable
  8Overall bit rate                         : 1 204 kb/s
  9Frame rate                               : 29.970 FPS
 10
 11Video
 12ID                                       : 49 (0x31)
 13Menu ID                                  : 3 (0x3)
 14Format                                   : HEVC
 15Format/Info                              : High Efficiency Video Coding
 16Format profile                           : Main 10@L2.1@Main
 17Codec ID                                 : 36
 18Duration                                 : 10 s 10 ms
 19Width                                    : 640 pixels
 20Height                                   : 360 pixels
 21Display aspect ratio                     : 16:9
 22Frame rate                               : 29.970 (30000/1001) FPS
 23Standard                                 : Component
 24Color space                              : YUV
 25Chroma subsampling                       : 4:2:0 (Type 0)
 26Bit depth                                : 10 bits
 27Color range                              : Limited
 28Color primaries                          : BT.709
 29Transfer characteristics                 : BT.709
 30Matrix coefficients                      : BT.709
 31
 32Audio
 33ID                                       : 50 (0x32)
 34Menu ID                                  : 3 (0x3)
 35Format                                   : AC-4
 36Format/Info                              : Audio Coding 4
 37Commercial name                          : Dolby AC-4
 38Format version                           : Version 2
 39Codec ID                                 : 6
 40Duration                                 : 6 s 172 ms
 41Channel(s)                               : 6 channels
 42Channel layout                           : L R C LFE Ls Rs
 43Sampling rate                            : 48.0 kHz
 44Frame rate                               : 29.970 (30000/1001) FPS (1601.6 SPF)
 45Compression mode                         : Lossy
 46Delay relative to video                  : 3 s 870 ms
 47Language                                 : English
 48Number of presentations                  : 1
 49NumberOfGroups                           : 1
 50Number of substreams                     : 1
 51Presentation #1                          : 5.1 Main
 52 Dialogue normalization                  : -24.00
 53 Loudness                                : Yes
 54  Integrated loudness (speech gated)     : -26.2 LKFS (Automated individual front channels)
 55  Integrated loudness (level gated)      : -23.7 LKFS
 56  Audio Loudness Standard                : Manual
 57  Realtime loudness corrected            : Yes
 58  Dialogue corrected                     : Yes (Automated individual front channels)
 59 Dynamic Range Control                   : Yes
 60 Downmix                                 : Yes
 61  LoRo center mix gain                   : -3.0 dB
 62  LoRo surround mix gain                 : -3.0 dB
 63  LtRt center mix gain                   : -3.0 dB
 64  LtRt surround mix gain                 : -3.0 dB
 65  LFE mix gain                           : -3 dB
 66  Preferred downmix                      : Pro Logic II
 67 Group #s                                : 1
 68Group #1                                 : Main
 69 Content classifier                      : Main
 70 Channel coded                           : Yes
 71 Number of substreams                    : 1
 72 Substream #s                            : 1
 73Substream #1                             : 5.1
 74 Channel mode                            : 5.1
 75 Channel layout                          : L R C LFE Ls Rs
 76 Preprocessing                           : Yes
 77  Phase 90 filter info                   : Not applied
 78  Surround attenuation known             : No
 79  LFE attenuation known                  : Yes
 80 Dialogue enhancement                    : Yes
 81  Enabled                                : Yes
 82  Max gain                               : 9 dB
 83  Channel configuration                  : C
 84
 85Text #1
 86ID                                       : 49 (0x31)-CC1
 87Menu ID                                  : 3 (0x3)
 88Format                                   : EIA-608
 89Muxing mode                              : SCTE 128 / DTVCC Transport
 90Muxing mode, more info                   : Muxed in Video #1
 91Duration                                 : 10 s 10 ms
 92Duration of the visible content          : 8 s 475 ms
 93Start time (commands)                    : 3 h 47 min
 94Start time                               : 3 h 47 min
 95End time                                 : 3 h 47 min
 96Bit rate mode                            : Constant
 97Stream size                              : 0.00 Byte (0%)
 98Count of events                          : 4
 99Count of PopOn events                    : 4
100Count of lines                           : 6
101Maximum count of lines per event         : 2
102Count of frames before first event       : 25
103Type of the first event                  : PopOn
104
105Text #2
106ID                                       : 49 (0x31)-1
107Menu ID                                  : 3 (0x3)
108Format                                   : EIA-708
109Muxing mode                              : SCTE 128 / DTVCC Transport
110Muxing mode, more info                   : Muxed in Video #1
111Duration                                 : 10 s 10 ms
112Bit rate mode                            : Constant
113Stream size                              : 0.00 Byte (0%)

Conclusion

On a hâte que ce patch arrive dans le dépôt officiel ffmpeg pour éviter ce bricolage 🔧. D'autre part l'exemple fourni atsc3.ts est bien compatible avec le patch, mais les essais effectués à partir d'une captation française DVBT2 n'ont pas été concluants. Le stream audio AC-4 est toujours considéré comme bin_data. Une subtile variante de codec entre les normes DVB et ATSC (norme de télévision numérique américaine) ? À suivre 🕵️ ...

Ressources

comments powered by Disqus