From 462a71c75b4d326c0ce787cd13f7048e7f5da630 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Wed, 18 Dec 2024 11:00:37 +0900
Subject: [PATCH] Add support for ALAC in MP4

> ALAC audio inside MP4 files was what you usually got when you set up iTunes
> to do lossless rips back in the day, and it still has the advantage of being
> the easiest way to get lossless music onto an iPod without a firmware replacement.

Closes #96
---
 README.md          | 1 +
 src/cyanrip_main.c | 1 +
 src/cyanrip_main.h | 1 +
 3 files changed, 3 insertions(+)

diff --git a/README.md b/README.md
index 2bd572b..34e6db1 100644
--- a/README.md
+++ b/README.md
@@ -166,6 +166,7 @@ The output encoding(s) can be set via the `-o` option as a comma-separated list.
 | `mp3`       | Standard MP3 files                              | `.mp3`    | :heavy_check_mark:  | VBR, use -b to adjust the bitrate, default is 256 (kbps)  |
 | `vorbis`    | Standard Ogg/Vorbis files (in an OGG container) | `.ogg`    | ⬜                  | Use -b to adjust the bitrate, default is 256 (kbps)       |
 | `wav`       | Standard WAV files                              | `.wav`    | ⬜                  | 16-bit little endian signed audio, or 32-bit in HDCD mode |
+| `alac_mp4`  | Standard MP4 files (with ALAC encoding)         | `.mp4`    | :heavy_check_mark:  | Always uses maximum compression                           |
 | `aac_mp4`   | Standard MP4 files (with AAC encoding)          | `.mp4`    | :heavy_check_mark:  | Use -b to adjust the bitrate, default is 256 (kbps)       |
 | `opus_mp4`  | Standard MP4 files (with Opus encoding)         | `.mp4`    | :heavy_check_mark:  | Use -b to adjust the bitrate, default is 256 (kbps)       |
 | `pcm`       | Raw audio, 16-bits, two channel, little-endian  | `.raw`    | ⬜                  |                                                           |
diff --git a/src/cyanrip_main.c b/src/cyanrip_main.c
index 50b439e..64a04c0 100644
--- a/src/cyanrip_main.c
+++ b/src/cyanrip_main.c
@@ -51,6 +51,7 @@ const cyanrip_out_fmt crip_fmt_info[] = {
     [CYANRIP_FORMAT_WAVPACK]  = { "wavpack",  "WV",   "wv",    "wv",    0,  3, 1, AV_CODEC_ID_WAVPACK,   },
     [CYANRIP_FORMAT_VORBIS]   = { "vorbis",   "OGG",  "ogg",   "ogg",   0,  0, 0, AV_CODEC_ID_VORBIS,    },
     [CYANRIP_FORMAT_ALAC]     = { "alac",     "ALAC", "m4a",   "ipod",  0,  2, 1, AV_CODEC_ID_ALAC,      },
+    [CYANRIP_FORMAT_ALAC_MP4] = { "alac_mp4", "ALAC", "mp4",   "mp4",   1,  2, 1, AV_CODEC_ID_ALAC,      },
     [CYANRIP_FORMAT_WAV]      = { "wav",      "WAV",  "wav",   "wav",   0,  0, 1, AV_CODEC_ID_NONE,      },
     [CYANRIP_FORMAT_OPUS_MP4] = { "opus_mp4", "OPUS", "mp4",   "mp4",   1, 10, 0, AV_CODEC_ID_OPUS,      },
     [CYANRIP_FORMAT_PCM]      = { "pcm",      "PCM",  "pcm",   "s16le", 0,  0, 1, AV_CODEC_ID_NONE,      },
diff --git a/src/cyanrip_main.h b/src/cyanrip_main.h
index 31ccce0..0efd43d 100644
--- a/src/cyanrip_main.h
+++ b/src/cyanrip_main.h
@@ -43,6 +43,7 @@ enum cyanrip_output_formats {
     CYANRIP_FORMAT_AAC,
     CYANRIP_FORMAT_WAVPACK,
     CYANRIP_FORMAT_ALAC,
+    CYANRIP_FORMAT_ALAC_MP4,
     CYANRIP_FORMAT_MP3,
     CYANRIP_FORMAT_VORBIS,
     CYANRIP_FORMAT_WAV,