从 Azure Functions 调用 ExifTool

问题描述 投票:0回答:1

我正在使用 ExifTool 从 .NET 8 azure 函数应用程序更新图像元数据。我正在通过 NExifTool 包装器库执行 exe 文件。它工作正常,但有时需要超过 30 秒才能完成正常执行时间约为 2-3 秒的任务。当有一批更新(例如 40 个文件)时,它会按预期处理 37 个文件,并使我们等待 40-50 秒来处理最后一个文件。对于单次执行或保持唤醒调用也会发生这种情况(不是每次,但会发生 5-6 次)。

我使用 Windows Stand-Alone Executable 版本,因为无法安装 PERL。会不会和perl运行时有关?

如有任何帮助,我们将不胜感激。

var updates = new List<Operation>();


// list of set operations   
updates.Add(new SetOperation(new Tag("CopyrightNotice", "2024 Company")));


stream.Seek(0, SeekOrigin.Begin);
var writeResult = await _exifTool.WriteTagsAsync(stream, updates, cancellationToken);

azure-functions exiftool
1个回答
0
投票

要将 ExifTool 功能集成到 Azure Function 中以更新图像元数据,ExifTool 可执行文件 (

exiftool.exe
) 必须包含在 Azure Function 中。

下面的代码与

exiftool.exe
交互,我使用了来自 git 的示例示例。

     const string c_exeName = "exiftool.exe";
        const string c_arguments = @"-stay_open 1 -@ - -common_args -charset UTF8 -G1 -args";
        const string c_exitCommand = "-stay_open\n0\n-execute\n";
        const int c_timeout = 30000;    // in milliseconds
        const int c_exitTimeout = 15000;

        static Encoding s_Utf8NoBOM = new UTF8Encoding(false);

        Process m_exifTool;
        StreamWriter m_in;
        StreamReader m_out;

        public ExifTool()
        {
            // Prepare process start
            var psi = new ProcessStartInfo(c_exeName, c_arguments);
            psi.UseShellExecute = false;
            psi.CreateNoWindow = true;
            psi.RedirectStandardInput = true;
            psi.RedirectStandardOutput = true;
            psi.StandardOutputEncoding = s_Utf8NoBOM;

            try
            {
                m_exifTool = Process.Start(psi);
                if (m_exifTool == null || m_exifTool.HasExited)
                {
                    throw new ApplicationException("Failed to launch ExifTool!");
                }
            }
            catch (System.ComponentModel.Win32Exception err)
            {
                throw new ApplicationException("Failed to load ExifTool. 'ExifTool.exe' should be located in the same directory as the application or on the path.", err);
            }

            // ProcessStartInfo in .NET Framework doesn't have a StandardInputEncoding property (though it does in .NET Core)
            // So, we have to wrap it this way.
            m_in = new StreamWriter(m_exifTool.StandardInput.BaseStream, s_Utf8NoBOM);
            m_out = m_exifTool.StandardOutput;
        }

        public void GetProperties(string filename, ICollection<KeyValuePair<string, string>> propsRead)
        {
            LogMessage(filename);
            m_in.Write(filename);
            m_in.Write("\n-execute\n");
            m_in.Flush();

            for (; ; )
            {
                var line = m_out.ReadLine();
                if (line.StartsWith("{ready")) break;
                if (line[0] == '-')
                {
                    int eq = line.IndexOf('=');
                    if (eq > 1)
                    {
                        string key = line.Substring(1, eq - 1);
                        string value = line.Substring(eq + 1).Trim();
                        propsRead.Add(new KeyValuePair<string, string>(key, value));
                    }
                }
            

enter image description here

有关嵌入 Perl 解释器,请参阅此 so

请参阅此链接到如何在 C#

中运行 PERL 脚本
© www.soinside.com 2019 - 2024. All rights reserved.