-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.pas
4744 lines (4267 loc) · 148 KB
/
Main.pas
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Main;
{$I Information.inc}
// basic review and reformatting: up to line 2969
interface
uses
// Delphi
Winapi.Windows, Winapi.Messages, Winapi.ShellAPI, Winapi.ActiveX, Winapi.DirectShow9, Winapi.WMF9,
System.SysUtils, System.DateUtils, System.Variants, System.Classes, System.IniFiles, System.Math, System.Actions,
System.StrUtils, System.ImageList, System.Win.Registry, System.Win.ComObj,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.OleCtrls, Vcl.StdCtrls, Vcl.Buttons,
Vcl.ExtCtrls, Vcl.Menus, Vcl.ToolWin, Vcl.ActnList, Vcl.ImgList, Vcl.Clipbrd,
// Indy
IdComponent, IdThreadComponent, IdBaseComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdReplyRFC,
IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL,
// DSPack
DSPack, DXSUtils, Unit_DSTrackBarEx,
// Jedi
JclSimpleXml, JvDialogs, JvComponentBase, JvAppCommand, JvBaseDlg, JvProgressDialog, JvExStdCtrls, JvCheckBox,
JvSpeedbar, JvExExtCtrls, JvExtComponent, JvGIF, JvSimpleXml, JclDebug, JvDesktopAlert,
// CA
CodecSettings, CutlistInfo_dialog, ManageFilters, Movie, Settings_dialog, TrackBarEx, UCutlist, UploadList, Utils;
const
// Registry Keys
CutlistID = 'CutAssistant.Cutlist';
CUTLIST_CONTENT_TYPE = 'text/plain';
ProgID = 'Cut_Assistant.exe';
ShellEditKey = 'CutAssistant.edit';
type
TFMain = class(TForm)
cmdStop: TButton;
cmdPlayPause: TButton;
lvCutlist: TListView;
cmdAddCut: TButton;
cmdDeleteCut: TButton;
edtFrom: TEdit;
edtDuration: TEdit;
edtTo: TEdit;
lblCutFrom: TLabel;
lblCutDuration: TLabel;
lblCutTo: TLabel;
cmdSetFrom: TButton;
cmdSetTo: TButton;
cmdFromStart: TButton;
cmdToEnd: TButton;
cmdJumpFrom: TButton;
cmdJumpTo: TButton;
cmdReplaceCut: TButton;
cmdEditCut: TButton;
rgCutMode: TRadioGroup;
cmdPrev12: TButton;
cmdStepBack: TButton;
cmdStepForwards: TButton;
tbVolume: TTrackBar;
lblVolume: TLabel;
lblPos_nl: TLabel;
cmdNext12: TButton;
tbFinePos: TtrackBarEx;
lblMinFinepos_nl: TLabel;
lblMaxFinepos_nl: TLabel;
lblDuration_nl: TLabel;
bvCutilistInfo: TBevel;
bvMovieControl: TBevel;
odCutlist: TOpenDialog;
VideoWindow: TVideoWindow;
lblFinePos_nl: TLabel;
tbFilePos: TDSTrackBarEx;
SampleGrabber: TSampleGrabber;
TeeFilter: TFilter;
NullRenderer: TFilter;
lblStartPosition_nl: TLabel;
pnlVideoWindow: TPanel;
cmd12FromTo: TButton;
cmdConvert: TButton;
actOpenMovie: TAction;
actOpenCutlist: TAction;
actFileExit: TAction;
ImageList: TImageList;
actSaveCutlistAs: TAction;
actAddCut: TAction;
actReplaceCut: TAction;
actEditCut: TAction;
actDeleteCut: TAction;
actShowFramesForm: TAction;
actNextFrames: TAction;
actPrevFrames: TAction;
actScanInterval: TAction;
actStartCutting: TAction;
actEditSettings: TAction;
actMovieMetaData: TAction;
actAbout: TAction;
actUsedFilters: TAction;
actWriteToRegisty: TAction;
actRemoveRegistryEntries: TAction;
actCutlistUpload: TAction;
WebRequest_nl: TIdHTTP;
actStepForward: TAction;
actStepBackward: TAction;
actBrowseWWWHelp: TAction;
actOpenCutlistHome: TAction;
actRepairMovie: TAction;
cmdCutlistInfo: TBitBtn;
actCutlistInfo: TAction;
ICutlistWarning: TImage;
actSaveCutlist: TAction;
actCalculateResultingTimes: TAction;
actAsfbinInfo: TAction;
pnlAuthor: TPanel;
lblCutlistAuthor_nl: TLabel;
actSearchCutlistByFileSize: TAction;
actSendRating: TAction;
actDeleteCutlistFromServer: TAction;
lblTotalCutoff_nl: TLabel;
lblResultingDuration_nl: TLabel;
tbRate: TtrackBarEx;
lblRate: TLabel;
lblCurrentRate_nl: TLabel;
lblTrueRate_nl: TLabel;
cmdNextCut: TButton;
cmdPrevCut: TButton;
actNextCut: TAction;
actPrevCut: TAction;
cmdFF: TButton;
FilterGraph: TFilterGraph;
actFullScreen: TAction;
actCloseMovie: TAction;
actSnapshotCopy: TAction;
actSnapshotSave: TAction;
mnuVideo: TPopupMenu;
miVideoCopySnapshottoClipboard_nl: TMenuItem;
miVideoSaveSnapshotas_nl: TMenuItem;
actPlayInMPlayerAndSkip: TAction;
miVideoNextXFrames_nl: TMenuItem;
miVideoPreviousXFrames_nl: TMenuItem;
miN1_nl: TMenuItem;
XMLResponse: TJvSimpleXML;
ActionList: TActionList;
SpeedBar_nl: TJvSpeedBar;
mnuMain: TMainMenu;
miFile: TMenuItem;
miCutlist: TMenuItem;
miEdit: TMenuItem;
miFrames: TMenuItem;
miInfo: TMenuItem;
miOptions: TMenuItem;
miHelp: TMenuItem;
miOpenMovie_nl: TMenuItem;
miStartCutting_nl: TMenuItem;
miPlayMovieinMPlayer_nl: TMenuItem;
miRepairMovie_nl: TMenuItem;
miCloseMovie_nl: TMenuItem;
miN2_nl: TMenuItem;
miExit_nl: TMenuItem;
miOpenCutlist_nl: TMenuItem;
miSearchCutlistsonServer_nl: TMenuItem;
miN3_nl: TMenuItem;
miSaveCutlistAs_nl: TMenuItem;
miSaveCutlist_nl: TMenuItem;
miUploadCutlisttoServer_nl: TMenuItem;
miDeleteCutlistfromServer_nl: TMenuItem;
miN4_nl: TMenuItem;
miCutlistInfo_nl: TMenuItem;
miCheckcutMovie_nl: TMenuItem;
miSendRating_nl: TMenuItem;
miAddnewcut_nl: TMenuItem;
miReplaceselectedcut_nl: TMenuItem;
miEditselectedcut_nl: TMenuItem;
miDeleteselectedcut_nl: TMenuItem;
miShowForm_nl: TMenuItem;
miN5_nl: TMenuItem;
miScanInterval_nl: TMenuItem;
miPreviousXFrames_nl: TMenuItem;
miNextXFrames_nl: TMenuItem;
miMovieMetaData_nl: TMenuItem;
miUsedFilters_nl: TMenuItem;
miCutApplications_nl: TMenuItem;
miSettings_nl: TMenuItem;
miN6_nl: TMenuItem;
miAssociatewithfileextensions_nl: TMenuItem;
miRemoveregistryentries_nl: TMenuItem;
miCutlistHomepage_nl: TMenuItem;
miInternetHelpPages_nl: TMenuItem;
miN7_nl: TMenuItem;
miAbout_nl: TMenuItem;
JvSpeedBarSection1: TJvSpeedBarSection;
JvSpeedItem1: TJvSpeedItem;
JvSpeedItem2: TJvSpeedItem;
JvSpeedItem3: TJvSpeedItem;
JvSpeedItem4: TJvSpeedItem;
JvSpeedItem5: TJvSpeedItem;
JvSpeedItem6: TJvSpeedItem;
JvSpeedItem7: TJvSpeedItem;
JvSpeedItem8: TJvSpeedItem;
JvSpeedItem9: TJvSpeedItem;
JvSpeedItem10: TJvSpeedItem;
JvSpeedItem11: TJvSpeedItem;
JvSpeedItem12: TJvSpeedItem;
JvSpeedItem13: TJvSpeedItem;
JvSpeedItem14: TJvSpeedItem;
JvSpeedItem15: TJvSpeedItem;
actSmallSkipForward: TAction;
actSmallSkipBackward: TAction;
actLargeSkipForward: TAction;
actLargeSkipBackward: TAction;
miNavigation: TMenuItem;
miStepForward_nl: TMenuItem;
miStepBack_nl: TMenuItem;
miN8_nl: TMenuItem;
miSmallSkipForward_nl: TMenuItem;
miSmallSkipBack_nl: TMenuItem;
miN9_nl: TMenuItem;
miLargeSkipForward_nl: TMenuItem;
miLargeSkipBack_nl: TMenuItem;
miN10_nl: TMenuItem;
miNextCut_nl: TMenuItem;
miPrevCut_nl: TMenuItem;
actShowLogging: TAction;
miN13_nl: TMenuItem;
miShowLoggingMessages_nl: TMenuItem;
actTestExceptionHandling: TAction;
miTestExceptionHandling_nl: TMenuItem;
actCheckInfoOnServer: TAction;
miCheckinfoonserver_nl: TMenuItem;
actOpenCutassistantHome: TAction;
miCutAssistantProject_nl: TMenuItem;
dlgRequestProgress: TJvProgressDialog;
RequestWorker: TIdThreadComponent;
actSupportRequest: TAction;
miMakeasupportrequest_nl: TMenuItem;
lblMovieType_nl: TLabel;
lblCutApplication_nl: TLabel;
lblMovieFPS_nl: TLabel;
actStop: TAction;
actPlayPause: TAction;
miPlayPause_nl: TMenuItem;
miStop_nl: TMenuItem;
miN16_nl: TMenuItem;
actPlay: TAction;
actPause: TAction;
miPlay_nl: TMenuItem;
miPause_nl: TMenuItem;
AppCommand: TJvAppCommand;
actCurrentFrames: TAction;
miFramesAround_nl: TMenuItem;
JvSpeedItem16: TJvSpeedItem;
cbMute: TJvCheckBox;
actSearchCutlistLocal: TAction;
JvSpeedItem17: TJvSpeedItem;
SearchCutlistsinDirectory_nl: TMenuItem;
KeyFrameGrabber: TSampleGrabber;
odMovie: TJvOpenDialog;
cbCutPreview: TJvCheckBox;
actSetCutStart: TAction;
actSetCutEnd: TAction;
actJumpCutStart: TAction;
actJumpCutEnd: TAction;
actSelectNextCut: TAction;
actSelectPrevCut: TAction;
miN17_nl: TMenuItem;
miSetendofcut_nl: TMenuItem;
miSetstartofcut_nl: TMenuItem;
miJumptostartofcut_nl: TMenuItem;
miJumptoendofcut_nl: TMenuItem;
actShiftCut: TAction;
shiftCut1: TMenuItem;
actSplitCut: TAction;
actMergeCut: TAction;
cmdMergeCut: TButton;
cmdSplitCut: TButton;
actChangeStyle: TAction;
JvSpeedItem18: TJvSpeedItem;
mnuStyles: TPopupMenu;
JvDesktopAlertStack: TJvDesktopAlertStack;
IdSSLIOHandler: TIdSSLIOHandlerSocketOpenSSL;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure cmdFromStartClick(Sender: TObject);
procedure cmdToEndClick(Sender: TObject);
procedure actStepForwardExecute(Sender: TObject);
procedure actStepBackwardExecute(Sender: TObject);
procedure lvCutlistSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
procedure lvCutlistDblClick(Sender: TObject);
procedure rgCutModeClick(Sender: TObject);
procedure tbVolumeChange(Sender: TObject);
procedure cbMuteClick(Sender: TObject);
procedure tbFilePosTimer(sender: TObject; CurrentPos, StopPos: Cardinal);
procedure tbFilePosPositionChangedByMouse(Sender: TObject);
procedure tbFilePosChange(Sender: TObject);
procedure tbFilePosSelChanged(Sender: TObject);
procedure tbFilePosChannelPostPaint(Sender: TDSTrackBarEx; const ARect: TRect);
procedure tbFinePosChange(Sender: TObject);
procedure FilterGraphGraphStepComplete(Sender: TObject);
procedure pnlVideoWindowResize(Sender: TObject);
procedure actOpenMovieExecute(Sender: TObject);
procedure actOpenCutlistExecute(Sender: TObject);
procedure actSaveCutlistExecute(Sender: TObject);
procedure actSaveCutlistAsExecute(Sender: TObject);
procedure actFileExitExecute(Sender: TObject);
procedure actAddCutExecute(Sender: TObject);
procedure actReplaceCutExecute(Sender: TObject);
procedure actEditCutExecute(Sender: TObject);
procedure actDeleteCutExecute(Sender: TObject);
procedure cmdConvertClick(Sender: TObject);
procedure actCutlistInfoExecute(Sender: TObject);
procedure actSearchCutlistByFileSizeExecute(Sender: TObject);
procedure actCutlistUploadExecute(Sender: TObject);
procedure actSendRatingExecute(Sender: TObject);
procedure actDeleteCutlistFromServerExecute(Sender: TObject);
procedure actShowFramesFormExecute(Sender: TObject);
procedure actNextFramesExecute(Sender: TObject);
procedure actPrevFramesExecute(Sender: TObject);
procedure actScanIntervalExecute(Sender: TObject);
procedure actRepairMovieExecute(Sender: TObject);
procedure actStartCuttingExecute(Sender: TObject);
procedure actAsfbinInfoExecute(Sender: TObject);
procedure actMovieMetaDataExecute(Sender: TObject);
procedure actEditSettingsExecute(Sender: TObject);
procedure actUsedFiltersExecute(Sender: TObject);
procedure actAboutExecute(Sender: TObject);
procedure actBrowseWWWHelpExecute(Sender: TObject);
procedure actOpenCutlistHomeExecute(Sender: TObject);
procedure actWriteToRegistyExecute(Sender: TObject);
procedure actRemoveRegistryEntriesExecute(Sender: TObject);
procedure actCalculateResultingTimesExecute(Sender: TObject);
procedure VideoWindowClick(Sender: TObject);
procedure tbRateChange(Sender: TObject);
procedure lblCurrentRate_nlDblClick(Sender: TObject);
procedure actNextCutExecute(Sender: TObject);
procedure actPrevCutExecute(Sender: TObject);
procedure cmdFFMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure cmdFFMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure VideoWindowDblClick(Sender: TObject);
procedure actFullScreenExecute(Sender: TObject);
procedure VideoWindowKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure actCloseMovieExecute(Sender: TObject);
procedure actSnapshotCopyExecute(Sender: TObject);
procedure actSnapshotSaveExecute(Sender: TObject);
procedure actPlayInMPlayerAndSkipExecute(Sender: TObject);
function FilterGraphSelectedFilter(Moniker: IMoniker; FilterName: WideString; ClassID: TGUID): Boolean;
procedure FramePopUpNext12FramesClick(Sender: TObject);
procedure FramePopUpPrevious12FramesClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure actShowLoggingExecute(Sender: TObject);
procedure actTestExceptionHandlingExecute(Sender: TObject);
procedure actCheckInfoOnServerExecute(Sender: TObject);
procedure actOpenCutassistantHomeExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure dlgRequestProgressShow(Sender: TObject);
procedure dlgRequestProgressProgress(Sender: TObject; var AContinue: Boolean);
procedure RequestWorkerRun(Sender: TIdThreadComponent);
procedure RequestWorkerException(Sender: TIdThreadComponent; AException: Exception);
procedure WebRequest_nlStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
procedure dlgRequestProgressCancel(Sender: TObject);
procedure WebRequest_nlWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Int64);
procedure actStopExecute(Sender: TObject);
procedure actPlayPauseExecute(Sender: TObject);
procedure actPlayExecute(Sender: TObject);
procedure actPauseExecute(Sender: TObject);
procedure actCurrentFramesExecute(Sender: TObject);
procedure FilterGraphGraphComplete(sender: TObject; Result: HRESULT; Renderer: IBaseFilter);
procedure actSearchCutlistLocalExecute(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure SampleGrabberSample(sender: TObject; SampleTime: Double; ASample: IMediaSample);
procedure KeyFrameGrabberSample(sender: TObject; SampleTime: Double; ASample: IMediaSample);
procedure actSetCutStartExecute(Sender: TObject);
procedure actSetCutEndExecute(Sender: TObject);
procedure actJumpCutStartExecute(Sender: TObject);
procedure actJumpCutEndExecute(Sender: TObject);
procedure actSelectNextCutExecute(Sender: TObject);
procedure actSelectPrevCutExecute(Sender: TObject);
procedure actShiftCutExecute(Sender: TObject);
procedure AppCommandAppCommand(Handle: NativeUInt; Cmd: Word; Device: TJvAppCommandDevice; KeyState: Word; var Handled: Boolean);
procedure actSplitCutExecute(Sender: TObject);
procedure actMergeCutExecute(Sender: TObject);
procedure actChangeStyleExecute(Sender: TObject);
procedure lvCutlistCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
private
{ private declarations }
UploadDataEntries: TStringList;
StepComplete: Boolean;
SampleInfo: RMediaSample;
KeyFrameSampleInfo: RMediaSample;
procedure ResetForm;
procedure EnableMovieControls(Value: Boolean);
procedure InitVideo;
procedure InsertKeyFrameGrabber;
procedure InsertSampleGrabber;
function GetSampleGrabberMediaType(var MediaType: TAMMediaType): HResult;
function CustomGetSampleGrabberBitmap(Bitmap: TBitmap; Buffer: Pointer; BufferLen: Integer): Boolean;
{
function SampleCB(SampleTime: Double; MediaSample: IMediaSample): HRESULT; stdcall;
function BufferCB(SampleTime: Double; pBuffer: PByte; BufferLen: longint): HResult; stdcall;
}
procedure refresh_lvCutlist(cutlist: TCutlist);
function WaitForStep(TimeOut: Integer; const WaitForSampleInfo: Boolean): Boolean;
procedure WaitForFilterGraph;
procedure HandleParameter(const param: string);
function CalcTrueRate(Interval: Double): Double;
procedure FF_Start;
procedure FF_Stop;
function ConvertUploadData: Boolean;
procedure AddUploadDataEntry(CutlistDate: TDateTime; CutlistName: string; CutlistID: Integer);
procedure UpdateMovieInfoControls;
procedure UpdatePlayPauseButton;
procedure UpdateTrackBarPageSize;
procedure UpdateVolume;
procedure SelectStyleClick(Sender: TObject);
public
{ public declarations }
procedure ProcessFileList(FileList: TStringList; IsMyOwnCommandLine: Boolean);
procedure refresh_times;
procedure enable_del_buttons(Value: Boolean);
function CurrentPosition: Double;
procedure JumpTo(NewPosition: Double);
procedure JumpToEx(NewPosition: Double; NewStop: Double);
procedure SetStartPosition(Position: Double);
procedure SetStopPosition(Position: Double);
procedure ShowFrames(startframe, endframe: Integer);
procedure ShowFramesAbs(startframe, endframe: Double; numberOfFrames: Integer);
function OpenFile(FileName: string): Boolean;
function BuildFilterGraph(FileName: string; FileType: TMovieType): Boolean;
function CloseCutlist: Boolean;
function CloseMovieAndCutlist: Boolean;
procedure CloseMovie;
function GraphPlayPause: Boolean;
function GraphPlay: Boolean;
function GraphPause: Boolean;
function ToggleFullScreen: Boolean;
procedure ShowMetaData;
function RepairMovie: Boolean;
function StartCutting: Boolean;
// function CreateVDubScript(cutlist: TCutlist; Inputfile, Outputfile: string; var scriptfile: string): Boolean;
function CreateMPlayerEDL(cutlist: TCutlist; Inputfile, Outputfile: string; var scriptfile: string): Boolean;
function DownloadInfo(settings: TSettings; const UseDate, ShowAll: Boolean): Boolean;
procedure LoadCutList;
// function search_cutlist: Boolean;
function SearchCutlists(AutoOpen: Boolean; SearchLocal, SearchWeb: Boolean; SearchTypes: TCutlistSearchTypes): Boolean;
function SearchCutlistsByFileSize_Local(SearchType: TCutlistSearchType): Integer;
function SearchCutlistsByFileSize_XML(SearchType: TCutlistSearchType; IgnorePrefix: Boolean = False): Integer;
// function DownloadCutlist(cutlist_name: string): Boolean;
function DownloadCutlistByID(const cutlist_id, TargetFileName: string): Boolean; overload;
function UploadCutlist(FileName: string): Boolean;
function DeleteCutlistFromServer(const cutlist_id: string): Boolean;
function AskForUserRating(Cutlist: TCutlist): Boolean;
function SendRating(Cutlist: TCutlist): Boolean;
procedure ShowNotifyMsg(const ACaption, AMessage: string);
protected
procedure WMDropFiles(var message: TWMDropFiles); message WM_DROPFILES;
procedure WMCopyData(var msg: TWMCopyData); message WM_COPYDATA;
function DoHttpGet(const url: string; const handleRedirects: Boolean; const Error_message: string; var Response: string): Boolean;
function DoHttpRequest(data: THttpRequest): Boolean;
function CheckResponse(const Response: string; const Protocol: Integer; const Command: TCutlistServerCommand): string;
function CheckResponseProto1(const Response: string; const Command: TCutlistServerCommand): string;
procedure SettingsChanged;
function HandleWorkerException(data: THttpRequest): Boolean;
function FormatMoviePosition(const position: Double): string; overload;
function FormatMoviePosition(const frame: longint; const duration: Double): string; overload;
procedure UpdateCutControls(APreviousPos, ANewPos: Double);
end;
var
FMain: TFMain;
CutList: TCutList;
Settings: TSettings = nil;
pos_to, pos_from: Double;
vol_temp: Integer;
last_pos: Double;
// Batch flags
exit_after_commandline, TryCutting: Boolean;
// movie params
MovieInfo: TMovieInfo;
// Interfaces
BasicVideo: IBasicVideo;
Seeking: IMediaSeeking;
MediaEvent: IMediaEvent;
Framestep: IVideoFrameStep;
VMRWindowlessControl: IVMRWindowlessControl;
VMRWindowlessControl9: IVMRWindowlessControl9;
implementation
{$WARN SYMBOL_PLATFORM OFF}
uses
// Delphi
System.TypInfo, System.UITypes, Vcl.Consts, Vcl.Themes,
// Indy
IdResourceStrings, IdURI,
// Jedi
JvParameterList, JvParameterListParameter, JvParameterListTools, JvDynControlEngineVCL, ExceptDlg, JvDesktopAlertForm,
// CA
DateTools, Frames, CutlistRate_Dialog, ResultingTimes, CutlistSearchResults, UfrmCutting, UCutApplicationBase,
UCutApplicationAsfbin, UCutApplicationMP4Box, UMemoDialog, UAbout, ULogging, UDSAStorage, CAResources,
TrackbarStyleHookCA,
// Other
uFreeLocalizer, PBOnceOnly;
{$R *.dfm}
const
ServerProtocol = 1;
function TFMain.CheckResponse(const Response: string; const Protocol: Integer; const Command: TCutlistServerCommand): string;
begin
case protocol of
1 : Result := CheckResponseProto1(Response, Command);
else Result := Format(RsMsgServerCommandErrorProtocol, [Protocol]);
end;
end;
function TFMain.CheckResponseProto1(const Response: string; const Command: TCutlistServerCommand): string;
var
ErrorCodeText: string;
ErrorCode: Integer;
ResponseFields: TStringList;
begin
ResponseFields := TStringList.Create;
try
with ResponseFields do
begin
CaseSensitive := False;
Duplicates := dupAccept;
Delimiter := #10;
NameValueSeparator := '=';
DelimitedText := Response;
ErrorCodeText := Values['error'];
end;
if (Command = cscRate) and (ErrorCodeText = '') then
ErrorCode := 0
else
ErrorCode := StrToIntDef(ErrorCodeText, -3);
case ErrorCode of
-3 : Result := RsMsgServerCommandErrorResponse;
-2 : Result := RsMsgServerCommandErrorUnspecified;
-1 : Result := Format(RsMsgServerCommandErrorMySql, [ResponseFields.Values['mysql_errno']]);
0 : Result := '';
else begin
case Command of
cscDelete : begin // Delete cutlist from server
case ErrorCode of
1 : Result := RsMsgCutlistDeleteEntryNotRemoved;
2 : Result := RsMsgServerCommandErrorArgMissing;
else Result := RsMsgCutlistDeleteUnexpected;
end;
end;
cscRate : begin // Rate cutlist on server
case ErrorCode of
1 : Result := RsMsgCutlistRateAlreadyRated;
2 : Result := RsMsgServerCommandErrorArgMissing;
else Result := RsMsgServerCommandErrorUnspecified
end;
end;
else Result := Format(RsMsgServerCommandErrorCommand, [GetEnumName(TypeInfo(TCutlistServerCommand), Ord(Command))]);
end;
end;
end;
finally
ResponseFields.Free;
end;
end;
function TFMain.FormatMoviePosition(const position: Double): string;
begin
if MovieInfo.frame_duration = 0 then
Result := FormatMoviePosition(0, 0)
else
Result := FormatMoviePosition(Round(position / MovieInfo.frame_duration), position)
end;
function TFMain.FormatMoviePosition(const frame: longint; const duration: Double): string;
begin
Result := IntToStr(frame) + ' / ' + MovieInfo.FormatPosition(duration);
end;
procedure TFMain.UpdateMovieInfoControls;
begin
if Assigned(MovieInfo) then
lblMovieFPS_nl.Caption := MovieInfo.FormatFrameRate
else
lblMovieFPS_nl.Caption := FrameRateToStr(0, #0);
if Assigned(MovieInfo) and MovieInfo.MovieLoaded then
begin
lblMovieType_nl.Caption := MovieInfo.MovieTypeString;
lblCutApplication_nl.Caption := Format(RsCaptionCutApplication, [Settings.GetCutAppName(MovieInfo.MovieType)]);
end else
begin
lblMovieType_nl.Caption := MovieInfo.GetStringFromMovieType(mtNone);
lblCutApplication_nl.Caption := Format(RsCaptionCutApplication, [RsNotAvailable]);
end;
end;
procedure TFMain.UpdatePlayPauseButton;
begin
actPlayPause.Caption := IfThen(FilterGraph.State = gsPlaying, '||', '>');
end;
procedure TFMain.UpdateTrackBarPageSize;
begin
if MovieInfo.MovieLoaded then
tbFilePos.PageSize := Round(MovieInfo.frame_duration * tbFinePos.Position * 1000 / tbFilePos.TimerInterval);
end;
procedure TFMain.refresh_times;
begin
edtFrom.Text := MovieInfo.FormatPosition(pos_from);
edtTo.Text := MovieInfo.FormatPosition(pos_to);
if pos_to >= pos_from then
begin
edtDuration.Text := MovieInfo.FormatPosition(pos_to - pos_from);
actAddCut.Enabled := True;
end else
begin
edtDuration.Text := '';
actAddCut.Enabled := False;
end;
end;
procedure TFMain.FormCreate(Sender: TObject);
procedure InitFramesProperties(const AAction: TAction; const s: string);
begin
if Assigned(AAction) then
begin
AAction.Caption := StringReplace(AAction.Caption, '$$', s, []);
AAction.Hint := StringReplace(AAction.Hint, '$$', s, []);
end;
end;
var
S,numFrames: string;
M: TMenuItem;
I,J: Integer;
icon: TIcon;
begin
TStyleManager.Engine.RegisterStyleHook(TDSTrackBarEx, TTrackBarStyleHookCA);
icon := TIcon.Create;
try
icon.Handle := LoadIcon(0, PChar(IDI_EXCLAMATION)) ;
ICutlistWarning.Picture.Icon := Icon;
finally
icon.Free;
end;
AdjustFormConstraints(Self);
if Screen.WorkAreaWidth < Constraints.MinWidth then
Constraints.MinWidth := Screen.Width;
if Screen.WorkAreaHeight < Constraints.MinHeight then
Constraints.MinHeight := Screen.Height;
if ValidRect(Settings.MainFormBounds) then
begin
BoundsRect := Settings.MainFormBounds;
end else
begin
Top := Screen.WorkAreaTop + Max(0, (Screen.WorkAreaHeight - Height) div 2);
Left := Screen.WorkAreaLeft + Max(0, (Screen.WorkAreaWidth - Width) div 2);
end;
numFrames := IntToStr(Settings.FramesCount);
InitFramesProperties(actNextFrames, numFrames);
InitFramesProperties(actCurrentFrames, numFrames);
InitFramesProperties(actPrevFrames, numFrames);
InitFramesProperties(actScanInterval, numFrames);
ResetForm;
// clear BtnCaption (autoloaded at runtime from ActionList) to prevent drawing of text below buttons
for I := 0 to Pred(SpeedBar_nl.SectionCount) do
for J := 0 to Pred(SpeedBar_nl.ItemsCount(I)) do
SpeedBar_nl.Items(I, J).BtnCaption := '';
DragAcceptFiles(Handle, True);
ExitCode := 0;
UploadDataEntries := TStringList.Create;
if FileExists(UploadData_Path(True)) then
UploadDataEntries.LoadFromFile(UploadData_Path(True));
if FileExists(UploadData_Path(False)) then
ConvertUploadData;
SettingsChanged;
rgCutMode.ItemIndex := settings.DefaultCutMode;
Cutlist.RefreshCallBack := refresh_lvCutlist;
cutlist.RefreshGUI;
filtergraph.Volume := 5000;
tbVolume.PageSize := tbVolume.Frequency;
tbVolume.LineSize := Round(tbVolume.PageSize / 10);
tbVolume.Position := filtergraph.Volume;
KeyFrameSampleInfo.Active := False;
SampleInfo.Active := False;
SampleInfo.Bitmap := TBitmap.Create;
cbCutPreview.Checked := Settings.CutPreview;
tbFinePos.Position := Settings.FinePosFrameCount;
lblFinePos_nl.Caption := Format(RsFrames, [tbFinePos.Position, tbFinePos.Position / 25]);
tbFilePos.Frequency := Round(60000 / tbFilePos.TimerInterval); // one tick every minute
with TStringList.Create do
try
for S in TStyleManager.StyleNames do
Add(S);
Sort;
for I := 0 to Pred(Count) do
begin
M := TMenuItem.Create(mnuStyles);
M.Caption := Strings[I];
M.OnClick := SelectStyleClick;
M.AutoCheck := True;
M.RadioItem := True;
M.GroupIndex := 1;
if Strings[I] = TStyleManager.ActiveStyle.Name then
M.Checked := True;
mnuStyles.Items.Add(M);
end;
finally
Free;
end;
WindowState := Settings.MainFormWindowState;
end;
procedure TFMain.FormDestroy(Sender: TObject);
begin
Settings.FinePosFrameCount := tbFinePos.Position;
Settings.MainFormBounds := BoundsRect;
Settings.MainFormWindowState := WindowState;
Settings.CutPreview := cbCutPreview.Checked;
FreeAndNil(SampleInfo.Bitmap);
FreeAndNil(UploadDataEntries);
end;
procedure TFMain.cmdFromStartClick(Sender: TObject);
begin
pos_from := 0;
refresh_times;
end;
procedure TFMain.cmdToEndClick(Sender: TObject);
begin
pos_to := MovieInfo.current_file_duration;
refresh_times;
end;
procedure TFMain.lvCutlistSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
enable_del_buttons(True);
end;
procedure TFMain.enable_del_buttons(Value: Boolean);
begin
actDeleteCut.enabled := Value;
actEditCut.Enabled := Value;
actReplaceCut.Enabled := Value;
actShiftCut.Enabled := Value;
actSplitCut.Enabled := lvCutlist.Items.Count > 0;
actMergeCut.Enabled := Value and (lvCutlist.Items.Count > 1);
end;
function TFMain.StartCutting: Boolean;
var
sourcefile, sourceExtension, targetfile, targetpath: string;
AskForPath: Boolean;
saveDlg: TSaveDialog;
CutApplication: TCutApplicationBase;
begin
Result := False;
if cutlist.Count > 0 then
begin
if settings.CutlistAutoSaveBeforeCutting and cutlist.HasChanged then
cutlist.Save(False);
sourcefile := ExtractFileName(MovieInfo.current_filename);
sourceExtension := ExtractFileExt(sourcefile);
if settings.UseMovieNameSuggestion and (Trim(cutlist.SuggestedMovieName) <> '') then
targetfile := Trim(cutlist.SuggestedMovieName) + SourceExtension
else
targetfile := ChangeFileExt(sourcefile, Settings.CutMovieExtension + SourceExtension);
case Settings.SaveCutMovieMode of
smWithSource: targetpath := ExtractFilePath(MovieInfo.current_filename); // with source
smGivenDir: targetpath := IncludeTrailingPathDelimiter(Settings.CutMovieSaveDir); // in given Dir
else targetpath := ExtractFilePath(MovieInfo.current_filename); // with source
end;
targetfile := CleanFileName(targetfile);
if not ForceDirectories(targetpath) then
begin
if not batchmode then
ErrMsgFmt(RsCouldNotCreateTargetPath, [targetpath]);
Exit;
end;
MovieInfo.target_filename := targetpath + targetfile;
//Display Save Dialog?
AskForPath := Settings.MovieNameAlwaysConfirm;
if FileExists(MovieInfo.target_FileName) and (not AskForPath) and (not batchmode) then
begin
if not NoYesMsgFmt(RsTargetMovieAlreadyExists, [MovieInfo.target_filename]) then
AskForPath := True;
end;
if AskForPath and (not batchmode) then
begin
saveDlg := TSaveDialog.Create(Self);
saveDlg.Filter := '*' + SourceExtension + '|*' + SourceExtension;
saveDlg.Title := RsSaveCutMovieAs;
saveDlg.InitialDir := targetpath;
saveDlg.FileName := Settings.ReplaceList.SearchAndReplace(targetfile);
saveDlg.Options := saveDlg.Options + [ofOverwritePrompt, ofPathMustExist];
if saveDlg.Execute then
begin
MovieInfo.target_filename := Trim(saveDlg.FileName);
if not SameText(ExtractFileExt(MovieInfo.target_filename), SourceExtension) then
MovieInfo.target_filename := MovieInfo.target_filename + sourceExtension;
end else
Exit;
end;
if FileExists(MovieInfo.target_FileName) then
begin
if not deletefile(MovieInfo.target_filename) then
begin
if not batchmode then
ErrMsgFmt(RsCouldNotDeleteFile, [MovieInfo.target_filename]);
Exit;
end;
end;
CutApplication := Settings.GetCutApplicationByMovieType(MovieInfo.MovieType);
if Assigned(CutApplication) then
begin
CutApplication.CutAppSettings := Settings.GetCutAppSettingsByMovieType(MovieInfo.MovieType);
frmCutting.CutApplication := CutApplication;
Result := CutApplication.PrepareCutting(MovieInfo.current_filename, MovieInfo.target_filename, cutlist);
if Result then
Result := frmCutting.ExecuteCutApp = mrOK;
end;
end else
begin
if not batchmode then
ErrMsg(RsNoCutsDefined);
end;
end;
procedure TFMain.UpdateVolume;
begin
if CBMUte.Checked then
FilterGraph.Volume := 0
else
FilterGraph.Volume := tbVolume.Position;
end;
procedure TFMain.cbMuteClick(Sender: TObject);
begin
UpdateVolume;
end;
procedure TFMain.tbVolumeChange(Sender: TObject);
begin
UpdateVolume;
end;
procedure TFMain.refresh_lvCutlist(cutlist: TCutlist);
var
icut: Integer;
cut: tcut;
cut_view: tlistitem;
i_column: Integer;
total_cutoff, resulting_duration: Double;
hascuts: Boolean;
begin
lvCutlist.Clear;
actSendRating.Enabled := cutlist.IDOnServer <> '';
hascuts := cutlist.Count > 0;
actStartCutting.Enabled := hascuts;
actCalculateResultingTimes.Enabled := hascuts;
actSaveCutlistAs.Enabled := hascuts;
actSaveCutlist.Enabled := hascuts;
actCutlistUpload.Enabled := hascuts;
actNextCut.Enabled := hascuts;
actPrevCut.Enabled := hascuts;
if hascuts then
begin
for icut := 0 to Pred(cutlist.Count) do
begin
cut := cutlist[icut];
cut_view := lvCutlist.Items.Add;
cut_view.Caption := IntToStr(icut); //IntToStr(cut.index);
cut_view.SubItems.Add(MovieInfo.FormatPosition(cut.pos_from));
cut_view.SubItems.Add(MovieInfo.FormatPosition(cut.pos_to));
cut_view.SubItems.Add(MovieInfo.FormatPosition(cut.pos_to - cut.pos_from + MovieInfo.frame_duration));
end;
//Auto-Resize columns
for i_column := 0 to Pred(lvCutlist.Columns.Count) do
lvCutlist.Columns[i_column].Width := -1;
end;
enable_del_buttons(hascuts and (lvCutlist.ItemIndex >= 0));
if cutlist.Mode = clmCutOut then
begin
total_cutoff := cutlist.TotalDurationOfCuts;
resulting_duration := MovieInfo.current_file_duration - total_cutoff;
end else
begin
resulting_duration := cutlist.TotalDurationOfCuts;
total_cutoff := MovieInfo.current_file_duration - resulting_duration;
end;
lblTotalCutoff_nl.Caption := Format(RsCaptionTotalCutoff, [secondsToTimeString(total_cutoff)]);
lblResultingDuration_nl.Caption := Format(RsCaptionResultingDuration, [secondsToTimeString(resulting_duration)]);
//Cuts in Trackbar are taken from global var "cutlist"!
tbFilePos.Perform(CM_RECREATEWND, 0, 0); // Show Cuts in Trackbar
case cutlist.Mode of
clmCutOut : rgCutMode.ItemIndex := 0;
clmTrim : rgCutMode.ItemIndex := 1;
end;
ICutlistWarning.Visible := (cutlist.RatingByAuthorPresent and (cutlist.RatingByAuthor <= 2)) or
cutlist.EPGError or cutlist.MissingBeginning or cutlist.MissingEnding or cutlist.MissingVideo or
cutlist.MissingAudio or cutlist.OtherError;
if ICutlistWarning.Visible then
cmdCutlistInfo.Width := ICutlistWarning.Left - cmdSplitCut.Left - 4
else
cmdCutlistInfo.Width := cmdSplitCut.Width;
if cutlist.Author <> '' then
begin
lblCutlistAuthor_nl.Caption := cutlist.Author;
pnlAuthor.Visible := True;
end else
pnlAuthor.Visible := False;
end;
function TFMain.OpenFile(FileName: string): Boolean; // False if file not found
var
SourceFilter, AviDecompressorFilter: IBaseFilter;
SourceAdded: Boolean;
AvailableFilters: TSysDevEnum;
PinList: TPinList;
IPin: Integer;
TempCursor: TCursor;
begin
Result := False;
if FileExists(FileName) then
begin
if MovieInfo.MovieLoaded then
begin
if not CloseMovieAndCutlist then
Exit;
end;
TempCursor := Screen.Cursor;