Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/ensure-ffmpeg-not-found-throws-ffmpeg…
Browse files Browse the repository at this point in the history
…exception
  • Loading branch information
rosenbjerg authored Dec 4, 2024
2 parents d43ea98 + 10bc004 commit f31dc2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
22 changes: 22 additions & 0 deletions FFMpegCore/FFMpeg/Arguments/CropArgument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Drawing;

namespace FFMpegCore.Arguments
{
public class CropArgument : IArgument
{
public readonly Size? Size;
public readonly int Top;
public readonly int Left;

public CropArgument(Size? size, int top, int left)
{
Size = size;
Top = top;
Left = left;
}

public CropArgument(int width, int height, int top, int left) : this(new Size(width, height), top, left) { }

public string Text => Size == null ? string.Empty : $"-vf crop={Size.Value.Width}:{Size.Value.Height}:{Left}:{Top}";
}
}
2 changes: 2 additions & 0 deletions FFMpegCore/FFMpeg/Enums/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static class AudioCodec
public static Codec Ac3 => FFMpeg.GetCodec("ac3");
public static Codec Eac3 => FFMpeg.GetCodec("eac3");
public static Codec LibMp3Lame => FFMpeg.GetCodec("libmp3lame");
public static Codec Copy => new Codec("copy", CodecType.Audio);

}

public static class VideoType
Expand Down
5 changes: 4 additions & 1 deletion FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ internal FFMpegArgumentOptions() { }
public FFMpegArgumentOptions WithVariableBitrate(int vbr) => WithArgument(new VariableBitRateArgument(vbr));
public FFMpegArgumentOptions Resize(int width, int height) => WithArgument(new SizeArgument(width, height));
public FFMpegArgumentOptions Resize(Size? size) => WithArgument(new SizeArgument(size));

public FFMpegArgumentOptions Crop(Size? size, int left, int top) => WithArgument(new CropArgument(size, top, left));
public FFMpegArgumentOptions Crop(int width, int height, int left, int top) => WithArgument(new CropArgument(new Size(width, height), top, left));
public FFMpegArgumentOptions Crop(Size? size) => WithArgument(new CropArgument(size, 0, 0));
public FFMpegArgumentOptions Crop(int width, int height) => WithArgument(new CropArgument(new Size(width, height), 0, 0));
public FFMpegArgumentOptions WithBitStreamFilter(Channel channel, Filter filter) => WithArgument(new BitStreamFilterArgument(channel, filter));
public FFMpegArgumentOptions WithConstantRateFactor(int crf) => WithArgument(new ConstantRateFactorArgument(crf));
public FFMpegArgumentOptions CopyChannel(Channel channel = Channel.Both) => WithArgument(new CopyArgument(channel));
Expand Down
5 changes: 4 additions & 1 deletion FFMpegCore/FFProbe/MediaAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ private MediaFormat ParseFormat(Format analysisFormat)
};
}

private string GetValue(string tagName, Dictionary<string, string>? tags, string defaultValue) =>
tags == null ? defaultValue : tags.TryGetValue(tagName, out var value) ? value : defaultValue;

private ChapterData ParseChapter(Chapter analysisChapter)
{
var title = analysisChapter.Tags.FirstOrDefault(t => t.Key == "title").Value;
var title = GetValue("title", analysisChapter.Tags, "TitleValueNotSet");
var start = MediaAnalysisUtils.ParseDuration(analysisChapter.StartTime);
var end = MediaAnalysisUtils.ParseDuration(analysisChapter.EndTime);

Expand Down

0 comments on commit f31dc2b

Please sign in to comment.