Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext context)
        {
            Process ps = null;

            if (!DisableActivity.Get(context))
            {
                FFmpegArgument arguments = new FFmpegArgument();
                arguments.FFmpegFilePath    = FFmpegFilePath.Get(context);
                arguments.OutputFileName    = OutputFileName.Get(context);
                arguments.VideoCodec        = VideoCodec.Get(context);
                arguments.PixelFormat       = PixelFormat.Get(context);
                arguments.ExtraOptionString = ExtraOptionString.Get(context);
                arguments.MaxDuration       = MaxDuration.Get(context);
                arguments.MaxFileSize       = MaxFileSize.Get(context);
                arguments.FrameRate         = FrameRate.Get(context);

                ps = StartRecording.Start(arguments, DelayAfter.Get(context));
            }

            FFmpegProcess.Set(context, ps);
        }
Exemplo n.º 2
0
        protected override void Execute(NativeActivityContext context)
        {
            if (!IsActivityDisable.Get(context))
            {
                FFmpegArgument arguments = new FFmpegArgument();
                arguments.FFmpegFilePath    = FFmpegFilePath.Get(context);
                arguments.OutputFileName    = OutputFileName.Get(context);
                arguments.VideoCodec        = VideoCodec.Get(context);
                arguments.PixelFormat       = PixelFormat.Get(context);
                arguments.ExtraOptionString = ExtraOptionString.Get(context);
                arguments.MaxDuration       = MaxDuration.Get(context);
                arguments.MaxFileSize       = MaxFileSize.Get(context);
                arguments.FrameRate         = FrameRate.Get(context);


                ps = StartRecording.Start(arguments, DelayAfter.Get(context));
            }

            if (Body != null)
            {
                context.ScheduleAction(Body, OnCompleted, OnFaulted);
            }
        }
Exemplo n.º 3
0
        public static Process Start(FFmpegArgument ffmpegArgument, int intDelayAfter)
        {
            Process ps = null;

            #region BuildArgument
            string strArgument = BASE_ARGUMENT;

            //Video Codec:   -vcodec option;
            string strVideoCodec = ffmpegArgument.VideoCodec;
            if (String.IsNullOrEmpty(strVideoCodec))
            {
                strVideoCodec = DEFAULT_VIDEO_CODEC;
            }
            strArgument += " -vcodec " + strVideoCodec;



            //Pixel Format:   -pix_fmt option;
            string strPixelFormat = ffmpegArgument.PixelFormat;
            if (String.IsNullOrEmpty(strPixelFormat))
            {
                strPixelFormat = DEFAULT_PIXEL_FORMAT;
            }
            strArgument += " -pix_fmt " + strPixelFormat;



            //Max Durtion:   -t option;
            int intMaxDuration = ffmpegArgument.MaxDuration;
            if (intMaxDuration == 0)
            {
                intMaxDuration = DEFAULT_MAX_DURATION;
            }
            strArgument += " -t " + intMaxDuration.ToString();



            //Max Filesize:  -fs option
            long longMaxFileSize = ffmpegArgument.MaxFileSize;
            if (longMaxFileSize == 0)
            {
                longMaxFileSize = DEFAULT_MAX_FILE_SIZE_MB;
            }
            strArgument += (" -fs " + (longMaxFileSize << 20).ToString()); // Mbyte to byte



            //Framerate: -framerate option
            int intFrameRate = ffmpegArgument.FrameRate;
            if (intFrameRate > 60 || intFrameRate < 1)
            {
                intFrameRate = DEFAULT_FPS;
            }
            strArgument += " -framerate " + intFrameRate.ToString();


            //Extra Options and Video File Name

            strArgument += " " + ffmpegArgument.ExtraOptionString;

            //Extra Options and Video File Name
            string strOutputVideoFileName = "\"" + ffmpegArgument.OutputFileName + "\"";
            strArgument += " " + strOutputVideoFileName;

            #endregion



            //Delete Video file if already exist.
            if (System.IO.File.Exists(ffmpegArgument.OutputFileName))
            {
                System.IO.File.Delete(ffmpegArgument.OutputFileName);
            }

            //Append "ffmpeg.exe" if the argument does not end with it.
            string strFFmpegFilePath = ffmpegArgument.FFmpegFilePath;
            if (!strFFmpegFilePath.EndsWith(FFMPEG_EXE_NAME))
            {
                strFFmpegFilePath = System.IO.Path.Combine(strFFmpegFilePath, FFMPEG_EXE_NAME);
            }

            #region Run FFmpeg
            //Check ffmpeg.exe
            if (System.IO.File.Exists(strFFmpegFilePath))
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName  = strFFmpegFilePath;
                psi.Arguments = strArgument;

                psi.CreateNoWindow  = false;
                psi.UseShellExecute = true;
                psi.WindowStyle     = ProcessWindowStyle.Minimized;

                ps = Process.Start(psi);

                System.Threading.Thread.Sleep(intDelayAfter);

                //Check if ffmpeg is normaly running.
                if (ps.HasExited)
                {
                    throw (new Exception(MSG_FFMPEG_FAILED_TO_START));
                }
            }
            else
            {
                throw new System.IO.FileNotFoundException(MSG_FFMPEG_NOT_FOUND_EXCEPTION);
            }
            #endregion

            return(ps);
        }