mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 23:09:31 -06:00
fixing bitrate percentage
This commit is contained in:
@@ -37,10 +37,15 @@
|
||||
set => _InputFiles = value ?? new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the video information for this video file
|
||||
/// </summary>
|
||||
public VideoInfo VideoInfo { get; set; }
|
||||
|
||||
internal static FfmpegModel CreateModel(VideoInfo info)
|
||||
{
|
||||
var model = new FfmpegModel();
|
||||
model.VideoInfo = info;
|
||||
model.InputFiles.Add(info.FileName);
|
||||
foreach (var item in info.VideoStreams.Select((stream, index) => (stream, index)))
|
||||
{
|
||||
|
||||
@@ -30,28 +30,34 @@ public class FfmpegBuilderVideoBitrate : FfmpegBuilderNode
|
||||
args.Logger?.ELog("Minimum birate not set");
|
||||
return -1;
|
||||
}
|
||||
|
||||
float currentBitrate = (int)(video.Stream.Bitrate / 1024f);
|
||||
if(currentBitrate <= 0)
|
||||
if (currentBitrate <= 0 && Model.VideoInfo.Bitrate > 0)
|
||||
currentBitrate = (int)(Model.VideoInfo.Bitrate/ 1024f);
|
||||
if (currentBitrate <= 0)
|
||||
{
|
||||
// need to work it out
|
||||
currentBitrate = (float)(args.WorkingFileSize / video.Stream.Duration.TotalSeconds);
|
||||
currentBitrate = args.WorkingFileSize;
|
||||
//currentBitrate /= 1024f;
|
||||
currentBitrate = (float)(currentBitrate / video.Stream.Duration.TotalSeconds);
|
||||
// rough estimate of 75% of the file is video
|
||||
currentBitrate *= 0.75f;
|
||||
currentBitrate /= 100;
|
||||
}
|
||||
|
||||
float br = Bitrate;
|
||||
if (Percent)
|
||||
br = currentBitrate * (Bitrate / 100f);
|
||||
|
||||
args.Logger?.ILog($"Source bitrate: {currentBitrate}k");
|
||||
args.Logger?.ILog($"Setting video bitrate to: {br}k");
|
||||
br = (int)Math.Round((double)br, 0);
|
||||
currentBitrate = ((int)Math.Round((double)currentBitrate, 0));
|
||||
int minimum = (int)(br * 0.75f);
|
||||
int maximum = (int)(br * 1.25f);
|
||||
|
||||
args.Logger?.ILog($"Source bitrate: {currentBitrate}k");
|
||||
args.Logger?.ILog($"Setting video bitrate to: {br}k");
|
||||
|
||||
video.AdditionalParameters.AddRange(new[]
|
||||
{
|
||||
"-b:v:{index}", br + "k",
|
||||
"-b:v:{index}", br + "k",
|
||||
"-minrate", minimum + "k",
|
||||
"-maxrate", maximum + "k",
|
||||
"-bufsize", currentBitrate + "k"
|
||||
|
||||
@@ -866,7 +866,8 @@ namespace FileFlows.VideoNodes.Tests.FfmpegBuilderTests
|
||||
ffEncode.Execute(args);
|
||||
|
||||
FfmpegBuilderVideoBitrate ffBitrate = new();
|
||||
ffBitrate.Bitrate = 1_000;
|
||||
ffBitrate.Bitrate = 50;
|
||||
ffBitrate.Percent = true;
|
||||
ffBitrate.Execute(args);
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
@@ -914,6 +915,55 @@ namespace FileFlows.VideoNodes.Tests.FfmpegBuilderTests
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_AddAc3Aac_AV1()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\av1.mkv";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg5\ffmpeg.exe";
|
||||
VideoInfoHelper.ProbeSize = 1000;
|
||||
var vi = new VideoInfoHelper(ffmpeg, logger);
|
||||
var vii = vi.Read(file);
|
||||
var args = new NodeParameters(file, logger, false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
FfmpegBuilderAudioTrackRemover ffAudioRemove = new();
|
||||
ffAudioRemove.RemoveAll = true;
|
||||
ffAudioRemove.Execute(args);
|
||||
|
||||
//FfmpegBuilderAudioAddTrack ffAddAudio = new();
|
||||
//ffAddAudio.Codec = "ac3";
|
||||
//ffAddAudio.Language = "eng";
|
||||
//ffAddAudio.Index = 0;
|
||||
//ffAddAudio.Execute(args);
|
||||
|
||||
FfmpegBuilderAudioAddTrack ffAddAudio2 = new();
|
||||
ffAddAudio2.Codec = "aac";
|
||||
ffAddAudio2.Language = "deu";
|
||||
ffAddAudio2.Index = 1;
|
||||
ffAddAudio2.Execute(args);
|
||||
|
||||
FfmpegBuilderSubtitleFormatRemover ffSubtitle= new();
|
||||
ffSubtitle.RemoveAll = true;
|
||||
ffSubtitle.Execute(args);
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
|
||||
int result = ffExecutor.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user