-
Notifications
You must be signed in to change notification settings - Fork 1
/
AVFormat.cs
1105 lines (890 loc) · 39.7 KB
/
AVFormat.cs
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
using System;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
namespace SharpFFmpeg
{
public partial class FFmpeg
{
/// <summary>
///
/// </summary>
/// <param name="pAVPacket"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_destruct_packet_nofree(IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVPacket"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_destruct_packet(IntPtr pAVPacket);
/// <summary>
/// Initialize optional fields of a packet.
/// </summary>
/// <param name="pAVPacket"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_init_packet(IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVPacket"></param>
/// <param name="size"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_new_packet(IntPtr pAVPacket, int size);
/// <summary>
///
/// </summary>
/// <param name="pByteIOContext"></param>
/// <param name="pAVPacket"></param>
/// <param name="size"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_get_packet(IntPtr pByteIOContext, IntPtr pAVPacket, int size);
/// <summary>
///
/// </summary>
/// <param name="pAVPacket"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_dup_packet(IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVPacket"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_free_packet(IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVImageFormat"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_register_image_format(IntPtr pAVImageFormat);
/// <summary>
///
/// </summary>
/// <param name="pAVProbeData"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr av_probe_image_format(IntPtr pAVProbeData);
/// <summary>
///
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr guess_image_format([MarshalAs(UnmanagedType.LPTStr)]String filename);
/// <summary>
///
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern CodecID av_guess_image2_codec([MarshalAs(UnmanagedType.LPTStr)]
String filename);
/// <summary>
///
/// </summary>
/// <param name="pByteIOContext"></param>
/// <param name="filename"></param>
/// <param name="pAVImageFormat"></param>
/// <param name="alloc_cb"></param>
/// <param name="opaque"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_read_image(IntPtr pByteIOContext,
[MarshalAs(UnmanagedType.LPTStr)]String filename,
IntPtr pAVImageFormat,
[MarshalAs(UnmanagedType.FunctionPtr)]
AllocCBCallback alloc_cb,
IntPtr opaque);
/// <summary>
///
/// </summary>
/// <param name="pByteIOContext"></param>
/// <param name="pAVImageFormat"></param>
/// <param name="pAVImageInfo"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_write_image(IntPtr pByteIOContext, IntPtr pAVImageFormat, IntPtr pAVImageInfo);
/// <summary>
///
/// </summary>
/// <param name="pAVInputFormat"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_register_input_format(IntPtr pAVInputFormat);
/// <summary>
///
/// </summary>
/// <param name="pAVOutputFormat"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_register_output_format(IntPtr pAVOutputFormat);
/// <summary>
///
/// </summary>
/// <param name="short_name"></param>
/// <param name="filename"></param>
/// <param name="mime_type"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr guess_stream_format([MarshalAs(UnmanagedType.LPTStr)]
String short_name,
[MarshalAs(UnmanagedType.LPTStr)]
String filename,
[MarshalAs(UnmanagedType.LPTStr)]
String mime_type);
/// <summary>
///
/// </summary>
/// <param name="short_name"></param>
/// <param name="filename"></param>
/// <param name="mime_type"></param>
/// <returns>AVOutputFormat pointer</returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr guess_format([MarshalAs(UnmanagedType.LPTStr)]
String short_name,
[MarshalAs(UnmanagedType.LPTStr)]
String filename,
[MarshalAs(UnmanagedType.LPTStr)]
String mime_type);
/// <summary>
///
/// </summary>
/// <param name="pAVOutoutFormat"></param>
/// <param name="short_name"></param>
/// <param name="filename"></param>
/// <param name="mime_type"></param>
/// <param name="type"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern CodecID av_guess_codec(IntPtr pAVOutoutFormat,
[MarshalAs(UnmanagedType.LPTStr)]
String short_name,
[MarshalAs(UnmanagedType.LPTStr)]
String filename,
[MarshalAs(UnmanagedType.LPTStr)]
String mime_type,
CodecType type);
/// <summary>
///
/// </summary>
/// <param name="pFile"></param>
/// <param name="buf"></param>
/// <param name="size"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_hex_dump(IntPtr pFile, IntPtr buf, int size);
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_pkt_dump(IntPtr pFile, IntPtr pAVPacket, int dump_payload);
/// <summary>
///
/// </summary>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_register_all();
/* media file input */
/// <summary>
///
/// </summary>
/// <param name="?"></param>
/// <returns>AVInputFormat pointer</returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr av_find_input_format([MarshalAs(UnmanagedType.LPTStr)]String short_name);
/// <summary>
///
/// </summary>
/// <param name="pAVProbeData"></param>
/// <param name="is_opened"></param>
/// <returns>AVInputFormat pointer</returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr av_probe_input_format(IntPtr pAVProbeData, int is_opened);
/// <summary>
///
/// </summary>
/// <param name="pFormatContext"></param>
/// <param name="filename"></param>
/// <param name="pAVInputFormat"></param>
/// <param name="buf_size"></param>
/// <param name="pAVFormatParameters"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_open_input_file([Out]out IntPtr pFormatContext,
[MarshalAs(UnmanagedType.LPStr)]String filename,
IntPtr pAVInputFormat, int buf_size, IntPtr pAVFormatParameters);
/// <summary>
///
/// </summary>
/// <returns>AVFormatContext pointer</returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr av_alloc_format_context();
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_find_stream_info(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVPacket"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_read_packet(IntPtr pAVFormatContext, IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVPacket"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_read_frame(IntPtr pAVFormatContext, IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="stream_index"></param>
/// <param name="timestamp"></param>
/// <param name="flags"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_seek_frame(IntPtr pAVFormatContext, int stream_index, Int64 timestamp, int flags);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_read_play(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_read_pause(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_close_input_file(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="id"></param>
/// <returns>AVStream pointer</returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr av_new_stream(IntPtr pAVFormatContext, int id);
/// <summary>
///
/// </summary>
/// <param name="pAVStream"></param>
/// <param name="pts_wrap_bits"></param>
/// <param name="pts_num"></param>
/// <param name="pts_den"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_set_pts_info(IntPtr pAVStream, int pts_wrap_bits, int pts_num, int pts_den);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_find_default_stream_index(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVStream"></param>
/// <param name="timestamp"></param>
/// <param name="flags"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_index_search_timestamp(IntPtr pAVStream, Int64 timestamp, int flags);
/// <summary>
///
/// </summary>
/// <param name="pAVStream"></param>
/// <param name="?"></param>
/// <param name="?"></param>
/// <param name="timestamp"></param>
/// <param name="size"></param>
/// <param name="distance"></param>
/// <param name="flags"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_add_index_entry(IntPtr pAVStream, Int64 pos, Int64 timestamp, int size, int distance, int flags);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="stream_index"></param>
/// <param name="target_ts"></param>
/// <param name="flags"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_seek_frame_binary(IntPtr pAVFormatContext, int stream_index, Int64 target_ts, int flags);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVStream"></param>
/// <param name="timestamp"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_update_cur_dts(IntPtr pAVFormatContext, IntPtr pAVStream, Int64 timestamp);
/* media file output */
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVFormatParameters"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_set_parameters(IntPtr pAVFormatContext, IntPtr pAVFormatParameters);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_write_header(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVPacket"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_write_frame(IntPtr pAVFormatContext, IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pAVPacket"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_interleaved_write_frame(IntPtr pAVFormatContext, IntPtr pAVPacket);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="p_out_AVPacket"></param>
/// <param name="pAVPacket"></param>
/// <param name="flush"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_interleave_packet_per_dts(IntPtr pAVFormatContext, out IntPtr p_out_AVPacket, IntPtr pAVPacket, int flush);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_write_trailer(IntPtr pAVFormatContext);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="index"></param>
/// <param name="url"></param>
/// <param name="is_output"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void dump_format(IntPtr pAVFormatContext, int index,
[MarshalAs(UnmanagedType.LPTStr)]
String url,
int is_output);
/// <summary>
///
/// </summary>
/// <param name="width_ptr"></param>
/// <param name="height_ptr"></param>
/// <param name="arg"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int parse_image_size(IntPtr width_ptr, IntPtr height_ptr,
[MarshalAs(UnmanagedType.LPTStr)]String arg);
/// <summary>
///
/// </summary>
/// <param name="pFrame_rate"></param>
/// <param name="pFrame_rate_base"></param>
/// <param name="arg"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int parse_frame_rate(IntPtr pFrame_rate, IntPtr pFrame_rate_base,
[MarshalAs(UnmanagedType.LPTStr)]String arg);
/// <summary>
///
/// </summary>
/// <param name="datestr"></param>
/// <param name="duration"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern Int64 parse_date([MarshalAs(UnmanagedType.LPTStr)]String datestr, int duration);
/// <summary>
///
/// </summary>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern Int64 av_gettime();
/// <summary>
///
/// </summary>
/// <param name="fd"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern Int64 ffm_read_write_index(int fd);
/// <summary>
///
/// </summary>
/// <param name="fd"></param>
/// <param name="pos"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void ffm_write_write_index(int fd, Int64 pos);
/// <summary>
///
/// </summary>
/// <param name="pAVFormatContext"></param>
/// <param name="pos"></param>
/// <param name="file_size"></param>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void ffm_set_write_index(IntPtr pAVFormatContext, Int64 pos, Int64 file_size);
/// <summary>
///
/// </summary>
/// <param name="arg"></param>
/// <param name="arg_size"></param>
/// <param name="tag1"></param>
/// <param name="info"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int find_info_tag([MarshalAs(UnmanagedType.LPTStr)]String arg,
int arg_size,
[MarshalAs(UnmanagedType.LPTStr)]String tag1,
[MarshalAs(UnmanagedType.LPTStr)]String info);
/// <summary>
///
/// </summary>
/// <param name="buf"></param>
/// <param name="buf_size"></param>
/// <param name="path"></param>
/// <param name="number"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_get_frame_filename(IntPtr buf, int buf_size,
[MarshalAs(UnmanagedType.LPTStr)]String path, int number);
/// <summary>
///
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int av_filename_number_test([MarshalAs(UnmanagedType.LPTStr)]String filename);
/// <summary>
///
/// </summary>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int video_grab_init();
/// <summary>
///
/// </summary>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int audio_init();
/* DV1394 */
/// <summary>
///
/// </summary>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int dv1394_init();
/// <summary>
///
/// </summary>
/// <returns></returns>
[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern int dc1394_init();
// *********************************************************************************
// Constants
// *********************************************************************************
public const int AV_TIME_BASE = 1000000;
public const int AVFMT_INFINITEOUTPUTLOOP = 0;
public const uint AVFMT_FLAG_GENPTS = 0x0001;
public const uint AVFMT_FLAG_IGNIDX = 0x0002;
public const int AVFMT_NOOUTPUTLOOP = -1;
// no file should be opened
public const uint AVFMT_NOFILE = 0x0001;
// needs '%d' in filename
public const uint AVFMT_NEEDNUMBER = 0x0002;
// show format stream IDs numbers
public const uint AVFMT_SHOW_IDS = 0x0008;
// format wants AVPicture structure for raw picture data
public const uint AVFMT_RAWPICTURE = 0x0020;
// format wants global header
public const uint AVFMT_GLOBALHEADER = 0x0040;
// format doesnt need / has any timestamps
public const uint AVFMT_NOTIMESTAMPS = 0x0080;
// AVImageFormat.flags field constants
public const uint AVIMAGE_INTERLEAVED = 0x0001;
public const int AVPROBE_SCORE_MAX = 100;
public const int PKT_FLAG_KEY = 0x0001;
public const int AVINDEX_KEYFRAME = 0x001;
public const int MAX_REORDER_DELAY = 4;
public const uint AVFMTCTX_NOHEADER = 0x001;
public const int MAX_STREAMS = 20;
public const int AVERROR_UNKNOWN = -1;
public const int AVERROR_IO = -2;
public const int AVERROR_NUMEXPECTED = -3;
public const int AVERROR_INVALIDDATA = -4;
public const int AVERROR_NOMEM = -5;
public const int AVERROR_NOFMT = -6;
public const int AVERROR_NOTSUPP = -7;
public const int AVSEEK_FLAG_BACKWARD = 1;
public const int AVSEEK_FLAG_BYTE = 2;
public const int AVSEEK_FLAG_ANY = 4;
public const int FFM_PACKET_SIZE = 4096;
// *********************************************************************************
// Constants
// *********************************************************************************
public delegate void DestructCallback(IntPtr pAVPacket);
[StructLayout(LayoutKind.Sequential)]
public struct AVPacket
{
[MarshalAs(UnmanagedType.I8)]
public Int64 pts; // presentation time stamp in time_base units
[MarshalAs(UnmanagedType.I8)]
public Int64 dts; // decompression time stamp in time_base units
public IntPtr data;
[MarshalAs(UnmanagedType.I4)]
public int size;
[MarshalAs(UnmanagedType.I4)]
public int stream_index;
[MarshalAs(UnmanagedType.I4)]
public int flags;
[MarshalAs(UnmanagedType.I4)]
public int duration;
[MarshalAs(UnmanagedType.FunctionPtr)]
public DestructCallback destruct;
public IntPtr priv;
[MarshalAs(UnmanagedType.I8)]
public Int64 pos;
};
[StructLayout(LayoutKind.Sequential)]
public struct AVFrac
{
[MarshalAs(UnmanagedType.I8)]
Int64 val;
[MarshalAs(UnmanagedType.I8)]
Int64 num;
[MarshalAs(UnmanagedType.I8)]
Int64 den;
};
[StructLayout(LayoutKind.Sequential)]
public struct AVProbeData
{
[MarshalAs(UnmanagedType.LPStr)]
String filename;
IntPtr buf;
int buf_size;
};
[StructLayout(LayoutKind.Sequential)]
public struct AVFormatParameters
{
AVRational time_base;
int sample_rate;
int channels;
int width;
int height;
PixelFormat pix_fmt;
IntPtr image_format; // AVImageFormat
int channel;
[MarshalAs(UnmanagedType.LPStr)]
String device;
[MarshalAs(UnmanagedType.LPStr)]
String standard;
int mpeg2ts_raw;
int mpeg2ts_compute_pcr;
int initial_pause;
int prealloced_context;
CodecID video_codec_id;
CodecID audio_codec_id;
};
public delegate int WriteHeader(IntPtr pAVFormatContext);
public delegate int WritePacket(IntPtr pAVFormatContext, IntPtr pAVPacket);
public delegate int WriteTrailer(IntPtr pAVFormatContext);
public delegate int SetParametersCallback(IntPtr pAVFormatContext, IntPtr avFormatParameters);
public delegate int InterleavePacketCallback(IntPtr pAVFormatContext, IntPtr pOutAVPacket, IntPtr pInAVPacket, int flush);
[StructLayout(LayoutKind.Sequential)]
public struct AVOutputFormat
{
[MarshalAs(UnmanagedType.LPStr)]
String name;
[MarshalAs(UnmanagedType.LPStr)]
String long_name;
[MarshalAs(UnmanagedType.LPStr)]
String mime_type;
[MarshalAs(UnmanagedType.LPStr)]
String extensions;
int priv_data_size;
CodecID audio_codec;
CodecID video_codec;
[MarshalAs(UnmanagedType.FunctionPtr)]
WriteHeader write_header;
[MarshalAs(UnmanagedType.FunctionPtr)]
WritePacket write_packet;
[MarshalAs(UnmanagedType.FunctionPtr)]
WriteTrailer write_trailer;
int flags;
[MarshalAs(UnmanagedType.FunctionPtr)]
SetParametersCallback set_parameters;
[MarshalAs(UnmanagedType.FunctionPtr)]
InterleavePacketCallback interleave_packet;
IntPtr nextAVOutputFormat;
};
public delegate int ReadProbeCallback(IntPtr pAVProbeData);
public delegate int ReadHeaderCallback(IntPtr pAVFormatContext, IntPtr pAVFormatParameters);
public delegate int ReadPacketCallback(IntPtr pAVFormatContext, IntPtr pAVPacket);
public delegate int ReadCloseCallback(IntPtr pAVFormatContext);
public delegate int ReadSeekCallback(IntPtr pAVFormatContext, int stream_index, Int64 timestamp, int flags);
//int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
//int64_t *pos, int64_t pos_limit);
public delegate int ReadTimestampCallback(IntPtr pAVFormatContext, int stream_index, IntPtr pos, Int64 pos_limit);
public delegate int ReadPlayCallback(IntPtr pAVFormatContext);
public delegate int ReadPauseCallback(IntPtr pAVFormatContext);
[StructLayout(LayoutKind.Sequential)]
public struct AVInputFormat
{
[MarshalAs(UnmanagedType.LPStr)]
String name;
[MarshalAs(UnmanagedType.LPStr)]
String long_name;
int priv_data_size;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadProbeCallback read_probe;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadHeaderCallback read_header;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadPacketCallback read_packet;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadCloseCallback read_close;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadSeekCallback read_seek;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadTimestampCallback read_timestamp;
// can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER
int flags;
[MarshalAs(UnmanagedType.LPStr)]
String extensions;
int value;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadPlayCallback read_play;
[MarshalAs(UnmanagedType.FunctionPtr)]
ReadPauseCallback read_pause;
IntPtr nextAVInputFormat;
};
[StructLayout(LayoutKind.Sequential)]
public struct AVIndexEntry
{
Int64 pos;
Int64 timestamp;
int flags;
int size;
int min_distance;
};
[StructLayout(LayoutKind.Sequential)]
public struct AVStream
{
[MarshalAs(UnmanagedType.I4)]
public int index; // stream index in AVFormatContext
[MarshalAs(UnmanagedType.I4)]
public int id; // format specific stream id
public IntPtr codec; // AVCodecContext
/**
* real base frame rate of the stream.
* for example if the timebase is 1/90000 and all frames have either
* approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1
*/
public AVRational r_frame_rate;
public IntPtr priv_data;
[MarshalAs(UnmanagedType.I8)]
public Int64 codec_info_duration; // internal data used in av_find_stream_info()
[MarshalAs(UnmanagedType.I4)]
public int codec_info_nb_frames;
public AVFrac pts; // encoding: PTS generation when outputing stream
/**
* this is the fundamental unit of time (in seconds) in terms
* of which frame timestamps are represented. for fixed-fps content,
* timebase should be 1/framerate and timestamp increments should be
* identically 1.
*/
public AVRational time_base;
[MarshalAs(UnmanagedType.I4)]
public int pts_wrap_bits; // number of bits in pts (used for wrapping control)
[MarshalAs(UnmanagedType.I4)]
public int stream_copy; // if TRUE, just copy stream
public AVDiscard discard; // selects which packets can be discarded at will and dont need to be demuxed
[MarshalAs(UnmanagedType.R4)]
public float quality;
[MarshalAs(UnmanagedType.I8)]
public Int64 start_time;
// decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
[MarshalAs(UnmanagedType.I8)]
public Int64 duration;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] language; // ISO 639 3-letter language code (empty string if undefined)
[MarshalAs(UnmanagedType.I4)]
public int need_parsing;
public IntPtr pAVCodecParserContext;
[MarshalAs(UnmanagedType.I8)]
public Int64 cur_dts;
[MarshalAs(UnmanagedType.I4)]
public int last_IP_duration;
[MarshalAs(UnmanagedType.I8)]
public Int64 last_IP_pts;
public IntPtr pAVIndexEntry; // only used if the format does not support seeking natively
[MarshalAs(UnmanagedType.I4)]
public int nb_index_entries;
[MarshalAs(UnmanagedType.I4)]
public int index_entries_allocated_size;
[MarshalAs(UnmanagedType.I8)]
public Int64 nb_frames; // number of frames in this stream if known or 0
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (MAX_REORDER_DELAY + 1))]
public Int64[] pts_buffer; // pts_buffer[MAX_REORDER_DELAY+1]
};
[StructLayout(LayoutKind.Sequential)]
public struct AVFormatContext
{
public IntPtr pAVClass; // set by av_alloc_format_context
public IntPtr pAVInputFormat; // can only be iformat or oformat, not both at the same time
public IntPtr pAVOutputFormat;
//[MarshalAs(UnmanagedType.FunctionPtr)]
//AnonymousCallback priv_data;
public IntPtr priv_data;
public ByteIOContext pb;
[MarshalAs(UnmanagedType.I4)]
public int nb_streams;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_STREAMS)]
public IntPtr[] streams; // AVStream
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
public byte[] filename; // input or output filename
/* stream info */
[MarshalAs(UnmanagedType.I8)]
public Int64 timestamp;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] title;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] author;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] copyright;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] comment;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
public byte[] album;
[MarshalAs(UnmanagedType.I4)]
public int year; // ID3 year, 0 if none
[MarshalAs(UnmanagedType.I4)]
public int tract; // track number, 0 if none
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] genre; // ID3 genre
[MarshalAs(UnmanagedType.I4)]
public int ctx_flags; // format specific flags, see AVFMTCTX_xx
/* This buffer is only needed when packets were already buffered but
not decoded, for example to get the codec parameters in mpeg
streams */
public IntPtr packet_buffer; // AVPacketList
/* decoding: position of the first frame of the component, in
AV_TIME_BASE fractional seconds. NEVER set this value directly:
it is deduced from the AVStream values. */
[MarshalAs(UnmanagedType.I8)]
public Int64 start_time;
/* decoding: duration of the stream, in AV_TIME_BASE fractional
seconds. NEVER set this value directly: it is deduced from the
AVStream values. */
[MarshalAs(UnmanagedType.I8)]
public Int64 duration;
[MarshalAs(UnmanagedType.I8)]
public Int64 file_size; // decoding: total file size. 0 if unknown
/* decoding: total stream bitrate in bit/s, 0 if not
available. Never set it directly if the file_size and the
duration are known as ffmpeg can compute it automatically. */
[MarshalAs(UnmanagedType.I4)]
public int bit_rate;
/* av_read_frame() support */
public IntPtr cur_st; // AVStream