private async void ButtonCreatePreview_Click(object sender, RoutedEventArgs e)
        {
            if (buttonCreatePreview.Content.ToString() == "Create preview")
            {
                await mediaElementOriginal.Pause();

                blurEffect.Radius             = 10;
                buttonPlayPause.IsEnabled     = false;
                sliderPreview.Visibility      = Visibility.Hidden;
                buttonCreatePreview.Content   = "Cancel";
                textBlockPreviewTimespan.Text = "Cutting original...";
                Storyboard storyboard = FindResource("ProgressAnimationIn") as Storyboard;
                storyboard.Begin();
                Directory.CreateDirectory(Environment.CurrentDirectory + "\\temp");

                double keyFrameBefore = (await mediaFile.GetNearestBeforeAndAfterKeyFrames(start.TotalSeconds)).before;
                start             = TimeSpan.FromSeconds(keyFrameBefore);
                end               = start.Add(TimeSpan.FromSeconds(4));
                conversionOptions = new ConversionOptions(encoder, 6, 16)
                {
                    Start = start,
                    End   = end
                };
                ffmpegEngine.FastCut(mediaFile.Source, Environment.CurrentDirectory + "\\temp\\source.mkv", start.Add(TimeSpan.FromSeconds(0.1)).ToString(@"hh\:mm\:ss\.ff"), end.ToString(@"hh\:mm\:ss\.ff"));
            }
            else
            {
                ButtonClose_Click(null, null);
            }
        }
        private async void ButtonCreatePreview_Click(object sender, RoutedEventArgs e)
        {
            if (buttonCreatePreview.Content.ToString() == "Create preview")
            {
                await mediaElementOriginal.Pause();

                blurEffect.Radius                  = 10;
                buttonPlayPause.IsEnabled          = false;
                sliderPreview.Visibility           = Visibility.Hidden;
                buttonCreatePreview.Content        = "Cancel";
                textBlockPreviewBuildProgress.Text = $"Creating preview ({currentPreview}/{PREVIEW_COUNT})";
                Storyboard storyboard = FindResource("ProgressAnimationIn") as Storyboard;
                storyboard.Begin();
                Directory.CreateDirectory(Environment.CurrentDirectory + "\\temp");

                double keyFrameBefore = (await mediaFile.GetNearestBeforeAndAfterKeyFrames(start.TotalSeconds)).before;
                start                            = TimeSpan.FromSeconds(keyFrameBefore);
                end                              = start.Add(TimeSpan.FromSeconds(4));
                encoder.Preset                   = Preset.VeryFast;
                encoder.Quality                  = Quality.Best;
                conversionOptions                = new ConversionOptions(encoder);
                conversionOptions.SkipAudio      = true;
                conversionOptions.EncodeSections = new TimeIntervalCollection(mediaFile.Duration);
                conversionOptions.EncodeSections.Add(start, end);
                ffmpegEngine.Convert(mediaFile, Environment.CurrentDirectory + "\\temp\\preview_0.mkv", conversionOptions);
            }
            else
            {
                ButtonClose_Click(null, null);
            }
        }
Beispiel #3
0
        private async void UpdateKeyFrameSuggestions(TimeSpan t)
        {
            var(before, after, isKeyFrame) = await mediaInfo.GetNearestBeforeAndAfterKeyFrames(t.TotalSeconds);

            t = TimeSpan.FromSeconds(before == 0 ? 0 : before);
            textBlockStartBefore.Text = t.ToString(@"hh\:mm\:ss\.ff");
            t = TimeSpan.FromSeconds(after);
            textBlockStartAfter.Text = t.ToString(@"hh\:mm\:ss\.ff");
            if (isKeyFrame)
            {
                textBoxStart.Foreground = new BrushConverter().ConvertFromString("#FF109320") as SolidColorBrush;
            }
            else
            {
                textBoxStart.Foreground = new BrushConverter().ConvertFromString("#FFC12222") as SolidColorBrush;
            }
        }
Beispiel #4
0
        public async void Convert(MediaInfo sourceInfo, string destination, ConversionOptions conversionOptions)
        {
            progressData = new ProgressData();

            //Captures the Synchronization Context of the caller, in order to invoke the events on its original thread
            synchronizationContext = SynchronizationContext.Current;

            //Duration
            if (conversionOptions.End != TimeSpan.Zero)
            {
                progressData.TotalTime = conversionOptions.End - conversionOptions.Start;
            }
            else
            {
                progressData.TotalTime = sourceInfo.Duration - conversionOptions.Start;
            }

            //Filters
            string filters = "";

            if (conversionOptions.Resolution.HasValue() || conversionOptions.CropData.HasValue() || conversionOptions.Rotation.HasValue())
            {
                filters = " -vf " + ConcatFilters(conversionOptions.Resolution.FilterString, conversionOptions.CropData.FilterString, conversionOptions.Rotation.FilterString);
            }

            //Get nearest before keyframe
            var keyframes = await sourceInfo.GetNearestBeforeAndAfterKeyFrames(conversionOptions.Start.TotalSeconds).ConfigureAwait(false);

            TimeSpan startTime = TimeSpan.FromSeconds(keyframes.before);

            //FFMpeg command string
            StringBuilder sb = new StringBuilder("-y");

            sb.Append($" -ss {startTime}");
            sb.Append($" -i \"{sourceInfo.Source}\"");
            if (sourceInfo.HasExternalAudio)
            {
                sb.Append($" -ss {startTime}");
                sb.Append($" -i \"{sourceInfo.ExternalAudioSource}\"");
            }
            if (conversionOptions.End != TimeSpan.Zero)
            {
                sb.Append($" -t {conversionOptions.End - conversionOptions.Start}");
            }
            sb.Append($" -map 0:v:0");
            if (!conversionOptions.SkipAudio)
            {
                foreach (var audioTrack in sourceInfo.AudioTracks)
                {
                    if (audioTrack.Enabled)
                    {
                        sb.Append($" -map {(sourceInfo.HasExternalAudio ? "1" : "0")}:{audioTrack.StreamIndex}");
                        sb.Append($" -disposition:{audioTrack.StreamIndex} {(audioTrack.Default ? "default" : "none")}");
                    }
                }
            }
            sb.Append(" -map 0:s?");
            sb.Append(" -movflags faststart -c:v " + conversionOptions.Encoder.GetFFMpegCommand());
            if (conversionOptions.Framerate > 0)
            {
                sb.Append(" -r " + conversionOptions.Framerate);
            }
            sb.Append(filters);
            sb.Append(conversionOptions.SkipAudio ? " -an" : " -c:a copy");
            sb.Append($" -ss {conversionOptions.Start - startTime}");
            sb.Append($" -avoid_negative_ts 1 \"{destination}\" -hide_banner");

            StartConversionProcess(sb.ToString());
        }