|
| 1 | +""" |
| 2 | +Thanks to Neon22 at: |
| 3 | +https://gist.github.com/Neon22 |
| 4 | +""" |
| 5 | + |
| 6 | +from ctypes import (c_int, c_int64, c_uint64, |
| 7 | + c_uint8, c_uint, c_size_t, c_char, c_char_p, |
| 8 | + c_void_p, POINTER, CFUNCTYPE, Structure) |
| 9 | + |
| 10 | + |
| 11 | +AV_NUM_DATA_POINTERS = 8 |
| 12 | + |
| 13 | + |
| 14 | +class AVCodecContext(Structure): |
| 15 | + pass |
| 16 | + |
| 17 | + |
| 18 | +class AVRational(Structure): |
| 19 | + pass |
| 20 | + |
| 21 | + |
| 22 | +class AVIOInterruptCB(Structure): |
| 23 | + pass |
| 24 | + |
| 25 | + |
| 26 | +class AVPacket(Structure): |
| 27 | + _fields_ = [ |
| 28 | + ('buf', c_void_p), |
| 29 | + ('pts', c_int64), |
| 30 | + ('dts', c_int64), |
| 31 | + ('data', POINTER(c_uint8)), |
| 32 | + ('size', c_int), |
| 33 | + ('stream_index', c_int), |
| 34 | + ('flags', c_int), |
| 35 | + ('side_data', c_void_p), |
| 36 | + ('side_data_elems', c_int), |
| 37 | + ('duration', c_int64), |
| 38 | + ('pos', c_int64), |
| 39 | + ('convergence_duration', c_int64) # Deprecated |
| 40 | + ] |
| 41 | + |
| 42 | + |
| 43 | +class AVFrame(Structure): |
| 44 | + _fields_ = [ |
| 45 | + ('data', POINTER(c_uint8) * AV_NUM_DATA_POINTERS), |
| 46 | + ('linesize', c_int * AV_NUM_DATA_POINTERS), |
| 47 | + ('extended_data', POINTER(POINTER(c_uint8))), |
| 48 | + ('width', c_int), |
| 49 | + ('height', c_int), |
| 50 | + ('nb_samples', c_int), |
| 51 | + ('format', c_int), |
| 52 | + ('key_frame', c_int), |
| 53 | + ('pict_type', c_int), # or c_uint8 |
| 54 | + ('sample_aspect_ratio', AVRational), |
| 55 | + ('pts', c_int64), |
| 56 | + ('pkt_pts', c_int64), # Deprecated |
| 57 | + ('pkt_dts', c_int64), |
| 58 | + ('coded_picture_number', c_int), |
| 59 | + ('display_picture_number', c_int), |
| 60 | + ('quality', c_int), |
| 61 | + ('opaque', c_void_p), |
| 62 | + ('error', c_uint64 * AV_NUM_DATA_POINTERS), #Deprecated |
| 63 | + ('repeat_pict', c_int), |
| 64 | + ('interlaced_frame', c_int), |
| 65 | + ('top_field_first', c_int), |
| 66 | + ('palette_has_changed', c_int), |
| 67 | + ('reordered_opaque', c_int64), |
| 68 | + ('sample_rate', c_int), |
| 69 | + ('channel_layout', c_uint64), |
| 70 | + ('buf', c_void_p * AV_NUM_DATA_POINTERS), |
| 71 | + ('extended_buf', c_void_p), |
| 72 | + ('nb_extended_buf', c_int), |
| 73 | + ('side_data', c_void_p), |
| 74 | + ('nb_side_data', c_int), |
| 75 | + ('flags', c_int), |
| 76 | + ('color_range', c_int), |
| 77 | + ('color_primaries', c_int), |
| 78 | + ('color_trc', c_int), |
| 79 | + ('colorspace', c_int), |
| 80 | + ('chroma_location', c_int), |
| 81 | + ('best_effort_timestamp', c_int64), |
| 82 | + ('pkt_pos', c_int64), |
| 83 | + ('pkt_duration', c_int64), |
| 84 | + #! |
| 85 | + ('metadata', c_void_p), |
| 86 | + ('decode_error_flags', c_int), |
| 87 | + ('channels', c_int), |
| 88 | + ('pkt_size', c_int), |
| 89 | + ('qscale_table', POINTER(c_int)), #Deprecated or c_unit8#! |
| 90 | + ('qstride', c_int), #Deprecated |
| 91 | + ('qscale_type', c_int), #Deprecated |
| 92 | + ('qp_table_buf', c_void_p), #Deprecated |
| 93 | + ('hw_frames_ctx', c_void_p), |
| 94 | + ('opaque_ref', c_void_p), |
| 95 | + #!('private_ref', POINTER(AVBufferRef)), |
| 96 | + #!('width', c_int), # video frames only |
| 97 | + #(!'height', c_int), # video frames only |
| 98 | + #!('crop_top', c_size_t), # video frames only |
| 99 | + #!('crop_bottom', c_size_t), # video frames only |
| 100 | + #!('crop_left', c_size_t), # video frames only |
| 101 | + #!('crop_right', c_size_t) # video frames only |
| 102 | + ] |
| 103 | + |
| 104 | + |
| 105 | +class AVFormatContext(Structure): |
| 106 | + pass |
| 107 | + |
| 108 | + |
| 109 | +AVFormatContext._fields_ = [ |
| 110 | + ('av_class', c_void_p), |
| 111 | + ('iformat', c_void_p), |
| 112 | + ('oformat', c_void_p), |
| 113 | + ('priv_data', c_void_p), |
| 114 | + ('pb', c_void_p), |
| 115 | + ('ctx_flags', c_int), |
| 116 | + ('nb_streams', c_uint), |
| 117 | + ('streams', c_void_p), |
| 118 | + ('filename', c_char*1024), # Deprecated |
| 119 | + ('url', c_char_p), |
| 120 | + ('start_time', c_int64), |
| 121 | + ('duration', c_int64), |
| 122 | + ('bit_rate', c_int64), |
| 123 | + ('packet_size', c_uint), |
| 124 | + ('max_delay', c_int), |
| 125 | + ('flags', c_int), |
| 126 | + ('probesize', c_int64), |
| 127 | + ('max_analyze_duration', c_int64), |
| 128 | + ('key', POINTER(c_uint8)), |
| 129 | + ('keylen', c_int), |
| 130 | + ('nb_programs', c_uint), |
| 131 | + ('programs', c_void_p), |
| 132 | + ('video_codec_id', c_int), |
| 133 | + ('audio_codec_id', c_int), |
| 134 | + ('subtitle_codec_id', c_int), |
| 135 | + ('max_index_size', c_uint), |
| 136 | + ('max_picture_buffer', c_uint), |
| 137 | + ('nb_chapters', c_uint), |
| 138 | + ('chapters', c_void_p), |
| 139 | + ('metadata', c_void_p), |
| 140 | + ('start_time_realtime', c_int64), |
| 141 | + ('fps_probe_size', c_int), |
| 142 | + ('error_recognition', c_int), |
| 143 | + ('interrupt_callback', AVIOInterruptCB), |
| 144 | + ('debug', c_int), |
| 145 | + ('max_interleave_delta', c_int64), |
| 146 | + ('strict_std_compliance', c_int), |
| 147 | + ('event_flags', c_int), |
| 148 | + ('max_ts_probe', c_int), |
| 149 | + ('avoid_negative_ts', c_int), |
| 150 | + ('ts_id', c_int), |
| 151 | + ('audio_preload', c_int), |
| 152 | + ('max_chunk_duration', c_int), |
| 153 | + ('max_chunk_size', c_int), |
| 154 | + ('use_wallclock_as_timestamps', c_int), |
| 155 | + ('avio_flags', c_int), |
| 156 | + ('duration_estimation_method', c_uint), #c_uint8 |
| 157 | + ('skip_initial_bytes', c_int64), |
| 158 | + ('correct_ts_overflow', c_uint), |
| 159 | + ('seek2any', c_int), |
| 160 | + ('flush_packets', c_int), |
| 161 | + ('probe_score', c_int), |
| 162 | + ('format_probesize', c_int), |
| 163 | + ('codec_whitelist', c_char_p), |
| 164 | + ('format_whitelist', c_char_p), |
| 165 | + ('internal', c_void_p), |
| 166 | + ('io_repositioned', c_int), |
| 167 | + ('video_codec', c_void_p), |
| 168 | + ('audio_codec', c_void_p), |
| 169 | + ('subtitle_codec', c_void_p), |
| 170 | + ('data_codec', c_void_p), |
| 171 | + ('metadata_header_padding', c_int), |
| 172 | + ('opaque', c_void_p), |
| 173 | + ('control_message_cb', CFUNCTYPE(c_int, |
| 174 | + POINTER(AVFormatContext), c_int, c_void_p, |
| 175 | + c_size_t)), |
| 176 | + ('output_ts_offset', c_int64), |
| 177 | + ('dump_separator', POINTER(c_uint8)), |
| 178 | + ('data_codec_id', c_int), |
| 179 | + # ! one more in here? |
| 180 | + ('protocol_whitelist', c_char_p), |
| 181 | + ('io_open', CFUNCTYPE(c_int, POINTER(AVFormatContext), |
| 182 | + c_void_p, c_char_p, c_int, |
| 183 | + c_void_p)), |
| 184 | + ('io_close', CFUNCTYPE(None, POINTER(AVFormatContext), c_void_p)), |
| 185 | + ('protocol_blacklist', c_char_p), |
| 186 | + ('max_streams', c_int) |
| 187 | + ] |
| 188 | + |
| 189 | + |
| 190 | +read_packet_func = CFUNCTYPE(c_int, c_void_p, POINTER(c_uint8), c_int) |
0 commit comments