edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9953355Tahinli6 days ago3940 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Objective comparison of two AAC encodes of one reference clip. |
| 3 | |
| 4 | Usage: |
| 5 | aac_score.py <ref.f32le> <channels> <label>=<decoded.f32le>:<encoded.aac> [...] |
| 6 | |
| 7 | `ref.f32le` is the reference PCM (interleaved f32le, 48 kHz). Each decoded file is the |
| 8 | same clip after decoding the encoder's output with ffmpeg. The decoder delay is removed |
| 9 | per encoder by cross-correlating the mono mix over the first five seconds (lag 0..4096). |
| 10 | |
| 11 | Metrics, all over the aligned overlap, per channel then averaged: |
| 12 | snr_db global signal-to-error ratio, 10 log10(sum ref^2 / sum err^2). |
| 13 | segsnr_db mean of per-frame SNR over 2048-sample frames, each clipped to [-10, 35] dB. |
| 14 | nsr_db band noise-to-signal proxy for NMR: STFT (2048 Hann, hop 2048), 20 log-spaced |
| 15 | bands from 100 Hz to 20 kHz, per-band 10 log10(noise / signal), clipped to |
| 16 | [-40, 10] dB, averaged over frames and bands. Lower is better. It has no |
| 17 | psychoacoustic masking threshold, so it is a proxy, not a standard NMR. |
| 18 | kbps encoded size over the reference duration, ADTS headers included. |
| 19 | """ |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | = 2048 |
| 26 | = |
| 27 | |
| 28 | |
| 29 | |
| 30 | = |
| 31 | = // |
| 32 | return |
| 33 | |
| 34 | |
| 35 | |
| 36 | """Lag (samples, >= 0) that best matches dec to ref on the first five seconds.""" |
| 37 | = |
| 38 | = |
| 39 | = |
| 40 | = |
| 41 | = 1 << |
| 42 | = |
| 43 | = |
| 44 | return |
| 45 | |
| 46 | |
| 47 | |
| 48 | = |
| 49 | = |
| 50 | = |
| 51 | = |
| 52 | , , = , , |
| 53 | = |
| 54 | = |
| 55 | = |
| 56 | |
| 57 | , = , |
| 58 | = - |
| 59 | |
| 60 | = // |
| 61 | = |
| 62 | = |
| 63 | = |
| 64 | = |
| 65 | = > 1e-10 |
| 66 | = 10 * |
| 67 | |
| 68 | = ** 2 |
| 69 | = ** 2 |
| 70 | = |
| 71 | |
| 72 | , = , |
| 73 | = |
| 74 | = |
| 75 | |
| 76 | |
| 77 | return |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | return 2 |
| 89 | , = , |
| 90 | = |
| 91 | = / 48000.0 |
| 92 | |
| 93 | , = |
| 94 | , = |
| 95 | = |
| 96 | = * 8 / / 1000.0 |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | return 0 |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | return |
| 108 | |
| 109 | |
| 110 | |
| 111 |