mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-22 20:58:28 -06:00
updated FFMPEG Builder Audio Tracks reorder to subtitles aswell and rename dit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Emby/Emby.csproj
BIN
Emby/Emby.csproj
Binary file not shown.
BIN
Emby/Plugin.cs
BIN
Emby/Plugin.cs
Binary file not shown.
Binary file not shown.
BIN
Gotify/Plugin.cs
BIN
Gotify/Plugin.cs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Plex/Plex.csproj
BIN
Plex/Plex.csproj
Binary file not shown.
BIN
Plex/Plugin.cs
BIN
Plex/Plugin.cs
Binary file not shown.
@@ -7,41 +7,83 @@ public class FfmpegBuilderAudioTrackReorder : FfmpegBuilderNode
|
||||
{
|
||||
public override int Outputs => 2;
|
||||
|
||||
public override string Icon => "fas fa-volume-off";
|
||||
public override string Icon => "fas fa-sort-alpha-down";
|
||||
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/audio-track-reorder";
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/track-reorder";
|
||||
|
||||
[StringArray(1)]
|
||||
public List<string> Languages { get; set; }
|
||||
|
||||
[Select(nameof(StreamTypeOptions), 1)]
|
||||
public string StreamType { get; set; }
|
||||
|
||||
[StringArray(2)]
|
||||
public List<string> OrderedTracks { get; set; }
|
||||
public List<string> Languages { get; set; }
|
||||
|
||||
[StringArray(3)]
|
||||
public List<string> OrderedTracks { get; set; }
|
||||
|
||||
[StringArray(4)]
|
||||
[ConditionEquals(nameof(StreamType), "Subtitle", inverse: true)]
|
||||
public List<string> Channels { get; set; }
|
||||
|
||||
private static List<ListOption> _StreamTypeOptions;
|
||||
public static List<ListOption> StreamTypeOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StreamTypeOptions == null)
|
||||
{
|
||||
_StreamTypeOptions = new List<ListOption>
|
||||
{
|
||||
new ListOption { Label = "Audio", Value = "Audio" },
|
||||
new ListOption { Label = "Subtitle", Value = "Subtitle" }
|
||||
};
|
||||
}
|
||||
return _StreamTypeOptions;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
OrderedTracks = OrderedTracks?.Select(x => x.ToLower())?.ToList() ?? new();
|
||||
|
||||
var reordered = Reorder(Model.AudioStreams);
|
||||
|
||||
bool same = AreSame(Model.AudioStreams, reordered);
|
||||
|
||||
if (same)
|
||||
if (StreamType == "Subtitle")
|
||||
{
|
||||
args.Logger?.ILog("No audio tracks need reordering");
|
||||
return 2;
|
||||
var reordered = Reorder(Model.SubtitleStreams);
|
||||
|
||||
bool same = AreSame(Model.SubtitleStreams, reordered);
|
||||
|
||||
if (same)
|
||||
{
|
||||
args.Logger?.ILog("No subtitle tracks need reordering");
|
||||
return 2;
|
||||
}
|
||||
|
||||
Model.SubtitleStreams = reordered;
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var reordered = Reorder(Model.AudioStreams);
|
||||
|
||||
Model.AudioStreams = reordered;
|
||||
// set the first audio track as the default track
|
||||
Model.MetadataParameters.AddRange(new[] { "-disposition:a:0", "default" });
|
||||
bool same = AreSame(Model.AudioStreams, reordered);
|
||||
|
||||
return 1;
|
||||
if (same)
|
||||
{
|
||||
args.Logger?.ILog("No audio tracks need reordering");
|
||||
return 2;
|
||||
}
|
||||
|
||||
Model.AudioStreams = reordered;
|
||||
// set the first audio track as the default track
|
||||
Model.MetadataParameters.AddRange(new[] { "-disposition:a:0", "default" });
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public List<FfmpegAudioStream> Reorder(List<FfmpegAudioStream> input)
|
||||
public List<T> Reorder<T>(List<T> input) where T : FfmpegStream
|
||||
{
|
||||
Languages ??= new List<string>();
|
||||
OrderedTracks ??= new List<string>();
|
||||
@@ -65,9 +107,21 @@ public class FfmpegBuilderAudioTrackReorder : FfmpegBuilderNode
|
||||
var debug = new StringBuilder();
|
||||
var data = input.OrderBy(x =>
|
||||
{
|
||||
int langIndex = Languages.IndexOf(x.Stream.Language?.ToLower() ?? String.Empty);
|
||||
int codecIndex = OrderedTracks.IndexOf(x.Stream.Codec?.ToLower() ?? String.Empty);
|
||||
int channelIndex = actualChannels.IndexOf(x.Stream.Channels);
|
||||
int langIndex = 0;
|
||||
int codecIndex = 0;
|
||||
int channelIndex = 0;
|
||||
|
||||
if (x is FfmpegAudioStream audioStream)
|
||||
{
|
||||
langIndex = Languages.IndexOf(audioStream.Stream.Language?.ToLower() ?? String.Empty);
|
||||
codecIndex = OrderedTracks.IndexOf(audioStream.Stream.Codec?.ToLower() ?? String.Empty);
|
||||
channelIndex = actualChannels.IndexOf(audioStream.Stream.Channels);
|
||||
}
|
||||
else if (x is FfmpegSubtitleStream subStream)
|
||||
{
|
||||
langIndex = Languages.IndexOf(subStream.Stream.Language?.ToLower() ?? String.Empty);
|
||||
codecIndex = OrderedTracks.IndexOf(subStream.Stream.Codec?.ToLower() ?? String.Empty);
|
||||
}
|
||||
|
||||
int result = base_number;
|
||||
if (langIndex >= 0)
|
||||
@@ -89,7 +143,7 @@ public class FfmpegBuilderAudioTrackReorder : FfmpegBuilderNode
|
||||
|
||||
return data;
|
||||
}
|
||||
public bool AreSame(List<FfmpegAudioStream> original, List<FfmpegAudioStream> reordered)
|
||||
public bool AreSame<T>(List<T> original, List<T> reordered) where T: FfmpegStream
|
||||
{
|
||||
for (int i = 0; i < reordered.Count; i++)
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
#if(DEBUG)
|
||||
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using VideoNodes.Tests;
|
||||
|
||||
@@ -592,14 +593,17 @@ public class FfmpegBuilder_BasicTests
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
FfmpegBuilderAudioTrackReorder ffAudioReorder= new();
|
||||
ffAudioReorder.Channels = new List<string> { "1.0", "5.1", "2.0" };
|
||||
ffAudioReorder.Languages = new List<string> { "fre", "deu" };
|
||||
ffAudioReorder.PreExecute(args);
|
||||
ffAudioReorder.Execute(args);
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
ffExecutor.PreExecute(args);
|
||||
int result = ffExecutor.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
@@ -607,6 +611,36 @@ public class FfmpegBuilder_BasicTests
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_SubtitleTrackReorder()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\movtext.mp4";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
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();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
var model = (FfmpegModel)args.Variables["FFMPEG_BUILDER_MODEL"];
|
||||
|
||||
Assert.AreNotEqual("eng", model.SubtitleStreams[0].Language);
|
||||
|
||||
FfmpegBuilderAudioTrackReorder ffAudioReorder = new();
|
||||
ffAudioReorder.StreamType = "Subtitle";
|
||||
ffAudioReorder.Languages = new List<string> { "eng", "deu" };
|
||||
ffAudioReorder.PreExecute(args);
|
||||
ffAudioReorder.Execute(args);
|
||||
|
||||
Assert.AreEqual("eng", model.SubtitleStreams[0].Language);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_AddAc3AacMp4NoSubs_BlackBars_Normalize_AutoChapters_Upscale4k()
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -70,7 +70,7 @@
|
||||
"1": "Audio tracks re-ordered in new temporary file",
|
||||
"2": "Audio tracks NOT re-ordered"
|
||||
},
|
||||
"Description": "Allows you to reorder audio tracks in the preferred order.\n\nEnter the languages/audio codecs/channels in the order you want. Any not listed will be ordered after the ones entered in their original order.\nIf there are multiple tracks with same language/codec/channels, they will be ordered first by the order you entered, then in their original order.\n\nOutput 1: Audio tracks were reordered\nOutput 2: Audio tracks did not need reordering",
|
||||
"Description": "Allows you to reorder audio tracks in the preferred order.\n\nEnter the languages/audio codecs/channels in the order you want. Any not listed will be ordered after the ones entered in their original order.\nIf there are multiple tracks with same language/codec/channels, they will be ordered first by the order you entered, then in their original order.\n\nOutput 1: Tracks were reordered\nOutput 2: Tracks did not need reordering",
|
||||
"Fields": {
|
||||
"OrderedTracks": "Ordered Audio Codecs",
|
||||
"OrderedTracks-Help": "The order of audio codecs to the audio tracks by. This is done after the languages (if any)",
|
||||
@@ -274,17 +274,19 @@
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderAudioTrackReorder": {
|
||||
"Label": "FFMPEG Builder: Audio Track Reorder",
|
||||
"Label": "FFMPEG Builder: Track Reorder",
|
||||
"Outputs": {
|
||||
"1": "Audio tracks re-ordered in FFMPEG Builder",
|
||||
"2": "Audio tracks NOT re-ordered"
|
||||
"1": "Tracks re-ordered in FFMPEG Builder",
|
||||
"2": "Tracks NOT re-ordered"
|
||||
},
|
||||
"Description": "Allows you to reorder audio tracks in the preferred order.\n\nEnter the languages/audio codecs/channels in the order you want. Any not listed will be ordered after the ones entered in their original order.\nIf there are multiple tracks with same language/codec/channels, they will be ordered first by the order you entered, then in their original order.\n\nOutput 1: Audio tracks were reordered\nOutput 2: Audio tracks did not need reordering",
|
||||
"Description": "Allows you to reorder tracks in the preferred order.\n\nEnter the languages/audio codecs/channels in the order you want. Any not listed will be ordered after the ones entered in their original order.\nIf there are multiple tracks with same language/codec/channels, they will be ordered first by the order you entered, then in their original order.\n\nOutput 1: Tracks were reordered\nOutput 2: Tracks did not need reordering",
|
||||
"Fields": {
|
||||
"OrderedTracks": "Ordered Audio Codecs",
|
||||
"OrderedTracks-Help": "The order of audio codecs to the audio tracks by. This is done after the languages (if any)",
|
||||
"StreamType": "Type",
|
||||
"StreamType-Help": "The type of tracks to reorder in the FFMPEG Builder",
|
||||
"OrderedTracks": "Ordered Codecs",
|
||||
"OrderedTracks-Help": "The order of codecs to the tracks by. This is done after the languages (if any)",
|
||||
"Languages": "Languages",
|
||||
"Languages-Help": "The order of languages to sort the audio tracks by. This sorting is done before the codec.",
|
||||
"Languages-Help": "The order of languages to sort the tracks by. This sorting is done before the codec.",
|
||||
"Channels": "Channels",
|
||||
"Channels-Help": "The order of audio channels to sort the audio tracks by. This sorting is done before languages.\nFor example \"5.1\",\"7.1\",\"6.2\",\"2\""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user