public static string BuildArgumentsString(AvOptions options)
        {
            StringBuilder result = new StringBuilder();
            AppendInputFile(result, options);
            AppendSpace(result);
            AppendAudioBitrate(result, options);
            AppendSpace(result);
            AppendFormat(result, options);
            AppendSpace(result);
            AppendVideoCodec(result, options);
            AppendSpace(result);
            AppendVideoBitrate(result, options);
            AppendSpace(result);
            AppendVideoCompression(result, options);
            AppendSpace(result);
            AppendAudioCodec(result, options);
            AppendSpace(result);
            AppendAudioType(result, options);
            AppendSpace(result);
            AppendAudioQuality(result, options);
            AppendSpace(result);
            AppendThreads(result, options);
            AppendSpace(result);
            AppendOverwriteOption(result, options);
            AppendSpace(result);
            AppendOutputFile(result, options);

            return result.ToString();
        }
        private static void AppendOutputFile(StringBuilder argumentString, AvOptions options)
        {
            if (string.IsNullOrEmpty(options.OutputFile))
                throw new ArgumentException("Output file is not defined");

            argumentString.AppendFormat("\"{0}\"", options.OutputFile);
        }
 private string GetExeFileName(AvOptions options)
 {
     return options.VideoOptions != null && options.VideoOptions.VideoCodec.HasValue &&
            options.VideoOptions.VideoCodec.Value == VideoCodecType.VP8
                ? AVConv
                : FFMpeg;
 }
        public void CanBuildArgumentsForMp3Audio()
        {
            AvOptions options = new AvOptions
            {
                VideoOptions = null,
                AudioOptions = new AudioOptions
                {
                    Bitrate = "44100",
                    AudioCodec = AudioCodecType.Mp3
                },
                Format = "mp3",
                InputFile = "test.wav",
                OutputFile = "result.mp3",
                Overwrite = false,
            };

            string arguments = MediaConverterArgumentsBuilder.BuildArgumentsString(options);
            string expectedResult = string.Format("-i \"{0}\" -ar 44100 -f mp3 -c:a libmp3lame -threads 2 \"{1}\"", options.InputFile, options.OutputFile);
            Assert.True(arguments == expectedResult);
        }
        public void CanBuildArgumentsForH254Video()
        {
            AvOptions options = new AvOptions
            {
                AudioOptions = new AudioOptions
                {
                    Bitrate = "44100",
                },
                VideoOptions = new VideoOptions
                {
                    Bitrate = "1000k",
                    VideoCodec = VideoCodecType.H254
                },
                InputFile = "movie.avi",
                OutputFile = "movie.mp4",
                Overwrite = false,
            };

            string arguments = MediaConverterArgumentsBuilder.BuildArgumentsString(options);
            string expectedResult = string.Format("-i \"{0}\" -ar 44100 -c:v libx264 -vb 1000k -threads 2 \"{1}\"", options.InputFile, options.OutputFile);
            Assert.True(arguments == expectedResult);
        }
 private static void AppendThreads(StringBuilder argumentString, AvOptions options)
 {
     argumentString.AppendFormat("-threads {0}", options.Threads);
 }
 private static void AppendOverwriteOption(StringBuilder argumentString, AvOptions options)
 {
     if (options.Overwrite)
         argumentString.Append("-y");
 }
 private static void AppendFormat(StringBuilder argumentString, AvOptions options)
 {
     if (!string.IsNullOrEmpty(options.Format))
         argumentString.AppendFormat("-f {0}", options.Format);
 }
 private static void AppendAudioType(StringBuilder argumentString, AvOptions options)
 {
     if (options.AudioOptions != null && options.AudioOptions.Audio.HasValue)
         argumentString.AppendFormat("-ac {0}", (int)options.AudioOptions.Audio);
 }
 private static void AppendAudioQuality(StringBuilder argumentString, AvOptions options)
 {
     if (options.AudioOptions != null && options.AudioOptions.AudioQuality.HasValue)
         argumentString.AppendFormat("-aq {0}", (int)options.AudioOptions.AudioQuality.Value);
 }
 private static void AppendAudioBitrate(StringBuilder argumentString, AvOptions options)
 {
     if (!string.IsNullOrEmpty(options.AudioOptions.Bitrate))
         argumentString.AppendFormat("-ar {0}", options.AudioOptions.Bitrate);
 }
 private static void AppendVideoCompression(StringBuilder argumentString, AvOptions options)
 {
     if (options.VideoOptions != null && options.VideoOptions.VideoCompression.HasValue)
         argumentString.AppendFormat("-qmax {0}", (int)options.VideoOptions.VideoCompression.Value);
 }
 private static void AppendVideoCodec(StringBuilder argumentString, AvOptions options)
 {
     if (options.VideoOptions != null && options.VideoOptions.VideoCodec.HasValue)
         argumentString.AppendFormat("-c:v {0}", EnumUtils.GetDescription(options.VideoOptions.VideoCodec.Value));
 }
 private static void AppendVideoBitrate(StringBuilder argumentString, AvOptions options)
 {
     if (options.VideoOptions != null && !string.IsNullOrEmpty(options.VideoOptions.Bitrate))
         argumentString.AppendFormat("-vb {0}", options.VideoOptions.Bitrate);
 }
        public Task<string> Convert(AvOptions options)
        {
            string fileName = GetExeFileName(options);

            return Run(MediaConverterArgumentsBuilder.BuildArgumentsString(options), fileName);
        }
 private static void AppendAudioCodec(StringBuilder argumentString, AvOptions options)
 {
     if (options.AudioOptions.AudioCodec.HasValue)
         argumentString.AppendFormat("-c:a {0}", EnumUtils.GetDescription(options.AudioOptions.AudioCodec.Value));
 }
        public void CanBuildArgumentsForOggVideo()
        {
            AvOptions options = new AvOptions
            {
                AudioOptions = new AudioOptions
                {
                    AudioCodec = AudioCodecType.Ogg,
                    Bitrate = "44100",
                },
                VideoOptions = new VideoOptions
                {
                    Bitrate = "1000k",
                    VideoCodec = VideoCodecType.Theora
                },
                InputFile = "movie.avi",
                OutputFile = "movie.mp4"
            };

            string arguments = MediaConverterArgumentsBuilder.BuildArgumentsString(options);

            string expectedResult = string.Format("-i \"{0}\" -ar 44100 -c:v libtheora -vb 1000k -c:a libvorbis -threads 2 -y \"{1}\"", options.InputFile, options.OutputFile);
            Assert.True(arguments == expectedResult);
        }