Add other stream types to Channel (V,s,d,t)

Former-commit-id: ca8275436b
This commit is contained in:
Sky Z 2022-07-14 02:23:38 -04:00 committed by Malte Rosenbjerg
parent 638f4cae89
commit a776db85d2
4 changed files with 53 additions and 11 deletions

View file

@ -16,9 +16,8 @@ public CopyArgument(Channel channel = Channel.Both)
public string Text => Channel switch
{
Channel.Audio => "-c:a copy",
Channel.Video => "-c:v copy",
_ => "-c copy"
Channel.Both => "-c:a copy -c:v copy",
_ => $"-c{Channel.StreamType()} copy"
};
}
}

View file

@ -1,19 +1,28 @@
namespace FFMpegCore.Arguments
using FFMpegCore.Enums;
namespace FFMpegCore.Arguments
{
/// <summary>
/// Represents choice of video stream
/// Represents choice of stream by the stream specifier
/// </summary>
public class MapStreamArgument : IArgument
{
private readonly int _inputFileIndex;
private readonly int _streamIndex;
private readonly Channel _channel;
public MapStreamArgument(int streamIndex, int inputFileIndex)
public MapStreamArgument(int streamIndex, int inputFileIndex, Channel channel = Channel.All)
{
if (channel == Channel.Both)
{
// "Both" is not valid in this case and probably means all stream types
channel = Channel.All;
}
_inputFileIndex = inputFileIndex;
_streamIndex = streamIndex;
_channel = channel;
}
public string Text => $"-map {_inputFileIndex}:{_streamIndex}";
public string Text => $"-map {_inputFileIndex}{_channel.StreamType()}:{_streamIndex}";
}
}

View file

@ -46,10 +46,43 @@ public enum Filter
Aac_AdtstoAsc
}
/// <summary>
/// https://ffmpeg.org/ffmpeg.html#Stream-specifiers-1
/// v or V for video, a for audio, s for subtitle, d for data, and t for attachments
/// V only matches video streams which are not attached pictures, video thumbnails or cover arts.
/// Both for audio + video
/// All for all types
/// </summary>
public enum Channel
{
Audio,
Video,
Both
Both,
VideoNoAttachedPic,
Subtitle,
Data,
Attachments,
All
}
internal static class ChannelMethods
{
/// <summary>
/// <see cref="Channel.Both"/> is left as empty because it cannot be in a single stream specifier
/// </summary>
/// <returns>The stream_type used in stream specifiers</returns>
public static string StreamType(this Channel channel)
{
return channel switch
{
Channel.Audio => ":a",
Channel.Video => ":v",
Channel.VideoNoAttachedPic => ":V",
Channel.Subtitle => ":s",
Channel.Data => ":d",
Channel.Attachments => ":t",
_ => string.Empty
};
}
}
}

View file

@ -61,9 +61,10 @@ public FFMpegArgumentOptions WithAudioFilters(Action<AudioFilterOptions> audioFi
public FFMpegArgumentOptions Seek(TimeSpan? seekTo) => WithArgument(new SeekArgument(seekTo));
public FFMpegArgumentOptions Loop(int times) => WithArgument(new LoopArgument(times));
public FFMpegArgumentOptions OverwriteExisting() => WithArgument(new OverwriteArgument());
public FFMpegArgumentOptions SelectStream(int streamIndex, int inputFileIndex = 0) => WithArgument(new MapStreamArgument(streamIndex, inputFileIndex));
public FFMpegArgumentOptions SelectStreams(IEnumerable<int> streamIndices, int inputFileIndex = 0) =>
streamIndices.Aggregate(this, (options, streamIndex) => options.SelectStream(streamIndex, inputFileIndex));
public FFMpegArgumentOptions SelectStream(int streamIndex, int inputFileIndex = 0,
Channel channel = Channel.All) => WithArgument(new MapStreamArgument(streamIndex, inputFileIndex, channel));
public FFMpegArgumentOptions SelectStreams(IEnumerable<int> streamIndices, int inputFileIndex = 0, Channel channel = Channel.All) =>
streamIndices.Aggregate(this, (options, streamIndex) => options.SelectStream(streamIndex, inputFileIndex, channel));
public FFMpegArgumentOptions ForceFormat(ContainerFormat format) => WithArgument(new ForceFormatArgument(format));
public FFMpegArgumentOptions ForceFormat(string format) => WithArgument(new ForceFormatArgument(format));