Skip to content

Commit

Permalink
Merge pull request #11 from valery-kirichenko/develop
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
valery-kirichenko authored Feb 5, 2021
2 parents 45069b4 + 602548c commit 2d223e7
Show file tree
Hide file tree
Showing 38 changed files with 684 additions and 957 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,4 @@ healthchecksdb
MigrationBackup/

# End of https://www.gitignore.io/api/visualstudio
.idea/
31 changes: 0 additions & 31 deletions ClipChopper.sln

This file was deleted.

6 changes: 0 additions & 6 deletions ClipChopper/App.config

This file was deleted.

File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions ClipChopper/Applications/ClipChopper.DesktopApp/AudioTrack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ClipChopper.DesktopApp
{
public sealed class AudioTrack
{
public string Name { get; set; } = string.Empty;
public int StreamIndex { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop" ToolsVersion="Current">
<PropertyGroup Label="Globals">
<Platforms>x64</Platforms>
<PackageVersion>1.1.0</PackageVersion>
<Company>Kirichenko Valery</Company>
<Product>ClipChopper</Product>
<AssemblyVersion>1.1.0</AssemblyVersion>
<AssemblyName>ClipChopper</AssemblyName>
<PackageId>ClipChopper</PackageId>
<Authors>Kirichenko Valery</Authors>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8600,CS8602,CS8603,CS8618,CS8625</WarningsAsErrors>
<RootNamespace>ClipChopper</RootNamespace>
<ApplicationIcon>icon.ico</ApplicationIcon>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Content Include="exiftool.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\avcodec-58.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\avdevice-58.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\avfilter-7.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\avformat-58.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\avutil-56.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\ffmpeg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\ffplay.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\ffprobe.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\postproc-55.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\swresample-3.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ffmpeg\swscale-5.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FFME.Windows" Version="4.2.330" />
<PackageReference Include="NExifTool" Version="0.9.0" />
<PackageReference Include="Ookii.Dialogs.Wpf.NETCore" Version="2.0.0" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions ClipChopper/Applications/ClipChopper.DesktopApp/DirectoryItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ClipChopper.DesktopApp
{
public sealed class DirectoryItem
{
public string Name { get; set; }
public string Path { get; set; }

public DirectoryItem(string name, string path)
{
Name = name;
Path = path;
}

public DirectoryItem(string path)
{
Name = System.IO.Path.GetFileName(path);
Path = path;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace ClipChopper.DesktopApp
{
// TODO: use Prism.WPF BindableBase.
public sealed class FragmentSelection : INotifyPropertyChanged
{
private TimeSpan _start;
private TimeSpan _stop;
private TimeSpan _duration;

public event PropertyChangedEventHandler? PropertyChanged;

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public FragmentSelection(TimeSpan duration)
{
Duration = duration;
Start = TimeSpan.Zero;
Stop = duration;
}

public TimeSpan Start
{
get => _start;

set
{
if (value != _start)
{
_start = value;
NotifyPropertyChanged();

if (Stop <= Start)
{
Stop = Duration;
}
}
}
}

public TimeSpan Stop
{
get => _stop;

set
{
if (value != _stop)
{
_stop = value;
NotifyPropertyChanged();

if (Start >= value)
{
Start = TimeSpan.Zero;
}
}
}
}

private TimeSpan Duration
{
get => _duration;
set
{
_duration = value;
if (Stop > value)
{
Stop = value;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,42 @@

namespace ClipChopper
{
static class KeyframeProber
internal static class KeyframeProber
{
public static TimeSpan FindClosestKeyframeTime(string filePath, TimeSpan time)
{
var ffprobePath = Unosquare.FFME.Library.FFmpegDirectory + @"\ffprobe.exe";
var keyframe = TimeSpan.Zero;


string args = $"-threads {Environment.ProcessorCount} -select_streams v -skip_frame nokey " +
$"-show_frames -print_format csv " +
$"-show_entries frame=key_frame,pkt_dts_time \"{filePath}\"";

var startInfo = new ProcessStartInfo()
{
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = ffprobePath,
Arguments = String.Format("-threads {0} -select_streams v -show_frames -print_format csv -show_entries frame=key_frame,pkt_dts_time \"{1}\"", Environment.ProcessorCount, filePath)
Arguments = args
};

using (var probe = Process.Start(startInfo))
{
probe.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
Debug.Assert(probe != null, nameof(probe) + " != null");
probe.OutputDataReceived += (s, e) =>
{
if (e.Data == null) return;
if (e.Data is null) return;

var data = e.Data.Split(',');
var splitted_time = data[2].Split('.');
TimeSpan frame = TimeSpan.FromSeconds(Int32.Parse(splitted_time[0])) + TimeSpan.ParseExact(splitted_time[1], "ffffff", System.Globalization.CultureInfo.InvariantCulture);
var splittedTime = data[2].Split('.');

// TODO: move this logic to new function.
TimeSpan frame = TimeSpan.FromSeconds(
int.Parse(splittedTime[0])) + TimeSpan.ParseExact(splittedTime[1],
"ffffff", System.Globalization.CultureInfo.InvariantCulture
);

if (data[1] == "1")
{
Expand All @@ -40,7 +51,7 @@ public static TimeSpan FindClosestKeyframeTime(string filePath, TimeSpan time)
keyframe = frame;
}
}
});
};
probe.BeginOutputReadLine();
probe.WaitForExit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="ClipChopper.MainWindow"
<Window x:Class="ClipChopper.DesktopApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -7,11 +7,12 @@
xmlns:local="clr-namespace:ClipChopper"
mc:Ignorable="d"
x:Name="CurrentWindow"
Title="Clip Chopper" Height="870" Width="1491" WindowStartupLocation="CenterScreen">
Title="Clip Chopper"
Height="870"
Width="1491"
WindowStartupLocation="CenterScreen">
<!--1491x870 to get 720p video preview-->
<Window.Resources>
<Path x:Key="PlayIcon" Width="20.5832" Height="31.6667" Canvas.Left="30.0833" Canvas.Top="22.1667" Stretch="Fill" Fill="#FF000000" Data="F1 M 30.0833,22.1667L 50.6665,37.6043L 50.6665,38.7918L 30.0833,53.8333L 30.0833,22.1667 Z "/>
<Path x:Key="PauseIcon" Width="22.1667" Height="28.5" Canvas.Left="26.9167" Canvas.Top="23.75" Stretch="Fill" Fill="#FF000000" Data="F1 M 26.9167,23.75L 33.25,23.75L 33.25,52.25L 26.9167,52.25L 26.9167,23.75 Z M 42.75,23.75L 49.0833,23.75L 49.0833,52.25L 42.75,52.25L 42.75,23.75 Z "/>
<local:TimeSpanToSecondsConverter x:Key="TimeSpanToSecondsConverter" />
<local:TimeSpanFormatter x:Key="TimeSpanFormatter" />
</Window.Resources>
Expand Down Expand Up @@ -72,7 +73,11 @@
<RowDefinition Height="48" />
</Grid.RowDefinitions>

<ffme:MediaElement Grid.Row="0" x:Name="Media" Background="Gray" LoadedBehavior="Manual" UnloadedBehavior="Manual" />
<ffme:MediaElement Grid.Row="0"
x:Name="Media"
Background="Gray"
LoadedBehavior="Manual"
UnloadedBehavior="Manual" />

<Slider Grid.Row="1" VerticalAlignment="Center" Margin="0 5"
x:Name="PositionSlider"
Expand All @@ -96,7 +101,7 @@
</Grid>

<StackPanel Orientation="Horizontal" Grid.Row="3">
<Button Margin="0 5 5 5" Name="play" Click="Play_Click" ToolTip="Play/Pause" RenderTransformOrigin="0.5,0.5">
<Button Margin="0 5 5 5" Click="Play_Click" ToolTip="Play/Pause" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<ScaleTransform ScaleX="-1" />
</Button.RenderTransform>
Expand All @@ -119,7 +124,7 @@
</Rectangle>
</Viewbox>
</Button>
<Button Margin="5" Name="pframe" Click="Pframe_Click" ToolTip="Previous frame">
<Button Margin="5" Click="Pframe_Click" ToolTip="Previous frame">
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
Expand All @@ -138,7 +143,7 @@
</Rectangle>
</Viewbox>
</Button>
<Button Margin="5" Name="nframe" Click="Nframe_Click" ToolTip="Next frame">
<Button Margin="5" Click="Nframe_Click" ToolTip="Next frame">
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
Expand All @@ -157,9 +162,43 @@
</Rectangle>
</Viewbox>
</Button>
<Button Margin="5" Padding="10 0" Name="start" Content="Start" Click="start_Click" />
<Button Margin="5" Padding="10 0" Name="stop" Content="Stop" Click="stop_Click" />
<Button Margin="5 5 0 5" Padding="10 0" Name="save" Content="Save..." Click="save_Click"/>
<Button Margin="5"
Padding="10 0"
x:Name="Start"
Content="Start"
Click="Start_Click" />

<Button Margin="5"
Padding="10 0"
x:Name="Stop"
Content="Stop"
Click="Stop_Click" />

<Button Margin="5 5 0 5"
Padding="10 0"
x:Name="Save"
Content="Save..."
Click="Save_Click"/>

<Slider VerticalAlignment="Center"
ToolTip="Volume"
Margin="5"
Width="100"
IsSnapToTickEnabled="False"
IsMoveToPointEnabled="True"
ValueChanged="Volume_Change"
Minimum="0"
Maximum="1"
Value="1"/>

<ComboBox Margin="5"
ToolTip="Audio Track"
SelectedIndex="0"
ItemsSource="{Binding Path=AudioTracks, Mode=OneWay, RelativeSource={RelativeSource AncestorType=Window}}"
DisplayMemberPath="Name"
x:Name="AudioTrackSlider"
VerticalContentAlignment="Center"
SelectionChanged="ComboBox_SelectionChanged"/>
</StackPanel>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 2d223e7

Please sign in to comment.