Add AudioBitrate as separate Argument

Former-commit-id: 4b88229f72
This commit is contained in:
Malte Rosenbjerg 2020-05-01 10:07:40 +02:00
parent c1393697a3
commit 78e3f5e0c5
6 changed files with 57 additions and 23 deletions

View file

@ -51,8 +51,22 @@ namespace FFMpegCore.Test
[TestMethod] [TestMethod]
public void Builder_BuildString_AudioCodec() public void Builder_BuildString_AudioCodec()
{ {
var str = GetArgumentsString(new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal)); var str = GetArgumentsString(new AudioCodecArgument(AudioCodec.Aac));
Assert.AreEqual(str, "-i \"input.mp4\" -c:a aac -b:a 128k \"output.mp4\""); Assert.AreEqual(str, "-i \"input.mp4\" -c:a aac \"output.mp4\"");
}
[TestMethod]
public void Builder_BuildString_AudioBitrate()
{
var str = GetArgumentsString(new AudioBitrateArgument(AudioQuality.Normal));
Assert.AreEqual(str, "-i \"input.mp4\" -b:a 128k \"output.mp4\"");
}
[TestMethod]
public void Builder_BuildString_Quiet()
{
var str = GetArgumentsString(new QuietArgument());
Assert.AreEqual(str, "-i \"input.mp4\" -hide_banner -loglevel warning \"output.mp4\"");
} }
[TestMethod] [TestMethod]

View file

@ -0,0 +1,19 @@
using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.FFMPEG.Argument
{
/// <summary>
/// Represents parameter of audio codec and it's quality
/// </summary>
public class AudioBitrateArgument : Argument<int>
{
public AudioBitrateArgument(AudioQuality value) : base((int)value) { }
public AudioBitrateArgument(int bitrate) : base(bitrate) { }
/// <inheritdoc/>
public override string GetStringValue()
{
return $"-b:a {Value}k";
}
}
}

View file

@ -7,26 +7,12 @@ namespace FFMpegCore.FFMPEG.Argument
/// </summary> /// </summary>
public class AudioCodecArgument : Argument<AudioCodec> public class AudioCodecArgument : Argument<AudioCodec>
{ {
/// <summary>
/// Bitrate of audio channel
/// </summary>
public int Bitrate { get; } = (int)AudioQuality.Normal;
public AudioCodecArgument() { }
public AudioCodecArgument(AudioCodec value) : base(value) { } public AudioCodecArgument(AudioCodec value) : base(value) { }
public AudioCodecArgument(AudioCodec value, AudioQuality bitrate) : this(value, (int) bitrate) { }
public AudioCodecArgument(AudioCodec value, int bitrate) : base(value)
{
Bitrate = bitrate;
}
/// <inheritdoc/> /// <inheritdoc/>
public override string GetStringValue() public override string GetStringValue()
{ {
return $"-c:a {Value.ToString().ToLower()} -b:a {Bitrate}k"; return $"-c:a {Value.ToString().ToLower()}";
} }
} }
} }

View file

@ -0,0 +1,10 @@
namespace FFMpegCore.FFMPEG.Argument
{
public class QuietArgument : Argument
{
public override string GetStringValue()
{
return "-hide_banner -loglevel warning";
}
}
}

View file

@ -149,7 +149,8 @@ namespace FFMpegCore.FFMPEG
new ScaleArgument(outputSize), new ScaleArgument(outputSize),
new VideoCodecArgument(VideoCodec.LibX264, 2400), new VideoCodecArgument(VideoCodec.LibX264, 2400),
new SpeedArgument(speed), new SpeedArgument(speed),
new AudioCodecArgument(AudioCodec.Aac, audioQuality), new AudioCodecArgument(AudioCodec.Aac),
new AudioBitrateArgument(audioQuality),
new OutputArgument(output))), new OutputArgument(output))),
VideoType.Ogv => Convert(new ArgumentContainer( VideoType.Ogv => Convert(new ArgumentContainer(
new InputArgument(source), new InputArgument(source),
@ -157,7 +158,8 @@ namespace FFMpegCore.FFMPEG
new ScaleArgument(outputSize), new ScaleArgument(outputSize),
new VideoCodecArgument(VideoCodec.LibTheora, 2400), new VideoCodecArgument(VideoCodec.LibTheora, 2400),
new SpeedArgument(speed), new SpeedArgument(speed),
new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality), new AudioCodecArgument(AudioCodec.LibVorbis),
new AudioBitrateArgument(audioQuality),
new OutputArgument(output))), new OutputArgument(output))),
VideoType.Ts => Convert(new ArgumentContainer( VideoType.Ts => Convert(new ArgumentContainer(
new InputArgument(source), new InputArgument(source),
@ -171,7 +173,8 @@ namespace FFMpegCore.FFMPEG
new ScaleArgument(outputSize), new ScaleArgument(outputSize),
new VideoCodecArgument(VideoCodec.LibVpx, 2400), new VideoCodecArgument(VideoCodec.LibVpx, 2400),
new SpeedArgument(speed), new SpeedArgument(speed),
new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality), new AudioCodecArgument(AudioCodec.LibVorbis),
new AudioBitrateArgument(audioQuality),
new OutputArgument(output))), new OutputArgument(output))),
_ => throw new ArgumentOutOfRangeException(nameof(type)) _ => throw new ArgumentOutOfRangeException(nameof(type))
}; };
@ -194,7 +197,8 @@ namespace FFMpegCore.FFMPEG
new InputArgument(image.FullName, audio.FullName), new InputArgument(image.FullName, audio.FullName),
new LoopArgument(1), new LoopArgument(1),
new VideoCodecArgument(VideoCodec.LibX264, 2400), new VideoCodecArgument(VideoCodec.LibX264, 2400),
new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Normal), new AudioCodecArgument(AudioCodec.Aac),
new AudioBitrateArgument(AudioQuality.Normal),
new ShortestArgument(true), new ShortestArgument(true),
new OutputArgument(output) new OutputArgument(output)
); );
@ -375,7 +379,8 @@ namespace FFMpegCore.FFMPEG
return Convert(new ArgumentContainer( return Convert(new ArgumentContainer(
new InputArgument(source.FullName, audio.FullName), new InputArgument(source.FullName, audio.FullName),
new CopyArgument(), new CopyArgument(),
new AudioCodecArgument(AudioCodec.Aac, AudioQuality.Hd), new AudioCodecArgument(AudioCodec.Aac),
new AudioBitrateArgument(AudioQuality.Hd),
new ShortestArgument(stopAtShortest), new ShortestArgument(stopAtShortest),
new OutputArgument(output) new OutputArgument(output)
)); ));

View file

@ -72,7 +72,7 @@ namespace FFMpegCore.FFMPEG
{ {
var metadata = JsonConvert.DeserializeObject<FFMpegStreamMetadata>(probeOutput); var metadata = JsonConvert.DeserializeObject<FFMpegStreamMetadata>(probeOutput);
if (metadata.Streams == null || metadata.Streams.Count == 0) if (metadata?.Streams == null || metadata.Streams.Count == 0)
{ {
throw new FFMpegException(FFMpegExceptionType.File, $"No video or audio streams could be detected. Source: ${info.FullName}"); throw new FFMpegException(FFMpegExceptionType.File, $"No video or audio streams could be detected. Source: ${info.FullName}");
} }