forked from fifonik/FFBitrateViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileItem.cs
More file actions
157 lines (120 loc) · 5.6 KB
/
FileItem.cs
File metadata and controls
157 lines (120 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using OxyPlot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace FFBitrateViewer
{
public class FileItem : Bindable
{
public BitRate? BitRateAvg { get { return Get<BitRate?>(); } private set { Set(value); } }
public BitRate? BitRateMax { get { return Get<BitRate?>(); } private set { Set(value); } }
public string? FS { // File Spec
get { return Get<string?>(); }
set {
Set(value);
IsExists = !string.IsNullOrEmpty(value) && File.Exists(value);
FN = Path.GetFileName(FS);
}
}
public string? FN { get { return Get<string?>(); } private set { Set(value); } } // File Name
private Frames Frames { get; set; } = new Frames();
public int? FramesCount { get { return Get<int?>(); } private set { Set(value); } }
public int? DropTarget { get { return Get<int?>(); } set { Set(value); } } // 1 -- top, 2 - bottom
public bool IsExists { get { return Get<bool>(); } private set { Set(value); OnPropertyChanged(nameof(IsExistsAndEnabled)); OnPropertyChanged(nameof(IsReady)); } }
public bool IsEnabled { get { return Get<bool>(); } set { Set(value); OnPropertyChanged(nameof(IsExistsAndEnabled)); OnPropertyChanged(nameof(IsReady)); } }
public bool IsExistsAndEnabled { get { return IsExists && IsEnabled; } }
public bool IsMediaInfoLoading { get { return Get<bool>(); } private set { Set(value); } }
public bool IsDataLoading { get { return Get<bool>(); } private set { Set(value); } }
public bool IsReady { get { return IsExists && IsEnabled; } }
public MediaInfo? MediaInfo { get { return Get<MediaInfo>(); } private set { Set(value); OnPropertyChanged(nameof(IsReady)); } }
public FileItem(string? fs = null, bool enabled = true)
{
IsEnabled = enabled;
MediaInfo = null;
if (!string.IsNullOrEmpty(fs)) FS = fs;
}
private void BitRatesCalc()
{
var avg = Frames.BitRateAvgCalc();
BitRateAvg = (avg == null) ? null : new BitRate((int)avg);
var max = Frames.BitRateMaxCalc();
BitRateMax = (max == null) ? null : new BitRate((int)max);
}
public void FramesIsAdjustStartTimeSet(bool isAdjustStartTime) {
if (isAdjustStartTime == Frames.IsAdjustStartTime) return;
Frames.IsAdjustStartTimeSet(isAdjustStartTime);
BitRatesCalc();
}
public void FramesClear()
{
BitRateAvg = null;
BitRateMax = null;
FramesCount = null;
Frames.Clear();
}
public void FramesGet(CancellationToken cancellationToken, Action<int?, Frame>? action = null)
{
if (string.IsNullOrEmpty(FS)) return;
IsDataLoading = true;
FF.FramesGet(FS, cancellationToken, o => {
if (o is Frame frame)
{
var pos = Frames.Add(frame);
action?.Invoke(pos, frame);
}
});
BitRatesCalc();
FramesCount = Frames.Items.Count;
IsDataLoading = false;
}
public List<DataPoint> FramesDataPointsGet(string? plotViewType)
{
return Frames.DataPointsGet(plotViewType);
}
public double? FramesDurationGet()
{
return Frames.DurationGet();
}
public int FramesMaxYGet(string? plotViewType)
{
return Frames.MaxYGet(plotViewType);
}
public int? GetBitRateFromStream()
{
return MediaInfo?.Video0?.BitRate?.Value;
}
public int? GetBitRateFromFile()
{
return MediaInfo?.BitRate?.Value;
}
public double? GetDuration()
{
return Frames.DurationGet() ?? GetDurationFromStream() ?? GetDurationFile();
}
public double? GetDurationFromStream()
{
return (MediaInfo?.Video0?.Duration > 0) ? (MediaInfo.Video0.Duration - (MediaInfo?.Video0?.StartTime ?? 0)) : null;
}
public double? GetDurationFile()
{
return (MediaInfo?.Duration > 0) ? (MediaInfo.Duration - (MediaInfo?.StartTime ?? 0)) : null;
}
public void MediaInfoClear()
{
MediaInfo = null;
}
public void MediaInfoGet()
{
if (!string.IsNullOrEmpty(FS) && IsExists)
{
IsMediaInfoLoading = true;
// Cannot just clear & reload media info as it will not updated in MediaInfoBox
var info = new MediaInfo(FS);
MediaInfo = info;
Frames.StartTime = info.StartTime;
IsMediaInfoLoading = false;
}
}
}
}