-
Notifications
You must be signed in to change notification settings - Fork 0
/
libavformat_avformat.go
2492 lines (2261 loc) · 92.3 KB
/
libavformat_avformat.go
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
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
/*
* copyright (c) 2001 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package ffmpeg
//#cgo pkg-config: libavcodec libavutil libavformat
//#include <time.h>
//#include <stdio.h>
//#include "libavcodec/avcodec.h"
//#include "libavutil/dict.h"
//#include "libavutil/log.h"
//#include "libavformat/avio.h"
//#include "libavformat/version.h"
//#include "libavformat/avformat.h"
import "C"
import (
"unsafe"
)
const AVPROBE_SCORE_RETRY = 25
const AVPROBE_SCORE_STREAM_RETRY = 24
const AVPROBE_SCORE_EXTENSION = 50
const AVPROBE_SCORE_MIME = 75
const AVPROBE_SCORE_MAX = 100
const AVPROBE_PADDING_SIZE = 32
const AVFMT_NOFILE = 0x0001
const AVFMT_NEEDNUMBER = 0x0002
const AVFMT_SHOW_IDS = 0x0008
const AVFMT_GLOBALHEADER = 0x0040
const AVFMT_NOTIMESTAMPS = 0x0080
const AVFMT_GENERIC_INDEX = 0x0100
const AVFMT_TS_DISCONT = 0x0200
const AVFMT_VARIABLE_FPS = 0x0400
const AVFMT_NODIMENSIONS = 0x0800
const AVFMT_NOSTREAMS = 0x1000
const AVFMT_NOBINSEARCH = 0x2000
const AVFMT_NOGENSEARCH = 0x4000
const AVFMT_NO_BYTE_SEEK = 0x8000
const AVFMT_ALLOW_FLUSH = 0x10000
const AVFMT_TS_NONSTRICT = 0x20000
const AVFMT_TS_NEGATIVE = 0x40000
const AVFMT_SEEK_TO_PTS = 0x4000000
const AVINDEX_KEYFRAME = 0x0001
const AVINDEX_DISCARD_FRAME = 0x0002
const AV_DISPOSITION_DEFAULT = 0x0001
const AV_DISPOSITION_DUB = 0x0002
const AV_DISPOSITION_ORIGINAL = 0x0004
const AV_DISPOSITION_COMMENT = 0x0008
const AV_DISPOSITION_LYRICS = 0x0010
const AV_DISPOSITION_KARAOKE = 0x0020
const AV_DISPOSITION_FORCED = 0x0040
const AV_DISPOSITION_HEARING_IMPAIRED = 0x0080
const AV_DISPOSITION_VISUAL_IMPAIRED = 0x0100
const AV_DISPOSITION_CLEAN_EFFECTS = 0x0200
const AV_DISPOSITION_ATTACHED_PIC = 0x0400
const AV_DISPOSITION_TIMED_THUMBNAILS = 0x0800
const AV_DISPOSITION_CAPTIONS = 0x10000
const AV_DISPOSITION_DESCRIPTIONS = 0x20000
const AV_DISPOSITION_METADATA = 0x40000
const AV_DISPOSITION_DEPENDENT = 0x80000
const AV_DISPOSITION_STILL_IMAGE = 0x100000
const AV_PTS_WRAP_IGNORE = 0
const AV_PTS_WRAP_ADD_OFFSET = 1
const AV_PTS_WRAP_SUB_OFFSET = -1
const AVSTREAM_EVENT_FLAG_METADATA_UPDATED = 0x0001
const MAX_STD_TIMEBASES = 399
const MAX_REORDER_DELAY = 16
const AV_PROGRAM_RUNNING = 1
const AVFMTCTX_NOHEADER = 0x0001
const AVFMTCTX_UNSEEKABLE = 0x0002
const AVFMT_FLAG_GENPTS = 0x0001
const AVFMT_FLAG_IGNIDX = 0x0002
const AVFMT_FLAG_NONBLOCK = 0x0004
const AVFMT_FLAG_IGNDTS = 0x0008
const AVFMT_FLAG_NOFILLIN = 0x0010
const AVFMT_FLAG_NOPARSE = 0x0020
const AVFMT_FLAG_NOBUFFER = 0x0040
const AVFMT_FLAG_CUSTOM_IO = 0x0080
const AVFMT_FLAG_DISCARD_CORRUPT = 0x0100
const AVFMT_FLAG_FLUSH_PACKETS = 0x0200
const AVFMT_FLAG_BITEXACT = 0x0400
const AVFMT_FLAG_MP4A_LATM = 0x8000
const AVFMT_FLAG_SORT_DTS = 0x10000
const AVFMT_FLAG_PRIV_OPT = 0x20000
const AVFMT_FLAG_KEEP_SIDE_DATA = 0x40000
const AVFMT_FLAG_FAST_SEEK = 0x80000
const AVFMT_FLAG_SHORTEST = 0x100000
const AVFMT_FLAG_AUTO_BSF = 0x200000
const FF_FDEBUG_TS = 0x0001
const AVFMT_EVENT_FLAG_METADATA_UPDATED = 0x0001
const AVFMT_AVOID_NEG_TS_AUTO = -1
const AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE = 1
const AVFMT_AVOID_NEG_TS_MAKE_ZERO = 2
const AVSEEK_FLAG_BACKWARD = 1
const AVSEEK_FLAG_BYTE = 2
const AVSEEK_FLAG_ANY = 4
const AVSEEK_FLAG_FRAME = 8
const AVSTREAM_INIT_IN_WRITE_HEADER = 0
const AVSTREAM_INIT_IN_INIT_OUTPUT = 1
const AV_FRAME_FILENAME_FLAGS_MULTIPLE = 1
type AVStream_Ams21 struct {
Last_dts int64
Duration_gcd int64
Duration_count int32
Rfps_duration_sum int64
Duration_error* [2][MAX_STD_TIMEBASES]float64
Codec_info_duration int64
Codec_info_duration_fields int64
Frame_delay_evidence int32
Found_decoder int32
Last_duration int64
Fps_first_dts int64
Fps_first_dts_idx int32
Fps_last_dts int64
Fps_last_dts_idx int32
}
/**
* @file
* @ingroup libavf
* Main libavformat public API header
*/
/**
* @defgroup libavf libavformat
* I/O and Muxing/Demuxing Library
*
* Libavformat (lavf) is a library for dealing with various media container
* formats. Its main two purposes are demuxing - i.e. splitting a media file
* into component streams, and the reverse process of muxing - writing supplied
* data in a specified container format. It also has an @ref lavf_io
* "I/O module" which supports a number of protocols for accessing the data (e.g.
* file, tcp, http and others). Before using lavf, you need to call
* av_register_all() to register all compiled muxers, demuxers and protocols.
* Unless you are absolutely sure you won't use libavformat's network
* capabilities, you should also call avformat_network_init().
*
* A supported input format is described by an AVInputFormat struct, conversely
* an output format is described by AVOutputFormat. You can iterate over all
* registered input/output formats using the av_iformat_next() /
* av_oformat_next() functions. The protocols layer is not part of the public
* API, so you can only get the names of supported protocols with the
* avio_enum_protocols() function.
*
* Main lavf structure used for both muxing and demuxing is AVFormatContext,
* which exports all information about the file being read or written. As with
* most Libavformat structures, its size is not part of public ABI, so it cannot be
* allocated on stack or directly with av_malloc(). To create an
* AVFormatContext, use avformat_alloc_context() (some functions, like
* avformat_open_input() might do that for you).
*
* Most importantly an AVFormatContext contains:
* @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat
* "output" format. It is either autodetected or set by user for input;
* always set by user for output.
* @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all
* elementary streams stored in the file. AVStreams are typically referred to
* using their index in this array.
* @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or
* set by user for input, always set by user for output (unless you are dealing
* with an AVFMT_NOFILE format).
*
* @section lavf_options Passing options to (de)muxers
* It is possible to configure lavf muxers and demuxers using the @ref avoptions
* mechanism. Generic (format-independent) libavformat options are provided by
* AVFormatContext, they can be examined from a user program by calling
* av_opt_next() / av_opt_find() on an allocated AVFormatContext (or its AVClass
* from avformat_get_class()). Private (format-specific) options are provided by
* AVFormatContext.priv_data if and only if AVInputFormat.priv_class /
* AVOutputFormat.priv_class of the corresponding format struct is non-NULL.
* Further options may be provided by the @ref AVFormatContext.pb "I/O context",
* if its AVClass is non-NULL, and the protocols layer. See the discussion on
* nesting in @ref avoptions documentation to learn how to access those.
*
* @section urls
* URL strings in libavformat are made of a scheme/protocol, a ':', and a
* scheme specific string. URLs without a scheme and ':' used for local files
* are supported but deprecated. "file:" should be used for local files.
*
* It is important that the scheme string is not taken from untrusted
* sources without checks.
*
* Note that some schemes/protocols are quite powerful, allowing access to
* both local and remote files, parts of them, concatenations of them, local
* audio and video devices and so on.
*
* @{
*
* @defgroup lavf_decoding Demuxing
* @{
* Demuxers read a media file and split it into chunks of data (@em packets). A
* @ref AVPacket "packet" contains one or more encoded frames which belongs to a
* single elementary stream. In the lavf API this process is represented by the
* avformat_open_input() function for opening a file, av_read_frame() for
* reading a single packet and finally avformat_close_input(), which does the
* cleanup.
*
* @section lavf_decoding_open Opening a media file
* The minimum information required to open a file is its URL, which
* is passed to avformat_open_input(), as in the following code:
* @code
* const char *url = "file:in.mp3";
* AVFormatContext *s = NULL;
* int ret = avformat_open_input(&s, url, NULL, NULL);
* if (ret < 0)
* abort();
* @endcode
* The above code attempts to allocate an AVFormatContext, open the
* specified file (autodetecting the format) and read the header, exporting the
* information stored there into s. Some formats do not have a header or do not
* store enough information there, so it is recommended that you call the
* avformat_find_stream_info() function which tries to read and decode a few
* frames to find missing information.
*
* In some cases you might want to preallocate an AVFormatContext yourself with
* avformat_alloc_context() and do some tweaking on it before passing it to
* avformat_open_input(). One such case is when you want to use custom functions
* for reading input data instead of lavf internal I/O layer.
* To do that, create your own AVIOContext with avio_alloc_context(), passing
* your reading callbacks to it. Then set the @em pb field of your
* AVFormatContext to newly created AVIOContext.
*
* Since the format of the opened file is in general not known until after
* avformat_open_input() has returned, it is not possible to set demuxer private
* options on a preallocated context. Instead, the options should be passed to
* avformat_open_input() wrapped in an AVDictionary:
* @code
* AVDictionary *options = NULL;
* av_dict_set(&options, "video_size", "640x480", 0);
* av_dict_set(&options, "pixel_format", "rgb24", 0);
*
* if (avformat_open_input(&s, url, NULL, &options) < 0)
* abort();
* av_dict_free(&options);
* @endcode
* This code passes the private options 'video_size' and 'pixel_format' to the
* demuxer. They would be necessary for e.g. the rawvideo demuxer, since it
* cannot know how to interpret raw video data otherwise. If the format turns
* out to be something different than raw video, those options will not be
* recognized by the demuxer and therefore will not be applied. Such unrecognized
* options are then returned in the options dictionary (recognized options are
* consumed). The calling program can handle such unrecognized options as it
* wishes, e.g.
* @code
* AVDictionaryEntry *e;
* if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
* fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
* abort();
* }
* @endcode
*
* After you have finished reading the file, you must close it with
* avformat_close_input(). It will free everything associated with the file.
*
* @section lavf_decoding_read Reading from an opened file
* Reading data from an opened AVFormatContext is done by repeatedly calling
* av_read_frame() on it. Each call, if successful, will return an AVPacket
* containing encoded data for one AVStream, identified by
* AVPacket.stream_index. This packet may be passed straight into the libavcodec
* decoding functions avcodec_send_packet() or avcodec_decode_subtitle2() if the
* caller wishes to decode the data.
*
* AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be
* set if known. They may also be unset (i.e. AV_NOPTS_VALUE for
* pts/dts, 0 for duration) if the stream does not provide them. The timing
* information will be in AVStream.time_base units, i.e. it has to be
* multiplied by the timebase to convert them to seconds.
*
* If AVPacket.buf is set on the returned packet, then the packet is
* allocated dynamically and the user may keep it indefinitely.
* Otherwise, if AVPacket.buf is NULL, the packet data is backed by a
* static storage somewhere inside the demuxer and the packet is only valid
* until the next av_read_frame() call or closing the file. If the caller
* requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy
* of it.
* In both cases, the packet must be freed with av_packet_unref() when it is no
* longer needed.
*
* @section lavf_decoding_seek Seeking
* @}
*
* @defgroup lavf_encoding Muxing
* @{
* Muxers take encoded data in the form of @ref AVPacket "AVPackets" and write
* it into files or other output bytestreams in the specified container format.
*
* The main API functions for muxing are avformat_write_header() for writing the
* file header, av_write_frame() / av_interleaved_write_frame() for writing the
* packets and av_write_trailer() for finalizing the file.
*
* At the beginning of the muxing process, the caller must first call
* avformat_alloc_context() to create a muxing context. The caller then sets up
* the muxer by filling the various fields in this context:
*
* - The @ref AVFormatContext.oformat "oformat" field must be set to select the
* muxer that will be used.
* - Unless the format is of the AVFMT_NOFILE type, the @ref AVFormatContext.pb
* "pb" field must be set to an opened IO context, either returned from
* avio_open2() or a custom one.
* - Unless the format is of the AVFMT_NOSTREAMS type, at least one stream must
* be created with the avformat_new_stream() function. The caller should fill
* the @ref AVStream.codecpar "stream codec parameters" information, such as the
* codec @ref AVCodecParameters.codec_type "type", @ref AVCodecParameters.codec_id
* "id" and other parameters (e.g. width / height, the pixel or sample format,
* etc.) as known. The @ref AVStream.time_base "stream timebase" should
* be set to the timebase that the caller desires to use for this stream (note
* that the timebase actually used by the muxer can be different, as will be
* described later).
* - It is advised to manually initialize only the relevant fields in
* AVCodecParameters, rather than using @ref avcodec_parameters_copy() during
* remuxing: there is no guarantee that the codec context values remain valid
* for both input and output format contexts.
* - The caller may fill in additional information, such as @ref
* AVFormatContext.metadata "global" or @ref AVStream.metadata "per-stream"
* metadata, @ref AVFormatContext.chapters "chapters", @ref
* AVFormatContext.programs "programs", etc. as described in the
* AVFormatContext documentation. Whether such information will actually be
* stored in the output depends on what the container format and the muxer
* support.
*
* When the muxing context is fully set up, the caller must call
* avformat_write_header() to initialize the muxer internals and write the file
* header. Whether anything actually is written to the IO context at this step
* depends on the muxer, but this function must always be called. Any muxer
* private options must be passed in the options parameter to this function.
*
* The data is then sent to the muxer by repeatedly calling av_write_frame() or
* av_interleaved_write_frame() (consult those functions' documentation for
* discussion on the difference between them; only one of them may be used with
* a single muxing context, they should not be mixed). Do note that the timing
* information on the packets sent to the muxer must be in the corresponding
* AVStream's timebase. That timebase is set by the muxer (in the
* avformat_write_header() step) and may be different from the timebase
* requested by the caller.
*
* Once all the data has been written, the caller must call av_write_trailer()
* to flush any buffered packets and finalize the output file, then close the IO
* context (if any) and finally free the muxing context with
* avformat_free_context().
* @}
*
* @defgroup lavf_io I/O Read/Write
* @{
* @section lavf_io_dirlist Directory listing
* The directory listing API makes it possible to list files on remote servers.
*
* Some of possible use cases:
* - an "open file" dialog to choose files from a remote location,
* - a recursive media finder providing a player with an ability to play all
* files from a given directory.
*
* @subsection lavf_io_dirlist_open Opening a directory
* At first, a directory needs to be opened by calling avio_open_dir()
* supplied with a URL and, optionally, ::AVDictionary containing
* protocol-specific parameters. The function returns zero or positive
* integer and allocates AVIODirContext on success.
*
* @code
* AVIODirContext *ctx = NULL;
* if (avio_open_dir(&ctx, "smb://example.com/some_dir", NULL) < 0) {
* fprintf(stderr, "Cannot open directory.\n");
* abort();
* }
* @endcode
*
* This code tries to open a sample directory using smb protocol without
* any additional parameters.
*
* @subsection lavf_io_dirlist_read Reading entries
* Each directory's entry (i.e. file, another directory, anything else
* within ::AVIODirEntryType) is represented by AVIODirEntry.
* Reading consecutive entries from an opened AVIODirContext is done by
* repeatedly calling avio_read_dir() on it. Each call returns zero or
* positive integer if successful. Reading can be stopped right after the
* NULL entry has been read -- it means there are no entries left to be
* read. The following code reads all entries from a directory associated
* with ctx and prints their names to standard output.
* @code
* AVIODirEntry *entry = NULL;
* for (;;) {
* if (avio_read_dir(ctx, &entry) < 0) {
* fprintf(stderr, "Cannot list directory.\n");
* abort();
* }
* if (!entry)
* break;
* printf("%s\n", entry->name);
* avio_free_directory_entry(&entry);
* }
* @endcode
* @}
*
* @defgroup lavf_codec Demuxers
* @{
* @defgroup lavf_codec_native Native Demuxers
* @{
* @}
* @defgroup lavf_codec_wrappers External library wrappers
* @{
* @}
* @}
* @defgroup lavf_protos I/O Protocols
* @{
* @}
* @defgroup lavf_internal Internal
* @{
* @}
* @}
*/
// type AVFormatContext
// type AVDeviceInfoList
// type AVDeviceCapabilitiesQuery
/**
* @defgroup metadata_api Public Metadata API
* @{
* @ingroup libavf
* The metadata API allows libavformat to export metadata tags to a client
* application when demuxing. Conversely it allows a client application to
* set metadata when muxing.
*
* Metadata is exported or set as pairs of key/value strings in the 'metadata'
* fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs
* using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg,
* metadata is assumed to be UTF-8 encoded Unicode. Note that metadata
* exported by demuxers isn't checked to be valid UTF-8 in most cases.
*
* Important concepts to keep in mind:
* - Keys are unique; there can never be 2 tags with the same key. This is
* also meant semantically, i.e., a demuxer should not knowingly produce
* several keys that are literally different but semantically identical.
* E.g., key=Author5, key=Author6. In this example, all authors must be
* placed in the same tag.
* - Metadata is flat, not hierarchical; there are no subtags. If you
* want to store, e.g., the email address of the child of producer Alice
* and actor Bob, that could have key=alice_and_bobs_childs_email_address.
* - Several modifiers can be applied to the tag name. This is done by
* appending a dash character ('-') and the modifier name in the order
* they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
* - language -- a tag whose value is localized for a particular language
* is appended with the ISO 639-2/B 3-letter language code.
* For example: Author-ger=Michael, Author-eng=Mike
* The original/default language is in the unqualified "Author" tag.
* A demuxer should set a default if it sets any translated tag.
* - sorting -- a modified version of a tag that should be used for
* sorting will have '-sort' appended. E.g. artist="The Beatles",
* artist-sort="Beatles, The".
* - Some protocols and demuxers support metadata updates. After a successful
* call to av_read_packet(), AVFormatContext.event_flags or AVStream.event_flags
* will be updated to indicate if metadata changed. In order to detect metadata
* changes on a stream, you need to loop through all streams in the AVFormatContext
* and check their individual event_flags.
*
* - Demuxers attempt to export metadata in a generic format, however tags
* with no generic equivalents are left as they are stored in the container.
* Follows a list of generic tag names:
*
@verbatim
album -- name of the set this work belongs to
album_artist -- main creator of the set/album, if different from artist.
e.g. "Various Artists" for compilation albums.
artist -- main creator of the work
comment -- any additional description of the file.
composer -- who composed the work, if different from artist.
copyright -- name of copyright holder.
creation_time-- date when the file was created, preferably in ISO 8601.
date -- date when the work was created, preferably in ISO 8601.
disc -- number of a subset, e.g. disc in a multi-disc collection.
encoder -- name/settings of the software/hardware that produced the file.
encoded_by -- person/group who created the file.
filename -- original name of the file.
genre -- <self-evident>.
language -- main language in which the work is performed, preferably
in ISO 639-2 format. Multiple languages can be specified by
separating them with commas.
performer -- artist who performed the work, if different from artist.
E.g for "Also sprach Zarathustra", artist would be "Richard
Strauss" and performer "London Philharmonic Orchestra".
publisher -- name of the label/publisher.
service_name -- name of the service in broadcasting (channel name).
service_provider -- name of the service provider in broadcasting.
title -- name of the work.
track -- number of this work in the set, can be in form current/total.
variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
@endverbatim
*
* Look in the examples section for an application example how to use the Metadata API.
*
* @}
*/
/* packet functions */
/**
* Allocate and read the payload of a packet and initialize its
* fields with default values.
*
* @param s associated IO context
* @param pkt packet
* @param size desired payload size
* @return >0 (read size) if OK, AVERROR_xxx otherwise
*/
func Av_get_packet(s *AVIOContext, pkt *AVPacket, size int32) int32 {
return int32(C.av_get_packet((*C.struct_AVIOContext)(unsafe.Pointer(s)),
(*C.struct_AVPacket)(unsafe.Pointer(pkt)), C.int(size)))
}
/**
* Read data and append it to the current content of the AVPacket.
* If pkt->size is 0 this is identical to av_get_packet.
* Note that this uses av_grow_packet and thus involves a realloc
* which is inefficient. Thus this function should only be used
* when there is no reasonable way to know (an upper bound of)
* the final size.
*
* @param s associated IO context
* @param pkt packet
* @param size amount of data to read
* @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
* will not be lost even if an error occurs.
*/
func Av_append_packet(s *AVIOContext, pkt *AVPacket, size int32) int32 {
return int32(C.av_append_packet((*C.struct_AVIOContext)(unsafe.Pointer(s)),
(*C.struct_AVPacket)(unsafe.Pointer(pkt)), C.int(size)))
}
/*************************************************/
/* input/output formats */
type AVCodecTag struct {
}
/**
* This structure contains the data a format has to probe a file.
*/
type AVProbeData struct {
Filename *byte
Buf *uint8
Buf_size int32
Mime_type *byte
}
///< score for file extension
///< score for file mime type
///< maximum score
///< extra allocated bytes at the end of the probe buffer
/// Demuxer will use avio_open, no opened file should be provided by the caller.
/**< Needs '%d' in filename. */
/**< Show format stream IDs numbers. */
/**< Format wants global header. */
/**< Format does not need / have any timestamps. */
/**< Use generic index building code. */
/**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
/**< Format allows variable fps. */
/**< Format does not need width/height */
/**< Format does not require any streams */
/**< Format does not allow to fall back on binary search via read_timestamp */
/**< Format does not allow to fall back on generic search */
/**< Format does not allow seeking by bytes */
/**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */
/**< Format does not require strictly
increasing timestamps, but they must
still be monotonic */
/**< Format allows muxing negative
timestamps. If not set the timestamp
will be shifted in av_write_frame and
av_interleaved_write_frame so they
start from 0.
The user or muxer can override this through
AVFormatContext.avoid_negative_ts
*/
/**< Seeking is based on PTS */
/**
* @addtogroup lavf_encoding
* @{
*/
type AVOutputFormat struct {
Name *byte
Long_name *byte
Mime_type *byte
Extensions *byte
Audio_codec AVCodecID
Video_codec AVCodecID
Subtitle_codec AVCodecID
Flags int32
Codec_tag **AVCodecTag
Priv_class *AVClass
Next *AVOutputFormat
Priv_data_size int32
Write_header uintptr
Write_packet uintptr
Write_trailer uintptr
Interleave_packet uintptr
Query_codec uintptr
Get_output_timestamp uintptr
Control_message uintptr
Write_uncoded_frame uintptr
Get_device_list uintptr
Create_device_capabilities uintptr
Free_device_capabilities uintptr
Data_codec AVCodecID
Init uintptr
Deinit uintptr
Check_bitstream uintptr
}
/**
* @}
*/
/**
* @addtogroup lavf_decoding
* @{
*/
type AVInputFormat struct {
Name *byte
Long_name *byte
Flags int32
Extensions *byte
Codec_tag **AVCodecTag
Priv_class *AVClass
Mime_type *byte
Next *AVInputFormat
Raw_codec_id int32
Priv_data_size int32
Read_probe uintptr
Read_header uintptr
Read_packet uintptr
Read_close uintptr
Read_seek uintptr
Read_timestamp uintptr
Read_play uintptr
Read_pause uintptr
Read_seek2 uintptr
Get_device_list uintptr
Create_device_capabilities uintptr
Free_device_capabilities uintptr
}
/**
* @}
*/
type AVStreamParseType int32
const (
AVSTREAM_PARSE_NONE AVStreamParseType = iota
AVSTREAM_PARSE_FULL
AVSTREAM_PARSE_HEADERS
AVSTREAM_PARSE_TIMESTAMPS
AVSTREAM_PARSE_FULL_ONCE
AVSTREAM_PARSE_FULL_RAW
)
// type AVIndexEntry
/**
* Track should be used during playback by default.
* Useful for subtitle track that should be displayed
* even when user did not explicitly ask for subtitles.
*/
/**< stream for hearing impaired audiences */
/**< stream for visual impaired audiences */
/**< stream without voice */
/**
* The stream is stored in the file as an attached picture/"cover art" (e.g.
* APIC frame in ID3v2). The first (usually only) packet associated with it
* will be returned among the first few packets read from the file unless
* seeking takes place. It can also be accessed at any time in
* AVStream.attached_pic.
*/
/**
* The stream is sparse, and contains thumbnail images, often corresponding
* to chapter markers. Only ever used with AV_DISPOSITION_ATTACHED_PIC.
*/
type AVStreamInternal struct {
}
/**
* To specify text track kind (different from subtitles default).
*/
///< dependent audio stream (mix_type=0 in mpegts)
///< still images in video stream (still_picture_flag=1 in mpegts)
/**
* Options for behavior on timestamp wrap detection.
*/
///< ignore the wrap
///< add the format specific offset on wrap detection
///< subtract the format specific offset on wrap detection
/**
* Stream structure.
* New fields can be added to the end with minor version bumps.
* Removal, reordering and changes to existing fields require a major
* version bump.
* sizeof(AVStream) must not be used outside libav*.
*/
type AVStream struct {
Index int32
Id int32
Codec *AVCodecContext
Priv_data unsafe.Pointer
Time_base AVRational
Start_time int64
Duration int64
Nb_frames int64
Disposition int32
Discard AVDiscard
Sample_aspect_ratio AVRational
Metadata *AVDictionary
Avg_frame_rate AVRational
Attached_pic AVPacket
Side_data *AVPacketSideData
Nb_side_data int32
Event_flags int32
R_frame_rate AVRational
Recommended_encoder_configuration *byte
Codecpar *AVCodecParameters
Info *AVStream_Ams21
Pts_wrap_bits int32
First_dts int64
Cur_dts int64
Last_IP_pts int64
Last_IP_duration int32
Probe_packets int32
Codec_info_nb_frames int32
Need_parsing AVStreamParseType
Parser *AVCodecParserContext
Last_in_packet_buffer *AVPacketList
Probe_data AVProbeData
Pts_buffer [MAX_REORDER_DELAY+1]int64
Index_entries *AVIndexEntry
Nb_index_entries int32
Index_entries_allocated_size uint32
Stream_identifier int32
Program_num int32
Pmt_version int32
Pmt_stream_idx int32
Interleaver_chunk_size int64
Interleaver_chunk_duration int64
Request_probe int32
Skip_to_keyframe int32
Skip_samples int32
Start_skip_samples int64
First_discard_sample int64
Last_discard_sample int64
Nb_decoded_frames int32
Mux_ts_offset int64
Pts_wrap_reference int64
Pts_wrap_behavior int32
Update_initial_durations_done int32
Pts_reorder_error [MAX_REORDER_DELAY+1]int64
Pts_reorder_error_count [MAX_REORDER_DELAY+1]uint8
Last_dts_for_order_check int64
Dts_ordered uint8
Dts_misordered uint8
Inject_global_side_data int32
Display_aspect_ratio AVRational
Internal *AVStreamInternal
}
/**
* Accessors for some AVStream fields. These used to be provided for ABI
* compatibility, and do not need to be used anymore.
*/
func Av_stream_get_r_frame_rate(s *AVStream) AVRational {
_ret := C.av_stream_get_r_frame_rate((*C.struct_AVStream)(unsafe.Pointer(s)))
return *(*AVRational)(unsafe.Pointer(&_ret))
}
func Av_stream_set_r_frame_rate(s *AVStream, r AVRational) {
C.av_stream_set_r_frame_rate((*C.struct_AVStream)(unsafe.Pointer(s)),
*(*C.struct_AVRational)(unsafe.Pointer(&r)))
}
func Av_stream_get_recommended_encoder_configuration(s *AVStream) string {
return C.GoString(C.av_stream_get_recommended_encoder_configuration(
(*C.struct_AVStream)(unsafe.Pointer(s))))
}
func Av_stream_set_recommended_encoder_configuration(s *AVStream, configuration *byte) {
C.av_stream_set_recommended_encoder_configuration(
(*C.struct_AVStream)(unsafe.Pointer(s)),
(*C.char)(unsafe.Pointer(configuration)))
}
func Av_stream_get_parser(s *AVStream) *AVCodecParserContext {
return (*AVCodecParserContext)(unsafe.Pointer(C.av_stream_get_parser(
(*C.struct_AVStream)(unsafe.Pointer(s)))))
}
/**
* Returns the pts of the last muxed packet + its duration
*
* the retuned value is undefined when used with a demuxer.
*/
func Av_stream_get_end_pts(st *AVStream) int64 {
return int64(C.av_stream_get_end_pts((*C.struct_AVStream)(unsafe.Pointer(st))))
}
/**
* New fields can be added to the end with minor version bumps.
* Removal, reordering and changes to existing fields require a major
* version bump.
* sizeof(AVProgram) must not be used outside libav*.
*/
type AVProgram struct {
Id int32
Flags int32
Discard AVDiscard
Stream_index *uint32
Nb_stream_indexes uint32
Metadata *AVDictionary
Program_num int32
Pmt_pid int32
Pcr_pid int32
Pmt_version int32
Start_time int64
End_time int64
Pts_wrap_reference int64
Pts_wrap_behavior int32
}
/**< signal that no header is present
(streams are added dynamically) */
/**< signal that the stream is definitely
not seekable, and attempts to call the
seek function will fail. For some
network protocols (e.g. HLS), this can
change dynamically at runtime. */
type AVChapter struct {
Id int32
Time_base AVRational
Start int64
End int64
Metadata *AVDictionary
}
/**
* Callback used by devices to communicate with application.
*/
type av_format_control_message C.av_format_control_message
type AVOpenCallback C.AVOpenCallback
/**
* The duration of a video can be estimated through various ways, and this enum can be used
* to know how the duration was estimated.
*/
type AVDurationEstimationMethod int32
const (
AVFMT_DURATION_FROM_PTS AVDurationEstimationMethod = iota
AVFMT_DURATION_FROM_STREAM
AVFMT_DURATION_FROM_BITRATE
)
type AVFormatInternal struct {
}
/**
* Format I/O context.
* New fields can be added to the end with minor version bumps.
* Removal, reordering and changes to existing fields require a major
* version bump.
* sizeof(AVFormatContext) must not be used outside libav*, use
* avformat_alloc_context() to create an AVFormatContext.
*
* Fields can be accessed through AVOptions (av_opt*),
* the name string used matches the associated command line parameter name and
* can be found in libavformat/options_table.h.
* The AVOption/command line parameter names differ in some cases from the C
* structure field names for historic reasons or brevity.
*/
type AVFormatContext struct {
Av_class *AVClass
Iformat *AVInputFormat
Oformat *AVOutputFormat
Priv_data unsafe.Pointer
Pb *AVIOContext
Ctx_flags int32
Nb_streams uint32
Streams **AVStream
Filename [1024]byte
Url *byte
Start_time int64
Duration int64
Bit_rate int64
Packet_size uint32
Max_delay int32
Flags int32
Probesize int64
Max_analyze_duration int64
Key *uint8
Keylen int32
Nb_programs uint32
Programs **AVProgram
Video_codec_id AVCodecID
Audio_codec_id AVCodecID
Subtitle_codec_id AVCodecID
Max_index_size uint32
Max_picture_buffer uint32
Nb_chapters uint32
Chapters **AVChapter
Metadata *AVDictionary
Start_time_realtime int64
Fps_probe_size int32
Error_recognition int32
Interrupt_callback AVIOInterruptCB
Debug int32
Max_interleave_delta int64
Strict_std_compliance int32
Event_flags int32
Max_ts_probe int32
Avoid_negative_ts int32
Ts_id int32
Audio_preload int32
Max_chunk_duration int32
Max_chunk_size int32
Use_wallclock_as_timestamps int32
Avio_flags int32
Duration_estimation_method AVDurationEstimationMethod