added audio track set language node

This commit is contained in:
reven
2021-12-27 11:12:23 +13:00
parent f69e257805
commit 372de640ca
7 changed files with 92 additions and 2 deletions

Binary file not shown.

View File

@@ -58,6 +58,13 @@ namespace FileFlows.BasicNodes.File
else
dest = Path.Combine(dest, new FileInfo(args.FileName).Name);
var fiDest = new FileInfo(dest);
var fiWorking = new FileInfo(args.WorkingFile);
if (string.IsNullOrEmpty(fiDest.Extension) == false && fiDest.Extension != fiWorking.Extension)
{
dest = dest.Substring(0, dest.LastIndexOf(".")) + fiWorking.Extension;
}
var destDir = new FileInfo(dest).DirectoryName;
args.CreateDirectoryIfNotExists(destDir ?? String.Empty);
@@ -67,6 +74,7 @@ namespace FileFlows.BasicNodes.File
dest = Path.Combine(destDir!, destFile);
}
args.Logger?.ILog($"Copying file '{args.WorkingFile}' to '{dest}");
// have to use file streams so we can report progress
int bufferSize = 1024 * 1024;

View File

@@ -45,6 +45,12 @@ namespace FileFlows.BasicNodes.File
else
dest = Path.Combine(dest, new FileInfo(args.FileName).Name);
var fiDest = new FileInfo(dest);
var fiWorking = new FileInfo(args.WorkingFile);
if (string.IsNullOrEmpty(fiDest.Extension) == false && fiDest.Extension != fiWorking.Extension)
{
dest = dest.Substring(0, dest.LastIndexOf(".")) + fiWorking.Extension;
}
if (string.IsNullOrEmpty(DestinationFile) == false)
{
@@ -52,7 +58,7 @@ namespace FileFlows.BasicNodes.File
dest = Path.Combine(new FileInfo(dest).DirectoryName!, destFile);
}
var fiDest = new FileInfo(dest);
fiDest = new FileInfo(dest);
var fiWorkingFile = new FileInfo(args.WorkingFile);
if (fiDest.Extension != fiWorkingFile.Extension)
{

View File

@@ -21,7 +21,7 @@ namespace FileFlows.BasicNodes.Functions
public new int Outputs { get; set; }
[Required]
[DefaultValue("// Variables contain variables available to this node from previous nodes.\n// Logger lets you log messages to the flow output.\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to select which output node will be processed next\n\nif(Variables.FileSize === 0)\n\treturn -1;\n\nreturn 0;")]
[DefaultValue("// Variables contain variables available to this node from previous nodes.\n// Logger lets you log messages to the flow output.\n\n// return 0 to complete the flow.\n// return -1 to signal an error in the flow\n// return 1+ to select which output node will be processed next\n\nif(Variables.file.Size === 0)\n\treturn -1;\n\nreturn 0;")]
[Code(2)]
public string Code { get; set; }

Binary file not shown.

View File

@@ -10,6 +10,14 @@
"Languages-Help": "The order of languages to sort the audio tracks by. This sorting is done before the codec."
}
},
"AudioTrackSetLanguage": {
"Label": "Audio: Set Language",
"Description": "Allows you to set the language for any audio tracks that have no language set. If the audio track does have a language set, it will be skipped.\n\nOutput 1: Audio Tracks were updated\nOutput 2: No audio tracks were needing to be updated",
"Fields": {
"Language": "Language",
"Language-Help": "The ISO 639-2 language code to use. \nhttps://en.wikipedia.org/wiki/List_of_ISO_639-2_codes"
}
},
"VideoFile": {
"Description": "An input video file that has had its VideoInformation read and can be processed"
},

View File

@@ -0,0 +1,68 @@
namespace FileFlows.VideoNodes
{
using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public class AudioTrackSetLanguage : EncodingNode
{
public override int Outputs => 2;
public override string Icon => "fas fa-comment-dots";
[Required]
[Text(1)]
public string Language { get; set; }
public override int Execute(NodeParameters args)
{
try
{
VideoInfo videoInfo = GetVideoInfo(args);
if (videoInfo == null)
return -1;
string ffmpegExe = GetFFMpegExe(args);
if (string.IsNullOrEmpty(ffmpegExe))
return -1;
List<string> ffArgs = new List<string>();
int index = 0;
foreach(var at in videoInfo.AudioStreams)
{
if (string.IsNullOrEmpty(at.Language))
{
ffArgs.Add($"-metadata:s:a:{index} language={Language.ToLower()}");
}
++index;
}
if (ffArgs.Count == 0)
return 2; // nothing to do
ffArgs.Insert(0, $"-map 0 -c copy");
string ffArgsLine = string.Join(" ", ffArgs);
string extension = new FileInfo(args.WorkingFile).Extension;
if(extension.StartsWith("."))
extension = extension.Substring(1);
args.Logger?.DLog("Working file: " + args.WorkingFile);
args.Logger?.DLog("Extension: " + extension);
if (Encode(args, ffmpegExe, ffArgsLine, extension) == false)
return -1;
return 1;
}
catch (Exception ex)
{
args.Logger?.ELog("Failed processing VideoFile: " + ex.Message);
return -1;
}
}
}
}