Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions SentryReplay/PackageManager.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Runtime.InteropServices;
using Serilog;

namespace SentryReplay;

public static class PackageManager
{
private const string FFmpegVersion = "7.1";
private static readonly string FFmpegArchiveRoot = $"ffmpeg-{FFmpegVersion}-full_build-shared";
private static readonly string FFmpegBinFolderName = $"ffmpeg-{FFmpegVersion}-bin";

private static async Task DownloadFile(string url, string savePath)
Expand All @@ -22,7 +22,7 @@ private static async Task DownloadFile(string url, string savePath)
}
}

private static void ExtractFFmpegBin(string zipFilePath, string destinationBinPath)
private static void ExtractFFmpegBin(string zipFilePath, string destinationBinPath, string archiveRoot)
{
if (Directory.Exists(destinationBinPath))
{
Expand All @@ -31,7 +31,7 @@ private static void ExtractFFmpegBin(string zipFilePath, string destinationBinPa

Directory.CreateDirectory(destinationBinPath);

var binPrefix = $"{FFmpegArchiveRoot}/bin/";
var binPrefix = $"{archiveRoot}/bin/";
using var archive = ZipFile.OpenRead(zipFilePath);
foreach (var entry in archive.Entries)
{
Expand Down Expand Up @@ -61,14 +61,20 @@ public static async Task DownloadAndExtractFFmpeg()
{
var outputFolder = Path.GetFullPath(".");
var destinationBinPath = Path.Combine(outputFolder, FFmpegBinFolderName);
var url = $"https://github.com/GyanD/codexffmpeg/releases/download/{FFmpegVersion}/ffmpeg-{FFmpegVersion}-full_build-shared.zip"; // TODO: ARM64 builds?
var url = RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => $"https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n{FFmpegVersion}-latest-win64-gpl-shared-{FFmpegVersion}.zip",
Architecture.Arm64 => $"https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n{FFmpegVersion}-latest-winarm64-gpl-shared-{FFmpegVersion}.zip",
_ => throw new NotSupportedException($"FFmpeg download is not supported for {RuntimeInformation.ProcessArchitecture}."),
};
var tempPath = Path.GetTempFileName();
var archiveRoot = Path.GetFileNameWithoutExtension(new Uri(url).AbsolutePath);

Log.Information($"Downloading ffmpeg to {tempPath} from {url}");
await DownloadFile(url, tempPath);

Log.Information($"Extracting ffmpeg bin to {destinationBinPath}");
ExtractFFmpegBin(tempPath, destinationBinPath);
ExtractFFmpegBin(tempPath, destinationBinPath, archiveRoot);

File.Delete(tempPath);
}
Expand Down