Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

feat(qta): read Apple Voice Memos recordings (#646)

SeoJCalive28352b2b6a3c
diff --git a/README.ar.md b/README.ar.md
index 2781b046..f7b05937 100644
--- a/README.ar.md
+++ b/README.ar.md
@@ -59,7 +59,7 @@
تظهر الصيغ حيث أنت، ولا يظهر منها إلا ما يناسب الملفات التي تسحبها.
</td>
<td width="33%" valign="top">
- <b>268 صيغة دون برامج أخرى</b><br>
+ <b>269 صيغة دون برامج أخرى</b><br>
الصور وPDF وWord وExcel وPowerPoint وHWP والكتب الإلكترونية والأرشيفات والخطوط وCAD والنماذج ثلاثية الأبعاد والبيانات الجغرافية، كلها تعمل دون Office أو Hancom Office أو LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.es.md b/README.es.md
index 9dd3f2ee..3e6813d3 100644
--- a/README.es.md
+++ b/README.es.md
@@ -57,7 +57,7 @@
Los formatos aparecen donde ya estás, y solo los que tienen sentido para los archivos que arrastras.
</td>
<td width="33%" valign="top">
- <b>268 formatos, sin otros programas</b><br>
+ <b>269 formatos, sin otros programas</b><br>
Imágenes, PDF, Word, Excel, PowerPoint, HWP, libros electrónicos, archivos comprimidos, tipografías, CAD, modelos 3D y datos geoespaciales funcionan sin Office, Hancom Office ni LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.fr.md b/README.fr.md
index 9031a16c..e7fc0b16 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -57,7 +57,7 @@
Les formats apparaissent là où vous êtes déjà, et seulement ceux qui ont un sens pour les fichiers que vous faites glisser.
</td>
<td width="33%" valign="top">
- <b>268 formats, sans autre logiciel</b><br>
+ <b>269 formats, sans autre logiciel</b><br>
Images, PDF, Word, Excel, PowerPoint, HWP, livres numériques, archives, polices, CAO, modèles 3D et données géospatiales fonctionnent sans Office, Hancom Office ni LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.hi.md b/README.hi.md
index 84ee65cc..e204e5a3 100644
--- a/README.hi.md
+++ b/README.hi.md
@@ -57,7 +57,7 @@
फ़ॉर्मैट वहीं दिखते हैं जहाँ आप पहले से हैं, और सिर्फ़ वही जो आपकी खींची जा रही फ़ाइलों के लिए सही हों।
</td>
<td width="33%" valign="top">
- <b>268 फ़ॉर्मैट, कोई और सॉफ़्टवेयर नहीं</b><br>
+ <b>269 फ़ॉर्मैट, कोई और सॉफ़्टवेयर नहीं</b><br>
इमेज, PDF, Word, Excel, PowerPoint, HWP, ई-बुक, आर्काइव, फ़ॉन्ट, CAD, 3D मॉडल और भू-स्थानिक डेटा Office, Hancom Office या LibreOffice के बिना काम करते हैं।
</td>
<td width="33%" valign="top">
diff --git a/README.ja.md b/README.ja.md
index ac80c006..94a0312f 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -57,7 +57,7 @@
いま作業している場所に、ドラッグ中のファイルに合う形式だけが表示されます。
</td>
<td width="33%" valign="top">
- <b>268形式、ほかのソフトは不要</b><br>
+ <b>269形式、ほかのソフトは不要</b><br>
画像、PDF、Word、Excel、PowerPoint、HWP、電子書籍、アーカイブ、フォント、CAD、3Dモデル、地理空間データを、Office、Hancom Office、LibreOfficeなしで変換できます。
</td>
<td width="33%" valign="top">
diff --git a/README.ko.md b/README.ko.md
index 5e192338..eadd43a8 100644
--- a/README.ko.md
+++ b/README.ko.md
@@ -58,7 +58,7 @@
끌고 있는 파일에 맞는 형식만 지금 있는 자리에 나타나요.
</td>
<td width="33%" valign="top">
- <b>268가지 형식, 다른 프로그램 없이</b><br>
+ <b>269가지 형식, 다른 프로그램 없이</b><br>
이미지, PDF, 워드, 엑셀, 파워포인트, HWP, 전자책, 압축 파일, 글꼴, CAD, 3D 모델, 지리 정보 데이터를 오피스·한컴오피스·LibreOffice 없이 변환해요.
</td>
<td width="33%" valign="top">
diff --git a/README.md b/README.md
index dbdc838d..54b4e5b2 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@
The formats appear where you already are, only the ones that make sense for the files you drag.
</td>
<td width="33%" valign="top">
- <b>268 formats, no other software</b><br>
+ <b>269 formats, no other software</b><br>
Images, PDF, Word, Excel, PowerPoint, HWP, e-books, archives, fonts, CAD, 3D models and geospatial data work without Office, Hancom Office or LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.pl.md b/README.pl.md
index cc573632..f44eee54 100644
--- a/README.pl.md
+++ b/README.pl.md
@@ -57,7 +57,7 @@
Formaty pojawiają się tam, gdzie już jesteś, i tylko te, które pasują do przeciąganych plików.
</td>
<td width="33%" valign="top">
- <b>268 formatów bez dodatkowych programów</b><br>
+ <b>269 formatów bez dodatkowych programów</b><br>
Obrazy, PDF, Word, Excel, PowerPoint, HWP, e-booki, archiwa, czcionki, CAD, modele 3D i dane geoprzestrzenne działają bez pakietu Office, Hancom Office i LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.pt-BR.md b/README.pt-BR.md
index a5c5595c..111993ee 100644
--- a/README.pt-BR.md
+++ b/README.pt-BR.md
@@ -57,7 +57,7 @@
Os formatos aparecem onde você já está, só os que fazem sentido para os arquivos que você arrasta.
</td>
<td width="33%" valign="top">
- <b>268 formatos, sem outro programa</b><br>
+ <b>269 formatos, sem outro programa</b><br>
Imagens, PDF, Word, Excel, PowerPoint, HWP, e-books, arquivos compactados, fontes, CAD, modelos 3D e dados geoespaciais funcionam sem Office, Hancom Office ou LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.pt-PT.md b/README.pt-PT.md
index 59ecec2e..d52c9c40 100644
--- a/README.pt-PT.md
+++ b/README.pt-PT.md
@@ -57,7 +57,7 @@
Os formatos aparecem onde estás, apenas os que fazem sentido para os ficheiros que arrastas.
</td>
<td width="33%" valign="top">
- <b>268 formatos, sem outro software</b><br>
+ <b>269 formatos, sem outro software</b><br>
Imagens, PDF, Word, Excel, PowerPoint, HWP, livros digitais, arquivos, tipos de letra, CAD, modelos 3D e dados geoespaciais funcionam sem Office, Hancom Office ou LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.ru.md b/README.ru.md
index ba3a3605..62bc9073 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -57,7 +57,7 @@
Форматы появляются там, где вы уже работаете, и только те, что подходят перетаскиваемым файлам.
</td>
<td width="33%" valign="top">
- <b>268 форматов без лишних программ</b><br>
+ <b>269 форматов без лишних программ</b><br>
Изображения, PDF, Word, Excel, PowerPoint, HWP, электронные книги, архивы, шрифты, чертежи CAD, 3D-модели и геоданные работают без Office, Hancom Office и LibreOffice.
</td>
<td width="33%" valign="top">
diff --git a/README.th.md b/README.th.md
index 7f4e9fa4..1ba9ecab 100644
--- a/README.th.md
+++ b/README.th.md
@@ -57,7 +57,7 @@
ฟอร์แมตที่เหมาะสมจะแสดงขึ้นตรงจุดที่คุณทำงานอยู่ โดยแสดงเฉพาะฟอร์แมตที่ใช้ได้กับไฟล์ที่คุณลากเท่านั้น
</td>
<td width="33%" valign="top">
- <b>268 ฟอร์แมต โดยไม่ต้องลงโปรแกรมอื่นเพิ่ม</b><br>
+ <b>269 ฟอร์แมต โดยไม่ต้องลงโปรแกรมอื่นเพิ่ม</b><br>
รูปภาพ, PDF, Word, Excel, PowerPoint, HWP, อีบุ๊ก, ไฟล์บีบอัด, ฟอนต์, CAD, โมเดล 3D และข้อมูลเชิงพื้นที่ ทำงานได้โดยไม่ต้องมี Microsoft Office, Hancom Office หรือ LibreOffice
</td>
<td width="33%" valign="top">
diff --git a/README.tr.md b/README.tr.md
index 113e5b45..0ea1663e 100644
--- a/README.tr.md
+++ b/README.tr.md
@@ -57,7 +57,7 @@
Formatlar zaten bulunduğunuz yerde görünür; yalnızca sürüklediğiniz dosyalara uygun olanlar listelenir.
</td>
<td width="33%" valign="top">
- <b>268 format, başka yazılım gerekmez</b><br>
+ <b>269 format, başka yazılım gerekmez</b><br>
Görseller, PDF, Word, Excel, PowerPoint, HWP, e-kitaplar, arşivler, yazı tipleri, CAD, 3B modeller ve coğrafi veriler; Office, Hancom Office veya LibreOffice olmadan çalışır.
</td>
<td width="33%" valign="top">
diff --git a/README.zh-CN.md b/README.zh-CN.md
index acb8d00d..ff27cdf9 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -57,7 +57,7 @@
只显示适合当前拖动文件的格式,就在你所在的位置。
</td>
<td width="33%" valign="top">
- <b>268 种格式,无需其他软件</b><br>
+ <b>269 种格式,无需其他软件</b><br>
图片、PDF、Word、Excel、PowerPoint、HWP、电子书、压缩包、字体、CAD、3D 模型和地理信息数据,无需 Office、韩文办公软件或 LibreOffice。
</td>
<td width="33%" valign="top">
diff --git a/README.zh-TW.md b/README.zh-TW.md
index 84598f46..28793cef 100644
--- a/README.zh-TW.md
+++ b/README.zh-TW.md
@@ -57,7 +57,7 @@
只顯示適合當前拖曳檔案的格式,就在你所在的位置。
</td>
<td width="33%" valign="top">
- <b>268 種格式,無需其他軟體</b><br>
+ <b>269 種格式,無需其他軟體</b><br>
圖片、PDF、Word、Excel、PowerPoint、HWP、電子書、壓縮檔、字型、CAD、3D 模型和地理資訊資料,無需 Office、韓文文書軟體或 LibreOffice。
</td>
<td width="33%" valign="top">
diff --git a/docs/ENGINES.md b/docs/ENGINES.md
index a00b4332..29ef5087 100644
--- a/docs/ENGINES.md
+++ b/docs/ENGINES.md
@@ -1509,6 +1509,9 @@ format, and FFmpeg reads what the file holds, so a `.dat` with no video in it fa
Read only (FFmpeg's decoders): APE (Monkey's Audio), Musepack (MPC), TAK, DSF and DFF (DSD), DTS, Speex (SPX) and the
formats above. No encoder for them is in the build, or (DTS) only an experimental one.
+ Apple Voice Memos recordings (`.qta`, read only, #646) are QuickTime audio: FFmpeg's mov demuxer reads them and
+ they go to every audio target, from the first audio track FFmpeg can decode, like any other source
+ (iOS 26 memos also carry a spatial APAC track FFmpeg has no decoder for).
- **Rewrapping instead of re-encoding.** When the target container takes the source's codecs as they are
(`MediaEncoding.Remuxable`: H.264/HEVC + AAC, ALAC, AC-3, E-AC-3 or MP3 for MP4/M4V/MOV, also ProRes and PCM for
diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.cs
index 3774a7ed..93fcdea5 100644
--- a/src/Filee.Core/Formats/FormatRegistry.cs
+++ b/src/Filee.Core/Formats/FormatRegistry.cs
@@ -268,6 +268,8 @@ public static class FormatRegistry
new("dff", "DFF", FormatCategory.Audio, ["dff"], Writable: false),
new("dts", "DTS", FormatCategory.Audio, ["dts"], Writable: false),
new("spx", "Speex", FormatCategory.Audio, ["spx"], Writable: false),
+ // Apple Voice Memos recordings (#646): QuickTime audio, read by FFmpeg's mov demuxer.
+ new("qta", "QTA", FormatCategory.Audio, ["qta"], Writable: false),
// Archives
// ANSYS Workbench project archives use the ZIP container (issue #294).
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index f32156ea..08f12f75 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -123,7 +123,7 @@ public sealed class DonutSettings
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
- public const int CurrentSchemaVersion = 54;
+ public const int CurrentSchemaVersion = 55;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index b788b690..1e16813f 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -931,6 +931,9 @@ internal static class SettingsMigrations
// donut; custom claims stay put.
if (from < 54)
changed |= LearnExtensions(profiles, out _, ["001", "7z.001", "zip.001", "tar.001"]);
+ // v55: Apple Voice Memos recordings (.qta, #646) learn the audio donut; custom claims stay put.
+ if (from < 55)
+ changed |= LearnExtensions(profiles, out _, ["qta"]);
return changed;
}
diff --git a/src/Filee.Engines/Media/ClipPreview.cs b/src/Filee.Engines/Media/ClipPreview.cs
index dcfef629..0102116c 100644
--- a/src/Filee.Engines/Media/ClipPreview.cs
+++ b/src/Filee.Engines/Media/ClipPreview.cs
@@ -77,7 +77,7 @@ public static partial class ClipPreview
{
if ((info.Audio is not null || clip.Music is not null) && Player() is { } ffplay)
{
- decoder = Start(ffmpeg, MediaEncoding.ClipPreviewAudio(input, clip, video, info.Audio is not null), stdin: false);
+ decoder = Start(ffmpeg, MediaEncoding.ClipPreviewAudio(input, clip, video, info.Audio is not null, info.Audio?.Ordinal ?? 0), stdin: false);
player = Start(ffplay, ["-hide_banner", "-loglevel", "error", "-nodisp", "-autoexit",
.. PlayerVolume is { } volume ? new[] { "-volume", volume.ToString(CultureInfo.InvariantCulture) } : [], "-i", "-"], stdin: true);
pump = Pump(decoder, player, stop.Token);
diff --git a/src/Filee.Engines/Media/FfmpegConverter.cs b/src/Filee.Engines/Media/FfmpegConverter.cs
index a712cf16..db42f4e5 100644
--- a/src/Filee.Engines/Media/FfmpegConverter.cs
+++ b/src/Filee.Engines/Media/FfmpegConverter.cs
@@ -577,6 +577,26 @@ public sealed partial class FfmpegConverter(ILogger? logger = null) : IConverter
}
});
+ private static readonly ConcurrentDictionary<string, IReadOnlySet<string>?> Decoders = new();
+
+ /// <summary>
+ /// The decodable codec names of this ffmpeg, cached per executable. Null assumes every codec can be decoded
+ /// when the table cannot be read.
+ /// </summary>
+ internal static IReadOnlySet<string>? DecodableCodecsOf(string ffmpeg, TimeSpan? timeout = null) =>
+ Decoders.GetOrAdd($"{ffmpeg}|{File.GetLastWriteTimeUtc(ffmpeg).Ticks}", _ =>
+ {
+ try
+ {
+ var result = FfmpegRunner.RunBriefly(ffmpeg, ["-hide_banner", "-codecs"], timeout ?? QueryTimeout);
+ return result.ExitCode == 0 ? ParseDecodableCodecs(result.StandardOutput) : null;
+ }
+ catch (Exception ex) when (ex is TimeoutException or InvalidOperationException or System.ComponentModel.Win32Exception or IOException)
+ {
+ return null;
+ }
+ });
+
private static readonly ConcurrentDictionary<string, IReadOnlySet<string>?> Filters = new();
/// <summary>
@@ -615,6 +635,17 @@ public sealed partial class FfmpegConverter(ILogger? logger = null) : IConverter
.Select(parts => parts[1])
.ToHashSet(StringComparer.Ordinal);
+ /// <summary>The decodable codec names in <c>ffmpeg -codecs</c> output.</summary>
+ internal static IReadOnlySet<string> ParseDecodableCodecs(string list) =>
+ // " DEA.L. aac AAC (Advanced Audio Coding) (decoders: aac aac_fixed)"
+ // " ..A.L. apple_apac Apple Positional Audio Codec"
+ list.Split('\n')
+ .Select(line => line.Split(' ', StringSplitOptions.RemoveEmptyEntries))
+ .Where(parts => parts.Length >= 2 && parts[0].Length == 6 && parts[0][0] == 'D'
+ && parts[0][2] is 'V' or 'A' or 'S' or 'D' or 'T')
+ .Select(parts => parts[1])
+ .ToHashSet(StringComparer.Ordinal);
+
private static void TryDelete(string path)
{
try
diff --git a/src/Filee.Engines/Media/LivePhotoWriter.cs b/src/Filee.Engines/Media/LivePhotoWriter.cs
index aa50d7f3..c46fc41d 100644
--- a/src/Filee.Engines/Media/LivePhotoWriter.cs
+++ b/src/Filee.Engines/Media/LivePhotoWriter.cs
@@ -150,7 +150,7 @@ internal static class LivePhotoWriter
List<string> args =
[
.. MediaEncoding.Common, "-ss", Seconds(clip.Start), "-i", input, "-map", "0:V:0",
- .. audio is null ? Array.Empty<string>() : ["-map", "0:a:0"],
+ .. audio is null ? Array.Empty<string>() : ["-map", $"0:a:{audio.Ordinal}"],
"-t", Seconds(clip.Length),
"-vf", $"{toneMap}fps={Fps},scale={width}:{height},setsar=1,format=yuv420p",
];
diff --git a/src/Filee.Engines/Media/MediaEncoding.Clip.cs b/src/Filee.Engines/Media/MediaEncoding.Clip.cs
index aa4e96f7..d36d152f 100644
--- a/src/Filee.Engines/Media/MediaEncoding.Clip.cs
+++ b/src/Filee.Engines/Media/MediaEncoding.Clip.cs
@@ -38,8 +38,9 @@ internal static partial class MediaEncoding
/// </param>
/// <param name="audio">The video's own sound is used (it has sound, and the preset keeps it).</param>
/// <param name="music">The clip's music is mixed in (the preset keeps sound).</param>
+ /// <param name="audioTrack">The selected audio track's ordinal in the input file.</param>
internal static ClipGraph ClipGraphOf(string input, ClipEdit edit, bool audio, int width, int height, string fps, string pixelFormat = "yuv420p",
- bool video = true, bool music = true)
+ bool video = true, bool music = true, int audioTrack = 0)
{
var song = music ? edit.Music : null;
var sound = audio || song is not null;
@@ -65,7 +66,7 @@ internal static partial class MediaEncoding
}
if (audio)
{
- graph.Append("[0:a:0]").Append(n > 1 ? $"asplit={n}" : "anull");
+ graph.Append($"[0:a:{audioTrack}]").Append(n > 1 ? $"asplit={n}" : "anull");
for (var k = 0; k < n; k++)
graph.Append($"[as{k}]");
graph.Append(';');
@@ -156,7 +157,7 @@ internal static partial class MediaEncoding
var tenBit = video.IsHighBitDepth && encoder is "libx265" or "libsvtav1" or "libaom-av1";
// "Remove audio" leaves the clip silent, music and all.
var graph = ClipGraphOf(input, edit, !options.RemoveAudio && info.Audio is not null, width, height, fps, tenBit ? "yuv420p10le" : "yuv420p",
- music: !options.RemoveAudio);
+ music: !options.RemoveAudio, audioTrack: info.Audio?.Ordinal ?? 0);
var audio = graph.HasAudio;
var pal = IsPal(video.FrameRate);
var filter = target is "vob" or "dv"
@@ -192,10 +193,11 @@ internal static partial class MediaEncoding
/// <summary>The arguments that play the sound of <paramref name="edit"/>: a WAV stream on stdout (for ffplay).</summary>
/// <param name="hasAudio">The video has sound of its own (else only the music plays).</param>
- internal static List<string> ClipPreviewAudio(string input, ClipEdit edit, VideoStreamInfo video, bool hasAudio = true)
+ /// <param name="audioTrack">The selected audio track's ordinal in the input file.</param>
+ internal static List<string> ClipPreviewAudio(string input, ClipEdit edit, VideoStreamInfo video, bool hasAudio = true, int audioTrack = 0)
{
var (width, height) = ClipSize(video, 90);
- var graph = ClipGraphOf(input, edit, hasAudio, width, height, "10", video: false);
+ var graph = ClipGraphOf(input, edit, hasAudio, width, height, "10", video: false, audioTrack: audioTrack);
return [.. Common, .. graph.Inputs, "-filter_complex", graph.Filter, "-map", "[a]", "-c:a", "pcm_s16le", "-f", "wav", "pipe:1"];
}
diff --git a/src/Filee.Engines/Media/MediaEncoding.cs b/src/Filee.Engines/Media/MediaEncoding.cs
index f433d5dc..a0f89fd3 100644
--- a/src/Filee.Engines/Media/MediaEncoding.cs
+++ b/src/Filee.Engines/Media/MediaEncoding.cs
@@ -240,7 +240,7 @@ internal static partial class MediaEncoding
var video = info.Video ?? throw new InvalidOperationException("The file has no video stream.");
// An input without sound is fine: the output simply has no audio track. Every track is kept (languages,
// commentary, issue #396), except in containers that hold one and in a clip, which keeps the first one as a
- // copied or edited clip does.
+ // copied or edited clip does. MediaInfo has already left out tracks FFmpeg cannot decode.
IReadOnlyList<AudioStreamInfo> tracks = options.RemoveAudio ? []
: clip is not null || SingleAudioTargets.Contains(target) ? [.. info.AudioTracks.Take(1)]
: info.AudioTracks;
@@ -248,7 +248,7 @@ internal static partial class MediaEncoding
// A clip: FFmpeg seeks the input and decodes from the key frame before the start, so the first frame is exact.
List<string> args = [.. Common, .. clip is { } part ? ClipInput(part) : [], "-i", input, "-map", "0:V:0"];
for (var i = 0; i < tracks.Count; i++)
- args.AddRange(["-map", $"0:a:{i}"]);
+ args.AddRange(["-map", $"0:a:{tracks[i].Ordinal}"]);
if (clip is null && !info.RawStream && CanCopyVideo(target, video, options))
{
@@ -322,7 +322,7 @@ internal static partial class MediaEncoding
List<string> args = [.. Common, .. ClipInput(clip), "-i", input, "-map", "0:V:0"];
if (audio)
- args.AddRange(["-map", "0:a:0"]);
+ args.AddRange(["-map", $"0:a:{info.Audio!.Ordinal}"]);
args.AddRange(["-c", "copy"]);
// Apple plays HEVC in MP4/MOV only under the "hvc1" tag (FFmpeg keeps "hev1" from some sources).
if (video.Codec == "hevc" && target is "mp4" or "m4v" or "mov")
@@ -679,7 +679,7 @@ internal static partial class MediaEncoding
// Ogg: the tags, and the picture as a comment, come from a metadata file (input 1) instead of the source.
if (extras?.MetadataFile is { } metadata)
args.AddRange(["-i", metadata]);
- args.AddRange(["-map", "0:a:0"]);
+ args.AddRange(["-map", $"0:a:{audio.Ordinal}"]);
if (info.CoverStreamIndex is { } cover && CoverTargets.Contains(target))
args.AddRange(["-map", $"0:{cover}", "-c:v", "copy", "-disposition:v:0", "attached_pic"]);
if (extras is { AttachmentFile: { } picture, AttachmentMime: { } mime })
diff --git a/src/Filee.Engines/Media/MediaInfo.cs b/src/Filee.Engines/Media/MediaInfo.cs
index 0bd023d3..697a5851 100644
--- a/src/Filee.Engines/Media/MediaInfo.cs
+++ b/src/Filee.Engines/Media/MediaInfo.cs
@@ -1,5 +1,5 @@
-// What the FFmpeg engine needs to know about a media file before encoding it (duration, first video and audio
-// stream, cover picture), read from ffprobe's JSON output.
+// What the FFmpeg engine needs to know about a media file before encoding it (duration, first video and first
+// decodable audio stream, cover picture), read from ffprobe's JSON output.
using System.Globalization;
using System.Text.Json;
@@ -65,14 +65,15 @@ internal sealed record VideoColor(string? Primaries, string? Transfer, string? M
/// <param name="Language">The language tag (<c>kor</c>, <c>eng</c>, …), null when the file doesn't say.</param>
internal sealed record SubtitleStreamInfo(int Index, string? Codec, string? Language);
-/// <summary>The first audio stream of a file.</summary>
+/// <summary>An audio stream of a file.</summary>
/// <param name="Codec">FFmpeg's codec name (<c>aac</c>, <c>opus</c>, …), null when unknown.</param>
-internal sealed record AudioStreamInfo(int Channels, int SampleRate, string? Codec = null);
+/// <param name="Ordinal">The audio track number in the file, including undecodable tracks (for <c>-map 0:a:Ordinal</c>).</param>
+internal sealed record AudioStreamInfo(int Channels, int SampleRate, string? Codec = null, int Ordinal = 0);
/// <summary>Summary of a media file.</summary>
/// <param name="Duration">Playing time, null when the container does not say (raw streams).</param>
/// <param name="Video">First video stream that is not a cover picture, if any.</param>
-/// <param name="Audio">First audio stream, if any.</param>
+/// <param name="Audio">First audio stream FFmpeg can decode, or the first audio stream when none can be decoded.</param>
/// <param name="CoverStreamIndex">Index of an embedded cover picture (JPEG or PNG) such as album art, if any.</param>
/// <param name="SubtitleStreams">Every subtitle stream in file order, null when there is none.</param>
/// <param name="RawStream">
@@ -80,12 +81,12 @@ internal sealed record AudioStreamInfo(int Channels, int SampleRate, string? Cod
/// always encoded, never copied into a container.
/// </param>
/// <param name="HasAttachments">The file carries attachments (an MKV's subtitle fonts).</param>
-/// <param name="AudioStreams">Every audio stream in file order (languages, commentary), null for none or only one.</param>
+/// <param name="AudioStreams">Decodable audio streams in file order (all when none can be decoded), null for none or only one.</param>
internal sealed record MediaInfo(TimeSpan? Duration, VideoStreamInfo? Video, AudioStreamInfo? Audio, int? CoverStreamIndex,
IReadOnlyList<SubtitleStreamInfo>? SubtitleStreams = null, bool RawStream = false, bool HasAttachments = false,
IReadOnlyList<AudioStreamInfo>? AudioStreams = null)
{
- /// <summary>Every audio stream, in file order: <see cref="Audio"/> first.</summary>
+ /// <summary>Decodable audio streams in file order (all when none can be decoded): <see cref="Audio"/> first.</summary>
public IReadOnlyList<AudioStreamInfo> AudioTracks => AudioStreams ?? (Audio is null ? [] : [Audio]);
/// <summary>Every subtitle stream, in file order.</summary>
@@ -95,7 +96,8 @@ internal sealed record MediaInfo(TimeSpan? Duration, VideoStreamInfo? Video, Aud
/// <summary>
/// Runs ffprobe on <paramref name="input"/>; throws with FFmpeg's message when the file cannot be read, or refuses an
- /// .m4s media segment that needs its init segment (<see cref="DashSegment"/>).
+ /// .m4s media segment that needs its init segment (<see cref="DashSegment"/>). Audio selection follows the codecs
+ /// that the ffmpeg beside this ffprobe can decode.
/// </summary>
public static async Task<MediaInfo> ProbeAsync(string ffprobe, string input, CancellationToken cancellationToken)
{
@@ -108,20 +110,22 @@ internal sealed record MediaInfo(TimeSpan? Duration, VideoStreamInfo? Video, Aud
var reason = FfmpegRunner.Summarize(result.StandardError);
throw new InvalidOperationException($"FFmpeg cannot read this file{(reason.Length > 0 ? ": " + reason : ".")}");
}
- return Parse(result.StandardOutput);
+ var ffmpeg = Path.Combine(Path.GetDirectoryName(ffprobe) ?? "", EngineEnvironment.ProgramName("ffmpeg.exe"));
+ return Parse(result.StandardOutput, FfmpegConverter.DecodableCodecsOf(ffmpeg));
}
- /// <summary>Parses the output of <c>ffprobe -print_format json -show_format -show_streams</c>.</summary>
- public static MediaInfo Parse(string json)
+ /// <summary>Parses ffprobe's JSON; null <paramref name="decodable"/> assumes every codec can be decoded.</summary>
+ public static MediaInfo Parse(string json, IReadOnlySet<string>? decodable = null)
{
using var document = JsonDocument.Parse(json);
var root = document.RootElement;
VideoStreamInfo? video = null;
- AudioStreamInfo? audio = null;
int? cover = null;
List<SubtitleStreamInfo> subtitles = [];
List<AudioStreamInfo> audios = [];
+ List<AudioStreamInfo> undecodable = [];
+ var audioOrdinal = 0;
var attachments = false;
double longestStream = 0;
if (root.TryGetProperty("streams", out var streams) && streams.ValueKind == JsonValueKind.Array)
@@ -149,9 +153,12 @@ internal sealed record MediaInfo(TimeSpan? Duration, VideoStreamInfo? Video, Aud
Text(stream, "extradata_hash"));
break;
case "audio":
- audios.Add(new AudioStreamInfo((int)Number(stream, "channels"), (int)Number(stream, "sample_rate"),
- Text(stream, "codec_name")));
- audio ??= audios[0];
+ var sound = new AudioStreamInfo((int)Number(stream, "channels"), (int)Number(stream, "sample_rate"),
+ Text(stream, "codec_name"), audioOrdinal++);
+ if (decodable is null || sound.Codec is not { } name || decodable.Contains(name))
+ audios.Add(sound);
+ else
+ undecodable.Add(sound);
break;
case "attachment":
attachments = true;
@@ -164,6 +171,9 @@ internal sealed record MediaInfo(TimeSpan? Duration, VideoStreamInfo? Video, Aud
}
}
+ if (audios.Count == 0)
+ audios = undecodable;
+ var audio = audios.FirstOrDefault();
var seconds = root.TryGetProperty("format", out var format) ? Number(format, "duration") : 0;
if (seconds <= 0)
seconds = longestStream;
diff --git a/src/Filee.Engines/Media/MediaJoining.cs b/src/Filee.Engines/Media/MediaJoining.cs
index fd174c21..f609c272 100644
--- a/src/Filee.Engines/Media/MediaJoining.cs
+++ b/src/Filee.Engines/Media/MediaJoining.cs
@@ -28,7 +28,8 @@ internal static class MediaJoining
/// <summary>
/// True when the clips can be joined without an encode: every one is a video MP4 takes as it is, all with the same
/// codec setup (parameter sets: the MP4 keeps only the first clip's), picture size, pixel format, frame rate, turn
- /// and pixel shape, and the same kind of sound (or none at all). Videos from one phone usually are.
+ /// and pixel shape, and the same kind of sound at the same audio track number (or none at all). The concat
+ /// demuxer maps one track number across every clip. Videos from one phone usually are.
/// </summary>
public static bool CanCopyVideos(IReadOnlyList<MediaInfo> clips, MediaOptions options)
{
@@ -43,7 +44,7 @@ internal static class MediaJoining
if (clips[0].Audio is not { } sound)
return clips.All(c => c.Audio is null);
return clips.All(c => c.Audio is { } a && MediaEncoding.CanCopyAudio("mp4", a, options)
- && a.Codec == sound.Codec && a.SampleRate == sound.SampleRate && a.Channels == sound.Channels);
+ && a.Codec == sound.Codec && a.SampleRate == sound.SampleRate && a.Channels == sound.Channels && a.Ordinal == sound.Ordinal);
}
/// <summary>The list of the concat demuxer: one <c>file '…'</c> line per clip, quotes escaped.</summary>
@@ -54,8 +55,8 @@ internal static class MediaJoining
public static List<string> CopyVideos(string listFile, string output, MediaInfo first)
{
List<string> args = [.. MediaEncoding.Common, "-f", "concat", "-safe", "0", "-i", listFile, "-map", "0:V:0"];
- if (first.Audio is not null)
- args.AddRange(["-map", "0:a:0"]);
+ if (first.Audio is { } sound)
+ args.AddRange(["-map", $"0:a:{sound.Ordinal}"]);
args.AddRange(["-c", "copy"]);
if (first.Video?.Codec == "hevc")
args.AddRange(["-tag:v", "hvc1"]);
@@ -103,7 +104,7 @@ internal static class MediaJoining
segments += $"[v{i}]";
if (!withSound)
continue;
- graph.Add(info.Audio is not null ? $"[{i}:a:0]{Resample("stereo")}[a{i}]" : $"{Silence(path, info, "stereo")}[a{i}]");
+ graph.Add(info.Audio is { } sound ? $"[{i}:a:{sound.Ordinal}]{Resample("stereo")}[a{i}]" : $"{Silence(path, info, "stereo")}[a{i}]");
segments += $"[a{i}]";
}
graph.Add($"{segments}concat=n={clips.Count}:v=1:a={(withSound ? 1 : 0)}[v]{(withSound ? "[a]" : "")}");
@@ -142,7 +143,7 @@ internal static class MediaJoining
for (var i = 0; i < clips.Count; i++)
{
var (path, info) = clips[i];
- graph.Add(info.Audio is not null ? $"[{i}:a:0]{Resample(layout)}[a{i}]" : $"{Silence(path, info, layout)}[a{i}]");
+ graph.Add(info.Audio is { } sound ? $"[{i}:a:{sound.Ordinal}]{Resample(layout)}[a{i}]" : $"{Silence(path, info, layout)}[a{i}]");
segments += $"[a{i}]";
}
graph.Add($"{segments}concat=n={clips.Count}:v=0:a=1[a]");
diff --git a/tests/Filee.Core.Tests/QtaFormatTests.cs b/tests/Filee.Core.Tests/QtaFormatTests.cs
new file mode 100644
index 00000000..059238d3
--- /dev/null
+++ b/tests/Filee.Core.Tests/QtaFormatTests.cs
@@ -0,0 +1,82 @@
+// Apple Voice Memos recordings (.qta, #646): a read-only audio source on the audio donut, learned by existing libraries.
+
+using Filee.Core.Formats;
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class QtaFormatTests
+{
+ [Fact]
+ public void Qta_is_audio_filee_reads_but_never_writes()
+ {
+ var qta = FormatRegistry.Detect("Memo.QTA");
+ Assert.NotNull(qta);
+ Assert.Equal(("qta", FormatCategory.Audio, false), (qta.Id, qta.Category, qta.Writable));
+ Assert.Equal("audio", ProfileSelector.Select(BuiltInData.CreateProfiles(), ["Memo.qta"])?.Id);
+ }
+
+ [Fact]
+ public void Version_54_libraries_learn_qta_once()
+ {
+ var presets = BuiltInData.CreatePresets();
+ var profiles = BuiltInData.CreateProfiles();
+ var audio = profiles.Single(p => p.Id == "audio");
+ audio.Extensions.Remove("qta");
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(54, presets, profiles));
+
+ Assert.Contains("qta", audio.Extensions);
+ Assert.False(SettingsMigrations.ApplyToLibrary(54, presets, profiles));
+ }
+
+ [Fact]
+ public void A_saved_version_54_library_learns_qta_on_the_next_start_only()
+ {
+ using var dir = new TempDir();
+ SaveVersion54Library(dir.Path);
+
+ var upgraded = new UserDataStore(dir.Path);
+ upgraded.Load();
+ var audio = upgraded.Profiles.Single(p => p.Id == "audio").Extensions;
+ Assert.Contains("qta", audio);
+ Assert.Equal(AppSettings.CurrentSchemaVersion, upgraded.Settings.SchemaVersion);
+
+ // The user takes it off the audio donut again: the start after that leaves it off.
+ audio.Remove("qta");
+ upgraded.SaveLibrary();
+ upgraded.SaveSettings();
+ var reloaded = new UserDataStore(dir.Path);
+ reloaded.Load();
+ Assert.DoesNotContain("qta", reloaded.Profiles.Single(p => p.Id == "audio").Extensions);
+ }
+
+ [Fact]
+ public void A_version_54_library_leaves_qta_on_the_users_own_donut()
+ {
+ using var dir = new TempDir();
+ SaveVersion54Library(dir.Path, new ToolbarProfile { Id = "my-memos", Name = "Memos", Extensions = ["QTA"] });
+
+ var upgraded = new UserDataStore(dir.Path);
+ upgraded.Load();
+
+ Assert.Equal(["QTA"], upgraded.Profiles.Single(p => p.Id == "my-memos").Extensions);
+ Assert.DoesNotContain("qta", upgraded.Profiles.Single(p => p.Id == "audio").Extensions, StringComparer.OrdinalIgnoreCase);
+ }
+
+ /// <summary>A library saved by Filee at schema 54: no donut has .qta yet, plus <paramref name="own"/> if given.</summary>
+ private static void SaveVersion54Library(string path, ToolbarProfile? own = null)
+ {
+ var store = new UserDataStore(path);
+ store.Load();
+ store.Settings.SchemaVersion = 54;
+ foreach (var profile in store.Profiles)
+ profile.Extensions.Remove("qta");
+ if (own is not null)
+ store.Profiles.Insert(0, own);
+ store.SaveLibrary();
+ store.SaveSettings();
+ }
+}
diff --git a/tests/Filee.Engines.Tests/AudioTracksTests.cs b/tests/Filee.Engines.Tests/AudioTracksTests.cs
index 1d083802..6fd33097 100644
--- a/tests/Filee.Engines.Tests/AudioTracksTests.cs
+++ b/tests/Filee.Engines.Tests/AudioTracksTests.cs
@@ -25,7 +25,7 @@ public class AudioTracksTests(EngineFixture fx) : IClassFixture<EngineFixture>
public void Every_track_is_mapped_and_each_gets_its_own_options()
{
var info = new MediaInfo(TimeSpan.FromMinutes(24), Hd, new AudioStreamInfo(2, 48000, "aac"), null,
- AudioStreams: [new(2, 48000, "aac"), new(6, 48000, "flac"), new(2, 48000, "opus")]);
+ AudioStreams: [new(2, 48000, "aac", 0), new(6, 48000, "flac", 1), new(2, 48000, "opus", 2)]);
var args = Plan("mp4", info, new MediaOptions { MaxHeight = 720 });
@@ -38,6 +38,19 @@ public class AudioTracksTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.DoesNotContain("-c:a", args); // nothing left unaddressed
}
+ [Fact]
+ public void Tracks_ffmpeg_cannot_decode_are_left_out_and_the_rest_keep_their_numbers()
+ {
+ var info = new MediaInfo(TimeSpan.FromSeconds(1), Hd, new AudioStreamInfo(2, 48000, "aac", 1), null,
+ AudioStreams: [new(2, 48000, "aac", 1), new(2, 48000, "opus", 3)]);
+ var args = Plan("mp4", info);
+ Assert.Equal(["0:V:0", "0:a:1", "0:a:3"], args.Where((a, i) => i > 0 && args[i - 1] == "-map"));
+ Assert.Equal("copy", After(args, "-c:a:0"));
+ Assert.Equal("aac", After(args, "-c:a:1"));
+ var flv = Plan("flv", info);
+ Assert.Equal(["0:V:0", "0:a:1"], flv.Where((a, i) => i > 0 && flv[i - 1] == "-map"));
+ }
+
[Fact]
public void One_track_keeps_the_plain_options_and_single_track_containers_take_the_first()
{
diff --git a/tests/Filee.Engines.Tests/ClipTests.cs b/tests/Filee.Engines.Tests/ClipTests.cs
index ea10a844..21844748 100644
--- a/tests/Filee.Engines.Tests/ClipTests.cs
+++ b/tests/Filee.Engines.Tests/ClipTests.cs
@@ -48,6 +48,20 @@ public class ClipTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal("out.mp4", args[^1]);
}
+ [Fact]
+ public void Clips_take_the_sound_track_the_probe_chose()
+ {
+ var info = Movie with { Audio = new AudioStreamInfo(2, 48000, "aac", 1) };
+ var fast = MediaEncoding.ClipCopy("in.mp4", "out.mp4", "mp4", new ClipRange(12.5, 42.5), new MediaOptions(), info);
+ Assert.Equal(["0:V:0", "0:a:1"], fast.Where((a, i) => i > 0 && fast[i - 1] == "-map"));
+ var exact = MediaEncoding.Plan("in.mp4", "out.mp4", "mp4", new MediaOptions(), info, "work",
+ clip: new ClipRange(12.5, 42.5)).Single().Arguments;
+ Assert.Equal(["0:V:0", "0:a:1"], exact.Where((a, i) => i > 0 && exact[i - 1] == "-map"));
+ var edited = MediaEncoding.ClipEditArguments("in.mp4", "out.mp4", "mp4", Parts(), new MediaOptions(), info);
+ Assert.Contains("[0:a:1]asplit=2", After(edited, "-filter_complex"));
+ Assert.Contains("[0:a:1]", After(MediaEncoding.ClipPreviewAudio("in.mp4", Parts(), Hd, audioTrack: 1), "-filter_complex"));
+ }
+
[Fact]
public void A_fast_clip_without_sound_leaves_the_audio_out()
{
diff --git a/tests/Filee.Engines.Tests/HardwareEncodingTests.cs b/tests/Filee.Engines.Tests/HardwareEncodingTests.cs
index 040fd890..24004612 100644
--- a/tests/Filee.Engines.Tests/HardwareEncodingTests.cs
+++ b/tests/Filee.Engines.Tests/HardwareEncodingTests.cs
@@ -462,6 +462,16 @@ public class HardwareEncodingTests(EngineFixture fx) : IClassFixture<EngineFixtu
Assert.True(watch.Elapsed < TimeSpan.FromSeconds(20), $"took {watch.Elapsed}");
}
+ [Fact]
+ public void Decoder_queries_give_up_on_a_missing_or_hanging_ffmpeg()
+ {
+ Assert.Null(FfmpegConverter.DecodableCodecsOf(Path.Combine(fx.NewFolder(), "missing-ffmpeg"), TimeSpan.FromSeconds(1)));
+ var hanging = HangingProgram(fx.NewFolder());
+ var watch = Stopwatch.StartNew();
+ Assert.Null(FfmpegConverter.DecodableCodecsOf(hanging, TimeSpan.FromSeconds(1)));
+ Assert.True(watch.Elapsed < TimeSpan.FromSeconds(20), $"took {watch.Elapsed}");
+ }
+
[Fact]
public void Encoder_lists_are_read()
{
@@ -474,6 +484,24 @@ public class HardwareEncodingTests(EngineFixture fx) : IClassFixture<EngineFixtu
Assert.DoesNotContain("Video", encoders);
}
+ [Fact]
+ public void Decodable_codec_lists_are_read()
+ {
+ var codecs = FfmpegConverter.ParseDecodableCodecs(
+ "Codecs:\n D..... = Decoding supported\n ..A... = Audio codec\n -------\n" +
+ " D.VI.S 012v Uncompressed 4:2:2 10-bit\n" +
+ " DEA.L. aac AAC (Advanced Audio Coding) (decoders: aac aac_fixed)\n" +
+ " ..A.L. apple_apac Apple Positional Audio Codec\r\n" +
+ " DEAIL. mp3 MP3 (MPEG audio layer 3) (decoders: mp3float mp3) (encoders: libmp3lame)\n");
+ Assert.Contains("aac", codecs);
+ Assert.Contains("mp3", codecs);
+ Assert.Contains("012v", codecs);
+ Assert.DoesNotContain("apple_apac", codecs);
+ Assert.DoesNotContain("=", codecs);
+ Assert.DoesNotContain("Decoding", codecs);
+ Assert.DoesNotContain("Audio", codecs);
+ }
+
/// <summary>A program that writes nothing and runs for a minute, keeping its output open (a hung FFmpeg).</summary>
private static string HangingProgram(string folder)
{
diff --git a/tests/Filee.Engines.Tests/LivePhotoCreationTests.cs b/tests/Filee.Engines.Tests/LivePhotoCreationTests.cs
index 7f02eed5..231294c3 100644
--- a/tests/Filee.Engines.Tests/LivePhotoCreationTests.cs
+++ b/tests/Filee.Engines.Tests/LivePhotoCreationTests.cs
@@ -54,6 +54,15 @@ public class LivePhotoCreationTests(EngineFixture fx) : IClassFixture<EngineFixt
return result.StandardOutput;
}
+ [Fact]
+ public void The_live_photo_clip_takes_the_sound_track_the_probe_chose()
+ {
+ var video = new VideoStreamInfo(1920, 1080, 1, 0, 30, "h264", "yuv420p");
+ var args = LivePhotoWriter.ClipArguments("in.mov", "out.mov", "mov", new LivePhotoClip(0, 3, 1), video,
+ new AudioStreamInfo(2, 48000, "aac", 1), new MediaOptions(), "libx264", "");
+ Assert.Equal(["0:V:0", "0:a:1"], args.Where((a, i) => i > 0 && args[i - 1] == "-map"));
+ }
+
// ───────────────────────── iPhone ─────────────────────────
[Theory]
diff --git a/tests/Filee.Engines.Tests/MediaJoiningTests.cs b/tests/Filee.Engines.Tests/MediaJoiningTests.cs
index 9bd35985..51214b94 100644
--- a/tests/Filee.Engines.Tests/MediaJoiningTests.cs
+++ b/tests/Filee.Engines.Tests/MediaJoiningTests.cs
@@ -44,6 +44,30 @@ public class MediaJoiningTests
Assert.False(MediaJoining.CanCopyVideos([unknown, unknown], options));
}
+ [Fact]
+ public void Clips_whose_chosen_sound_is_another_track_are_encoded()
+ {
+ var first = Clip(PhoneVideo, new AudioStreamInfo(2, 48000, "aac", 1));
+ var second = Clip(PhoneVideo, new AudioStreamInfo(2, 48000, "aac", 0));
+ Assert.False(MediaJoining.CanCopyVideos([first, second], new MediaOptions()));
+ Assert.True(MediaJoining.CanCopyVideos([first, first], new MediaOptions()));
+ }
+
+ [Fact]
+ public void Joined_files_take_the_sound_track_the_probe_chose()
+ {
+ var clip = Clip(PhoneVideo, new AudioStreamInfo(2, 48000, "aac", 1));
+ Assert.Contains("0:a:1", MediaJoining.CopyVideos("clips.txt", "out.mp4", clip));
+ var video = MediaJoining.EncodeVideos([("a.mov", clip), ("b.mp4", Clip(PhoneVideo, new AudioStreamInfo(2, 48000, "aac")))],
+ "out.mp4", new MediaOptions(), "libx264", "work");
+ Assert.Contains("[0:a:1]", After(video, "-filter_complex"));
+ Assert.Contains("[1:a:0]", After(video, "-filter_complex"));
+ var audio = MediaJoining.EncodeAudio([("a.mp3", Clip(audio: new AudioStreamInfo(2, 48000, "mp3"))),
+ ("b.qta", Clip(audio: new AudioStreamInfo(2, 48000, "aac", 2)))], "out.m4a", new MediaOptions(), "work");
+ Assert.Contains("[0:a:0]", After(audio, "-filter_complex"));
+ Assert.Contains("[1:a:2]", After(audio, "-filter_complex"));
+ }
+
[Fact]
public void Encoded_clips_fit_the_first_ones_frame_and_a_silent_one_gets_silence()
{
diff --git a/tests/Filee.Engines.Tests/MediaTests.cs b/tests/Filee.Engines.Tests/MediaTests.cs
index 30a558bc..dba6c819 100644
--- a/tests/Filee.Engines.Tests/MediaTests.cs
+++ b/tests/Filee.Engines.Tests/MediaTests.cs
@@ -188,6 +188,188 @@ public class MediaTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Empty(Directory.GetFiles(folder, "segment*.mp4"));
}
+ [Fact]
+ public void Voice_memo_qta_goes_to_every_audio_target_in_one_ffmpeg_step()
+ {
+ // #646: Apple Voice Memos' QuickTime audio, read through FFmpeg's mov demuxer; never a target.
+ foreach (var target in MediaEncoding.AudioTargets.Keys)
+ {
+ var route = Planner().Plan("qta", target);
+ Assert.True(route is not null, target);
+ Assert.Equal("ffmpeg", Assert.Single(route.Steps).Converter.Id);
+ }
+ Assert.DoesNotContain(new FfmpegConverter().Edges, e => e.To == "qta");
+ Assert.Null(Planner().Plan("mp3", "qta"));
+ }
+
+ [Fact]
+ public async Task A_voice_memo_qta_converts_to_audio()
+ {
+ SkipUnlessInstalled();
+ var memo = Path.Combine(fx.NewFolder(), "memo.qta");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y", "-f", "lavfi",
+ "-i", "sine=frequency=440:sample_rate=44100:duration=2", "-c:a", "aac", "-f", "mov", memo]);
+
+ foreach (var target in new[] { "mp3", "wav", "m4a" })
+ {
+ var probed = await ProbeAsync(await ConvertAsync(memo, target));
+ var audio = Assert.Single(probed.Streams, s => s.Type == "audio");
+ Assert.InRange(probed.Duration, 1.7, 2.4);
+ if (target == "m4a")
+ Assert.Equal("aac", audio.Codec);
+ }
+ }
+
+ [Fact]
+ public async Task A_qta_with_more_tracks_converts_its_first_audio_track()
+ {
+ // #646: audio targets take the first sound track (-map 0:a:0), not the second one or a mix of both, and leave
+ // text and timecode (data) tracks out. The tracks differ in channels and length so the result tells them apart.
+ SkipUnlessInstalled();
+ var folder = fx.NewFolder();
+ var srt = Path.Combine(folder, "words.srt");
+ await File.WriteAllTextAsync(srt, "1\n00:00:00,000 --> 00:00:00,900\nhello\n", TestContext.Current.CancellationToken);
+ // FFmpeg writes a timecode (tmcd) track only beside a video track, so the memo is copied out of a clip with one.
+ var stage = Path.Combine(folder, "stage.mov");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=44100:duration=1",
+ "-f", "lavfi", "-i", "sine=frequency=880:sample_rate=44100:duration=2",
+ "-i", srt, "-f", "lavfi", "-i", "testsrc2=size=64x64:rate=1:duration=1",
+ "-ac:a:1", "2", "-map", "0:a", "-map", "1:a", "-map", "2:s", "-map", "3:v",
+ "-c:a", "aac", "-c:s", "mov_text", "-c:v", "mjpeg", "-timecode", "00:00:00:00", "-f", "mov", stage]);
+ var memo = Path.Combine(folder, "memo.qta");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y", "-i", stage,
+ "-map", "0:a", "-map", "0:s", "-map", "0:d", "-c", "copy", "-f", "mov", memo]);
+ var source = await ProbeAsync(memo);
+ Assert.Equal(["audio", "audio", "subtitle", "data"], source.Streams.Select(s => s.Type));
+ Assert.Equal([1, 2], source.Streams.Where(s => s.Type == "audio").Select(s => s.Channels));
+
+ var probed = await ProbeAsync(await ConvertAsync(memo, "mka"));
+ var audio = Assert.Single(probed.Streams);
+ Assert.Equal(("audio", 1), (audio.Type, audio.Channels));
+ Assert.InRange(probed.Duration, 0.8, 1.3);
+ }
+
+ [Fact]
+ public async Task A_qta_whose_first_track_ffmpeg_cannot_decode_converts_the_next_one()
+ {
+ SkipUnlessInstalled();
+ var memo = Path.Combine(fx.NewFolder(), "memo.qta");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=48000:duration=2",
+ "-f", "lavfi", "-i", "sine=frequency=880:sample_rate=44100:duration=1",
+ "-ac:a:0", "4", "-map", "0:a", "-map", "1:a", "-c:a", "aac", "-f", "mov", memo]);
+ WithoutDecoder(memo);
+ Assert.Equal(["apple_apac", "aac"], (await ProbeAsync(memo)).Streams.Select(s => s.Codec));
+
+ foreach (var target in new[] { "mp3", "wav", "m4a" })
+ {
+ var probed = await ProbeAsync(await ConvertAsync(memo, target));
+ var audio = Assert.Single(probed.Streams);
+ Assert.Equal(("audio", 1), (audio.Type, audio.Channels));
+ Assert.InRange(probed.Duration, 0.8, 1.3);
+ }
+ }
+
+ [Fact]
+ public async Task A_qta_whose_only_sound_ffmpeg_cannot_decode_fails_naming_the_codec()
+ {
+ SkipUnlessInstalled();
+ var folder = fx.NewFolder();
+ var memo = Path.Combine(folder, "memo.qta");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "sine=frequency=440:duration=2", "-c:a", "aac", "-f", "mov", memo]);
+ WithoutDecoder(memo);
+ var job = await fx.ConvertAsync([memo], new Preset { TargetFormat = "mp3" });
+ var file = Assert.Single(job.Files);
+ Assert.Equal(FileState.Failed, file.State);
+ Assert.Contains("apple_apac", file.ErrorDetail);
+ Assert.Empty(Directory.GetFiles(folder, "*.mp3"));
+ }
+
+ [Fact]
+ public async Task A_video_whose_first_sound_ffmpeg_cannot_decode_keeps_the_next_one()
+ {
+ SkipUnlessInstalled();
+ var video = Path.Combine(fx.NewFolder(), "clip.mov");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "testsrc2=size=64x64:rate=10:duration=2",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=48000:duration=2",
+ "-f", "lavfi", "-i", "sine=frequency=880:sample_rate=44100:duration=2",
+ "-map", "0:v", "-map", "1:a", "-map", "2:a", "-ac:a:0", "4",
+ "-c:v", "mjpeg", "-c:a", "aac", "-f", "mov", video]);
+ WithoutDecoder(video);
+ Assert.Equal(["apple_apac", "aac"], (await ProbeAsync(video)).Streams.Where(s => s.Type == "audio").Select(s => s.Codec));
+ var probed = await ProbeAsync(await ConvertAsync(video, "mkv"));
+ Assert.Equal(1, Assert.Single(probed.Streams, s => s.Type == "audio").Channels);
+ Assert.Single(probed.Streams, s => s.Type == "video");
+ }
+
+ [Fact]
+ public async Task A_video_whose_later_sound_ffmpeg_cannot_decode_keeps_only_the_first()
+ {
+ SkipUnlessInstalled();
+ var video = Path.Combine(fx.NewFolder(), "clip.mov");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "testsrc2=size=64x64:rate=10:duration=2",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=44100:duration=2",
+ "-f", "lavfi", "-i", "sine=frequency=880:sample_rate=48000:duration=2",
+ "-map", "0:v", "-map", "1:a", "-map", "2:a", "-ac:a:1", "4",
+ "-c:v", "mjpeg", "-c:a", "aac", "-f", "mov", video]);
+ WithoutDecoder(video, track: 1);
+ Assert.Equal(["aac", "apple_apac"], (await ProbeAsync(video)).Streams.Where(s => s.Type == "audio").Select(s => s.Codec));
+ var probed = await ProbeAsync(await ConvertAsync(video, "mkv"));
+ Assert.Equal(1, Assert.Single(probed.Streams, s => s.Type == "audio").Channels);
+ Assert.Single(probed.Streams, s => s.Type == "video");
+ }
+
+ [Fact]
+ public async Task A_late_starting_first_sound_stays_the_first_track()
+ {
+ SkipUnlessInstalled();
+ var late = Path.Combine(fx.NewFolder(), "late.ts");
+ await RunAsync(Tools!.Value.Ffmpeg, ["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "testsrc2=size=64x64:rate=10:duration=12",
+ "-itsoffset", "8", "-f", "lavfi", "-i", "sine=frequency=440:duration=4",
+ "-f", "lavfi", "-i", "sine=frequency=880:duration=12",
+ "-map", "0:v", "-map", "1:a", "-map", "2:a", "-c:v", "mpeg2video", "-c:a", "aac", "-f", "mpegts", late]);
+ var info = await MediaInfo.ProbeAsync(Tools.Value.Ffprobe, late, TestContext.Current.CancellationToken);
+ Assert.Equal(("aac", 0), (info.Audio!.Codec, info.Audio.Ordinal));
+ Assert.Equal([0, 1], info.AudioTracks.Select(t => t.Ordinal));
+ var args = Args("mkv", info: info);
+ Assert.Equal(["0:V:0", "0:a:0", "0:a:1"], args.Where((a, i) => i > 0 && args[i - 1] == "-map"));
+ var probed = await ProbeAsync(await ConvertAsync(late, "mp3"));
+ Assert.Single(probed.Streams, s => s.Type == "audio");
+ Assert.InRange(probed.Duration, 3.5, 4.6);
+ }
+
+ /// <summary>Marks one AAC QuickTime track as APAC, which the bundled FFmpeg identifies but cannot decode.</summary>
+ internal static void WithoutDecoder(string path, int track = 0)
+ {
+ var bytes = File.ReadAllBytes(path);
+ var at = 0;
+ for (var i = 0; i < (track + 1) * 3; i++)
+ {
+ var index = bytes.AsSpan(at).IndexOf("mp4a"u8);
+ Assert.True(index >= 0, "AAC sample entry not found.");
+ at += index;
+ if (i >= track * 3)
+ "apac"u8.CopyTo(bytes.AsSpan(at));
+ at += 4;
+ }
+ at = 0;
+ for (var i = 0; i <= track; i++)
+ {
+ var index = bytes.AsSpan(at).IndexOf("esds"u8);
+ Assert.True(index >= 0, "AAC descriptor not found.");
+ at += index;
+ if (i == track)
+ "free"u8.CopyTo(bytes.AsSpan(at));
+ at += 4;
+ }
+ File.WriteAllBytes(path, bytes);
+ }
+
/// <summary>The top-level boxes of a short MP4 (32-bit sizes, as FFmpeg writes them for small files).</summary>
private static List<(string Type, byte[] Bytes)> TopLevelBoxes(byte[] data)
{
@@ -395,6 +577,13 @@ public class MediaTests(EngineFixture fx) : IClassFixture<EngineFixture>
private static string After(IReadOnlyList<string> args, string option) => args[args.ToList().IndexOf(option) + 1];
+ [Fact]
+ public void Audio_targets_map_the_track_the_probe_chose()
+ {
+ var info = new MediaInfo(TimeSpan.FromSeconds(1), null, new AudioStreamInfo(1, 44100, "aac", 1), null);
+ Assert.Equal("0:a:1", After(Args("mp3", info: info), "-map"));
+ }
+
[Fact]
public void Quality_bitrate_and_size_options_reach_the_encoders()
{
@@ -706,6 +895,32 @@ public class MediaTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Null(raw.Video);
}
+ [Fact]
+ public void Probe_skips_audio_ffmpeg_cannot_decode()
+ {
+ const string json = """
+ { "streams": [
+ { "index": 0, "codec_type": "video", "codec_name": "h264" },
+ { "index": 1, "codec_type": "audio", "codec_name": "apple_apac", "channels": 4, "sample_rate": "48000" },
+ { "index": 2, "codec_type": "audio", "codec_name": "aac", "channels": 0, "sample_rate": "0" },
+ { "index": 3, "codec_type": "audio", "codec_name": "aac", "channels": 2, "sample_rate": "48000", "sample_fmt": "fltp" },
+ { "index": 4, "codec_type": "audio", "channels": 2 }
+ ] }
+ """;
+ var decodable = new HashSet<string> { "h264", "aac" };
+ var info = MediaInfo.Parse(json, decodable);
+ Assert.Equal(new AudioStreamInfo(0, 0, "aac", 1), info.Audio);
+ Assert.Equal([1, 2, 3], info.AudioTracks.Select(t => t.Ordinal));
+ var unknown = MediaInfo.Parse(json);
+ Assert.Equal(new AudioStreamInfo(4, 48000, "apple_apac"), unknown.Audio);
+ Assert.Equal([0, 1, 2, 3], unknown.AudioTracks.Select(t => t.Ordinal));
+ var only = MediaInfo.Parse("""
+ { "streams": [{ "codec_type": "audio", "codec_name": "apple_apac", "channels": 4, "sample_rate": "48000" }] }
+ """, decodable);
+ Assert.Equal(new AudioStreamInfo(4, 48000, "apple_apac"), only.Audio);
+ Assert.Equal([0], only.AudioTracks.Select(t => t.Ordinal));
+ }
+
[Fact]
public void Ffmpeg_progress_and_errors_are_read()
{
diff --git a/tests/Filee.Engines.Tests/MediaToolRealTests.cs b/tests/Filee.Engines.Tests/MediaToolRealTests.cs
index dec78b71..f7148882 100644
--- a/tests/Filee.Engines.Tests/MediaToolRealTests.cs
+++ b/tests/Filee.Engines.Tests/MediaToolRealTests.cs
@@ -141,6 +141,34 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal("aac", probed.Audio!.Codec);
}
+ [Fact]
+ public async Task Clips_whose_sound_is_on_another_track_keep_every_parts_sound_when_merged()
+ {
+ SkipUnlessInstalled();
+ var folder = fx.NewFolder();
+ var first = Path.Combine(folder, "a.mov");
+ await FfmpegAsync(["-hide_banner", "-nostdin", "-v", "error", "-y",
+ "-f", "lavfi", "-i", "testsrc2=size=320x240:rate=25:duration=1",
+ "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=48000:duration=1",
+ "-f", "lavfi", "-i", "sine=frequency=880:sample_rate=48000:duration=1",
+ "-map", "0:v", "-map", "1:a", "-map", "2:a", "-ac:a:0", "4", "-ac:a:1", "2",
+ "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-f", "mov", first]);
+ MediaTests.WithoutDecoder(first);
+ var second = await MakeClipAsync(folder, "b.mov", 1, extra: ["-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-f", "mov"]);
+ var a = await MediaInfo.ProbeAsync(Tools!.Value.Ffprobe, first, TestContext.Current.CancellationToken);
+ var b = await MediaInfo.ProbeAsync(Tools.Value.Ffprobe, second, TestContext.Current.CancellationToken);
+ Assert.Equal(a.Video, b.Video);
+ Assert.Equal(new AudioStreamInfo(2, 48000, "aac", 1), a.Audio);
+ Assert.Equal(new AudioStreamInfo(2, 48000, "aac", 0), b.Audio);
+
+ var output = await RunAsync([first, second], BuiltIn("merge-videos"));
+ var duration = await ProcessRunner.RunAsync(Tools.Value.Ffprobe,
+ ["-v", "error", "-select_streams", "a:0", "-show_entries", "stream=duration", "-of", "csv=p=0", output],
+ TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken);
+ Assert.True(duration.ExitCode == 0, duration.StandardError);
+ Assert.InRange(double.Parse(duration.StandardOutput.Trim(), CultureInfo.InvariantCulture), 1.8, 2.2);
+ }
+
[Fact]
public async Task Clips_of_one_size_but_other_encoder_settings_still_play_after_merging()
{