Added support for aaxc decryption

This commit is contained in:
Jonas Kamsker 2022-01-12 00:15:32 +01:00
parent bfd2f4a908
commit 2626b3796b
5 changed files with 86 additions and 0 deletions

View file

@ -0,0 +1,16 @@
namespace FFMpegCore.Arguments
{
public class AudibleEncryptionKeyArgument : IArgument
{
private readonly string _key;
private readonly string _iv;
public AudibleEncryptionKeyArgument(string key, string iv)
{
_key = key;
_iv = iv;
}
public string Text => $"-audible_key {_key} -audible_iv {_iv}";
}
}

View file

@ -0,0 +1,14 @@
namespace FFMpegCore.Arguments
{
public class ID3V2VersionArgument : IArgument
{
private readonly int _version;
public ID3V2VersionArgument(int version)
{
_version = version;
}
public string Text => $"-id3v2_version {_version}";
}
}

View file

@ -0,0 +1,44 @@
using FFMpegCore.Extend;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FFMpegCore.Arguments
{
public class MapMetadataArgument : IInputArgument, IDynamicArgument
{
private readonly int? _inputIndex;
/// <summary>
/// Null means it takes the last input used befroe this argument
/// </summary>
/// <param name="inputIndex"></param>
public MapMetadataArgument(int? inputIndex = null)
{
_inputIndex = inputIndex;
}
public string Text => GetText(null);
public string GetText(StringBuilder context)
{
var index = _inputIndex ?? context?.ToString().CountOccurrences("-i") -1 ?? 0;
return $"-map_metadata {index}";
}
public Task During(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
public void Post()
{
}
public void Pre()
{
}
}
}

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using FFMpegCore.Arguments; using FFMpegCore.Arguments;
using FFMpegCore.Enums; using FFMpegCore.Enums;
@ -66,6 +67,10 @@ public FFMpegArgumentOptions WithAudioFilters(Action<AudioFilterOptions> audioFi
public FFMpegArgumentOptions ForcePixelFormat(string pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat)); public FFMpegArgumentOptions ForcePixelFormat(string pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat));
public FFMpegArgumentOptions ForcePixelFormat(PixelFormat pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat)); public FFMpegArgumentOptions ForcePixelFormat(PixelFormat pixelFormat) => WithArgument(new ForcePixelFormat(pixelFormat));
public FFMpegArgumentOptions WithAudibleEncryptionKeys(string key, string iv) => WithArgument(new AudibleEncryptionKeyArgument(key, iv));
public FFMpegArgumentOptions WithTagVersion(int id3v2Version = 3) => WithArgument(new ID3V2VersionArgument(id3v2Version));
public FFMpegArgumentOptions WithArgument(IArgument argument) public FFMpegArgumentOptions WithArgument(IArgument argument)
{ {
Arguments.Add(argument); Arguments.Add(argument);

View file

@ -60,6 +60,13 @@ public FFMpegArguments WithGlobalOptions(Action<FFMpegGlobalArguments> configure
public FFMpegArguments AddMetaData(string content, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(content), addArguments); public FFMpegArguments AddMetaData(string content, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(content), addArguments);
public FFMpegArguments AddMetaData(IReadOnlyMetaData metaData, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(MetaDataSerializer.Instance.Serialize(metaData)), addArguments); public FFMpegArguments AddMetaData(IReadOnlyMetaData metaData, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(MetaDataSerializer.Instance.Serialize(metaData)), addArguments);
/// <summary>
/// Maps the metadata of the given stream
/// </summary>
/// <param name="inputIndex">null means, the previous input will be used</param>
public FFMpegArguments MapMetaData(int? inputIndex = null, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MapMetadataArgument(inputIndex), addArguments);
private FFMpegArguments WithInput(IInputArgument inputArgument, Action<FFMpegArgumentOptions>? addArguments) private FFMpegArguments WithInput(IInputArgument inputArgument, Action<FFMpegArgumentOptions>? addArguments)
{ {
var arguments = new FFMpegArgumentOptions(); var arguments = new FFMpegArgumentOptions();