Example #1
0
        private static bool ExecuteFFMpegExtraction(MediaSource source, string path, long position, string tempFile)
        {
            var info = new ProcessStartInfo();
            info.Arguments = String.Format("-ss {0} -i \"{1}\" -vframes 1 -vf \"yadif,scale=ih*dar:ih\" -f image2 \"{2}\"", position, path, tempFile);
            info.FileName = Configuration.StreamingProfiles.FFMpegPath;
            info.CreateNoWindow = true;
            info.UseShellExecute = false;
            info.RedirectStandardError = Log.IsEnabled(LogLevel.Trace);
            info.RedirectStandardOutput = Log.IsEnabled(LogLevel.Trace);

            TranscoderProcess proc = new TranscoderProcess();
            proc.StartInfo = info;
            if (source.NeedsImpersonation)
                proc.StartAsUser(Configuration.Services.NetworkImpersonation.Domain, Configuration.Services.NetworkImpersonation.Username, Configuration.Services.NetworkImpersonation.GetPassword());
            else
                proc.Start();

            if (Log.IsEnabled(LogLevel.Trace))
            {
                Log.Trace("ExtractImage: executing path={0} arguments={1}", info.FileName, info.Arguments);
                StreamCopy.AsyncStreamRead(proc.StandardError, l => Log.Trace("ExtractImage: stderr: {0}", l));
                StreamCopy.AsyncStreamRead(proc.StandardOutput, l => Log.Trace("ExtractImage: stdout: {0}", l));
            }
            proc.WaitForExit();

            if (!File.Exists(tempFile))
            {
                Log.Warn("Failed to extract image from {0} with {1} {2}", source.GetDebugName(), info.FileName, info.Arguments);
                return false;
            }

            return true;
        }
Example #2
0
        private bool SpawnTranscoder(bool needsStdin, bool needsStdout)
        {
            ProcessStartInfo start = new ProcessStartInfo(transcoderPath, arguments);
            start.UseShellExecute = false;
            start.RedirectStandardInput = needsStdin;
            start.RedirectStandardOutput = needsStdout || (!DebugOutput && logStream == LogStream.StandardOut && IsLogStreamConnected);
            start.RedirectStandardError = !DebugOutput && logStream == LogStream.StandardError && IsLogStreamConnected;
            start.WindowStyle = DebugOutput ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden;
            start.CreateNoWindow = !DebugOutput;

            StreamLog.Info(context.Identifier, "Encoder: Transcoder configuration dump");
            StreamLog.Info(context.Identifier, "Encoder:   hasStdin {0}, hasStdout {1}, hasStderr {2}", start.RedirectStandardInput, start.RedirectStandardOutput, start.RedirectStandardError);
            StreamLog.Info(context.Identifier, "Encoder:   path {0}", transcoderPath);
            StreamLog.Info(context.Identifier, "Encoder:   arguments {0}", arguments);

            try
            {
                transcoderApplication = new TranscoderProcess();
                transcoderApplication.StartInfo = start;
                if (context.Source.NeedsImpersonation)
                    transcoderApplication.StartAsUser(Configuration.Services.NetworkImpersonation.Domain, Configuration.Services.NetworkImpersonation.Username, Configuration.Services.NetworkImpersonation.GetPassword());
                else
                    transcoderApplication.Start();
            }
            catch (Win32Exception e)
            {
                StreamLog.Error(context.Identifier, "Encoding: Failed to start transcoder", e);
                return false;
            }
            return true;
        }