Skip to content

Instantly share code, notes, and snippets.

@tqk2811
Last active April 26, 2023 13:14
Show Gist options
  • Save tqk2811/9f2f074fc973b5471b5f1526665c3e41 to your computer and use it in GitHub Desktop.
Save tqk2811/9f2f074fc973b5471b5f1526665c3e41 to your computer and use it in GitHub Desktop.
//https://github.com/tqk2811/FFmpegArgs
FFmpegArg ffmpegArg = new FFmpegArg();
var colorInput = new FilterGraphInput();
colorInput.FilterGraph.ColorFilter().Size(new Size(width,height)).Color(Color.Transparent);
var colorVideo = ffmpegArg.AddVideoInput(colorInput,1,0);
var colorMap = colorVideo.ImageMaps.First();
List<ImageMap> maps = new List<ImageMap>();
foreach(var input in inputs)
{
var videoMap = ffmpegArg.AddVideoInput(new VideoFileInput(input.FileName),1,0);
var imageMap = videoMap.ImageMaps.First().
.ScaleFilter()//scale save ratio
.W($"if(gte(iw/ih,{width}/{height}),min(iw,{width}),-1)")
.H($"if(gte(iw/ih,{width}/{height}),-1,min(ih,{height}))").MapOut
.SetSarFilter().Ratio("1/1").MapOut
.OverlayFilterOn(colorMap)
.X("(main_w - overlay_w)/2")
.Y("(main_h-overlay_h)/2")
.EofAction(EofAction.EndAll).MapOut//center
maps.Add(imageMap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment