text:
# Automatically generated using Clang.jl wrap_c, version 0.0.0

import Base.zero

export
    unix,
    linux,
    AV_TIME_BASE,
    AV_NOPTS_VALUE,
    AV_FOURCC_MAX_STRING_SIZE,
    AVMediaType,
    AVMEDIA_TYPE_UNKNOWN,
    AVMEDIA_TYPE_VIDEO,
    AVMEDIA_TYPE_AUDIO,
    AVMEDIA_TYPE_DATA,
    AVMEDIA_TYPE_SUBTITLE,
    AVMEDIA_TYPE_ATTACHMENT,
    AVMEDIA_TYPE_NB,
    AVPictureType,
    AV_PICTURE_TYPE_NONE,
    AV_PICTURE_TYPE_I,
    AV_PICTURE_TYPE_P,
    AV_PICTURE_TYPE_B,
    AV_PICTURE_TYPE_S,
    AV_PICTURE_TYPE_SI,
    AV_PICTURE_TYPE_SP,
    AV_PICTURE_TYPE_BI,
    AV_BUFFER_FLAG_READONLY,
    AVBuffer,
    AVBufferRef,
    AVBufferPool,
    AV_DICT_MATCH_CASE,
    AV_DICT_IGNORE_SUFFIX,
    AV_DICT_DONT_STRDUP_KEY,
    AV_DICT_DONT_STRDUP_VAL,
    AV_DICT_DONT_OVERWRITE,
    AV_DICT_APPEND,
    AV_DICT_MULTIKEY,
    AVDictionaryEntry,
    AVDictionary,
    AVFifoBuffer,
    AV_NUM_DATA_POINTERS,
    AV_FRAME_FLAG_CORRUPT,
    AV_FRAME_FLAG_DISCARD,
    AVFrameSideDataType,
    AV_FRAME_DATA_PANSCAN,
    AV_FRAME_DATA_A53_CC,
    AV_FRAME_DATA_STEREO3D,
    AV_FRAME_DATA_MATRIXENCODING,
    AV_FRAME_DATA_DOWNMIX_INFO,
    AV_FRAME_DATA_REPLAYGAIN,
    AV_FRAME_DATA_DISPLAYMATRIX,
    AV_FRAME_DATA_AFD,
    AV_FRAME_DATA_MOTION_VECTORS,
    AV_FRAME_DATA_SKIP_SAMPLES,
    AV_FRAME_DATA_AUDIO_SERVICE_TYPE,
    AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
    AV_FRAME_DATA_GOP_TIMECODE,
    AV_FRAME_DATA_SPHERICAL,
    AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
    AV_FRAME_DATA_ICC_PROFILE,
    AV_FRAME_DATA_QP_TABLE_PROPERTIES,
    AV_FRAME_DATA_QP_TABLE_DATA,
    AV_FRAME_DATA_S12M_TIMECODE,
    AVActiveFormatDescription,
    AV_AFD_SAME,
    AV_AFD_4_3,
    AV_AFD_16_9,
    AV_AFD_14_9,
    AV_AFD_4_3_SP_14_9,
    AV_AFD_16_9_SP_14_9,
    AV_AFD_SP_4_3,
    AVFrameSideData,
    AVRational,
    AVColorRange,
    AVCOL_RANGE_UNSPECIFIED,
    AVCOL_RANGE_MPEG,
    AVCOL_RANGE_JPEG,
    AVCOL_RANGE_NB,
    AVColorPrimaries,
    AVCOL_PRI_RESERVED0,
    AVCOL_PRI_BT709,
    AVCOL_PRI_UNSPECIFIED,
    AVCOL_PRI_RESERVED,
    AVCOL_PRI_BT470M,
    AVCOL_PRI_BT470BG,
    AVCOL_PRI_SMPTE170M,
    AVCOL_PRI_SMPTE240M,
    AVCOL_PRI_FILM,
    AVCOL_PRI_BT2020,
    AVCOL_PRI_SMPTE428,
    AVCOL_PRI_SMPTEST428_1,
    AVCOL_PRI_SMPTE431,
    AVCOL_PRI_SMPTE432,
    AVCOL_PRI_JEDEC_P22,
    AVCOL_PRI_NB,
    AVColorTransferCharacteristic,
    AVCOL_TRC_RESERVED0,
    AVCOL_TRC_BT709,
    AVCOL_TRC_UNSPECIFIED,
    AVCOL_TRC_RESERVED,
    AVCOL_TRC_GAMMA22,
    AVCOL_TRC_GAMMA28,
    AVCOL_TRC_SMPTE170M,
    AVCOL_TRC_SMPTE240M,
    AVCOL_TRC_LINEAR,
    AVCOL_TRC_LOG,
    AVCOL_TRC_LOG_SQRT,
    AVCOL_TRC_IEC61966_2_4,
    AVCOL_TRC_BT1361_ECG,
    AVCOL_TRC_IEC61966_2_1,
    AVCOL_TRC_BT2020_10,
    AVCOL_TRC_BT2020_12,
    AVCOL_TRC_SMPTE2084,
    AVCOL_TRC_SMPTEST2084,
    AVCOL_TRC_SMPTE428,
    AVCOL_TRC_SMPTEST428_1,
    AVCOL_TRC_ARIB_STD_B67,
    AVCOL_TRC_NB,
    AVColorSpace,
    AVCOL_SPC_RGB,
    AVCOL_SPC_BT709,
    AVCOL_SPC_UNSPECIFIED,
    AVCOL_SPC_RESERVED,
    AVCOL_SPC_FCC,
    AVCOL_SPC_BT470BG,
    AVCOL_SPC_SMPTE170M,
    AVCOL_SPC_SMPTE240M,
    AVCOL_SPC_YCGCO,
    AVCOL_SPC_YCOCG,
    AVCOL_SPC_BT2020_NCL,
    AVCOL_SPC_BT2020_CL,
    AVCOL_SPC_SMPTE2085,
    AVCOL_SPC_CHROMA_DERIVED_NCL,
    AVCOL_SPC_CHROMA_DERIVED_CL,
    AVCOL_SPC_ICTCP,
    AVCOL_SPC_NB,
    AVChromaLocation,
    AVCHROMA_LOC_UNSPECIFIED,
    AVCHROMA_LOC_LEFT,
    AVCHROMA_LOC_CENTER,
    AVCHROMA_LOC_TOPLEFT,
    AVCHROMA_LOC_TOP,
    AVCHROMA_LOC_BOTTOMLEFT,
    AVCHROMA_LOC_BOTTOM,
    AVCHROMA_LOC_NB,
    AVFrame,
    ANONYMOUS_1,
    AV_FRAME_CROP_UNALIGNED,
    AV_LOG_QUIET,
    AV_LOG_PANIC,
    AV_LOG_FATAL,
    AV_LOG_ERROR,
    AV_LOG_WARNING,
    AV_LOG_INFO,
    AV_LOG_VERBOSE,
    AV_LOG_DEBUG,
    AV_LOG_TRACE,
    AV_LOG_MAX_OFFSET,
    AV_LOG_SKIP_REPEATED,
    AV_LOG_PRINT_LEVEL,
    ANONYMOUS_2,
    AV_CLASS_CATEGORY_NA,
    AV_CLASS_CATEGORY_INPUT,
    AV_CLASS_CATEGORY_OUTPUT,
    AV_CLASS_CATEGORY_MUXER,
    AV_CLASS_CATEGORY_DEMUXER,
    AV_CLASS_CATEGORY_ENCODER,
    AV_CLASS_CATEGORY_DECODER,
    AV_CLASS_CATEGORY_FILTER,
    AV_CLASS_CATEGORY_BITSTREAM_FILTER,
    AV_CLASS_CATEGORY_SWSCALER,
    AV_CLASS_CATEGORY_SWRESAMPLER,
    AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
    AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
    AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
    AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
    AV_CLASS_CATEGORY_DEVICE_OUTPUT,
    AV_CLASS_CATEGORY_DEVICE_INPUT,
    AV_CLASS_CATEGORY_NB,
    AVClassCategory,
    AVOptionRange,
    AVOptionRanges,
    AVOptionType,
    AV_OPT_TYPE_FLAGS,
    AV_OPT_TYPE_INT,
    AV_OPT_TYPE_INT64,
    AV_OPT_TYPE_DOUBLE,
    AV_OPT_TYPE_FLOAT,
    AV_OPT_TYPE_STRING,
    AV_OPT_TYPE_RATIONAL,
    AV_OPT_TYPE_BINARY,
    AV_OPT_TYPE_DICT,
    AV_OPT_TYPE_UINT64,
    AV_OPT_TYPE_CONST,
    AV_OPT_TYPE_IMAGE_SIZE,
    AV_OPT_TYPE_PIXEL_FMT,
    AV_OPT_TYPE_SAMPLE_FMT,
    AV_OPT_TYPE_VIDEO_RATE,
    AV_OPT_TYPE_DURATION,
    AV_OPT_TYPE_COLOR,
    AV_OPT_TYPE_CHANNEL_LAYOUT,
    AV_OPT_TYPE_BOOL,
    AVOption,
    AVClass,
    AV_PIX_FMT_FLAG_BE,
    AV_PIX_FMT_FLAG_PAL,
    AV_PIX_FMT_FLAG_BITSTREAM,
    AV_PIX_FMT_FLAG_HWACCEL,
    AV_PIX_FMT_FLAG_PLANAR,
    AV_PIX_FMT_FLAG_RGB,
    AV_PIX_FMT_FLAG_PSEUDOPAL,
    AV_PIX_FMT_FLAG_ALPHA,
    AV_PIX_FMT_FLAG_BAYER,
    AV_PIX_FMT_FLAG_FLOAT,
    AVComponentDescriptor,
    AVPixFmtDescriptor,
    AVPALETTE_SIZE,
    AVPALETTE_COUNT,
    AVPixelFormat,
    AV_PIX_FMT_NONE,
    AV_PIX_FMT_YUV420P,
    AV_PIX_FMT_YUYV422,
    AV_PIX_FMT_RGB24,
    AV_PIX_FMT_BGR24,
    AV_PIX_FMT_YUV422P,
    AV_PIX_FMT_YUV444P,
    AV_PIX_FMT_YUV410P,
    AV_PIX_FMT_YUV411P,
    AV_PIX_FMT_GRAY8,
    AV_PIX_FMT_MONOWHITE,
    AV_PIX_FMT_MONOBLACK,
    AV_PIX_FMT_PAL8,
    AV_PIX_FMT_YUVJ420P,
    AV_PIX_FMT_YUVJ422P,
    AV_PIX_FMT_YUVJ444P,
    AV_PIX_FMT_UYVY422,
    AV_PIX_FMT_UYYVYY411,
    AV_PIX_FMT_BGR8,
    AV_PIX_FMT_BGR4,
    AV_PIX_FMT_BGR4_BYTE,
    AV_PIX_FMT_RGB8,
    AV_PIX_FMT_RGB4,
    AV_PIX_FMT_RGB4_BYTE,
    AV_PIX_FMT_NV12,
    AV_PIX_FMT_NV21,
    AV_PIX_FMT_ARGB,
    AV_PIX_FMT_RGBA,
    AV_PIX_FMT_ABGR,
    AV_PIX_FMT_BGRA,
    AV_PIX_FMT_GRAY16BE,
    AV_PIX_FMT_GRAY16LE,
    AV_PIX_FMT_YUV440P,
    AV_PIX_FMT_YUVJ440P,
    AV_PIX_FMT_YUVA420P,
    AV_PIX_FMT_RGB48BE,
    AV_PIX_FMT_RGB48LE,
    AV_PIX_FMT_RGB565BE,
    AV_PIX_FMT_RGB565LE,
    AV_PIX_FMT_RGB555BE,
    AV_PIX_FMT_RGB555LE,
    AV_PIX_FMT_BGR565BE,
    AV_PIX_FMT_BGR565LE,
    AV_PIX_FMT_BGR555BE,
    AV_PIX_FMT_BGR555LE,
    AV_PIX_FMT_VAAPI_MOCO,
    AV_PIX_FMT_VAAPI_IDCT,
    AV_PIX_FMT_VAAPI_VLD,
    AV_PIX_FMT_VAAPI,
    AV_PIX_FMT_YUV420P16LE,
    AV_PIX_FMT_YUV420P16BE,
    AV_PIX_FMT_YUV422P16LE,
    AV_PIX_FMT_YUV422P16BE,
    AV_PIX_FMT_YUV444P16LE,
    AV_PIX_FMT_YUV444P16BE,
    AV_PIX_FMT_DXVA2_VLD,
    AV_PIX_FMT_RGB444LE,
    AV_PIX_FMT_RGB444BE,
    AV_PIX_FMT_BGR444LE,
    AV_PIX_FMT_BGR444BE,
    AV_PIX_FMT_YA8,
    AV_PIX_FMT_Y400A,
    AV_PIX_FMT_GRAY8A,
    AV_PIX_FMT_BGR48BE,
    AV_PIX_FMT_BGR48LE,
    AV_PIX_FMT_YUV420P9BE,
    AV_PIX_FMT_YUV420P9LE,
    AV_PIX_FMT_YUV420P10BE,
    AV_PIX_FMT_YUV420P10LE,
    AV_PIX_FMT_YUV422P10BE,
    AV_PIX_FMT_YUV422P10LE,
    AV_PIX_FMT_YUV444P9BE,
    AV_PIX_FMT_YUV444P9LE,
    AV_PIX_FMT_YUV444P10BE,
    AV_PIX_FMT_YUV444P10LE,
    AV_PIX_FMT_YUV422P9BE,
    AV_PIX_FMT_YUV422P9LE,
    AV_PIX_FMT_GBRP,
    AV_PIX_FMT_GBR24P,
    AV_PIX_FMT_GBRP9BE,
    AV_PIX_FMT_GBRP9LE,
    AV_PIX_FMT_GBRP10BE,
    AV_PIX_FMT_GBRP10LE,
    AV_PIX_FMT_GBRP16BE,
    AV_PIX_FMT_GBRP16LE,
    AV_PIX_FMT_YUVA422P,
    AV_PIX_FMT_YUVA444P,
    AV_PIX_FMT_YUVA420P9BE,
    AV_PIX_FMT_YUVA420P9LE,
    AV_PIX_FMT_YUVA422P9BE,
    AV_PIX_FMT_YUVA422P9LE,
    AV_PIX_FMT_YUVA444P9BE,
    AV_PIX_FMT_YUVA444P9LE,
    AV_PIX_FMT_YUVA420P10BE,
    AV_PIX_FMT_YUVA420P10LE,
    AV_PIX_FMT_YUVA422P10BE,
    AV_PIX_FMT_YUVA422P10LE,
    AV_PIX_FMT_YUVA444P10BE,
    AV_PIX_FMT_YUVA444P10LE,
    AV_PIX_FMT_YUVA420P16BE,
    AV_PIX_FMT_YUVA420P16LE,
    AV_PIX_FMT_YUVA422P16BE,
    AV_PIX_FMT_YUVA422P16LE,
    AV_PIX_FMT_YUVA444P16BE,
    AV_PIX_FMT_YUVA444P16LE,
    AV_PIX_FMT_VDPAU,
    AV_PIX_FMT_XYZ12LE,
    AV_PIX_FMT_XYZ12BE,
    AV_PIX_FMT_NV16,
    AV_PIX_FMT_NV20LE,
    AV_PIX_FMT_NV20BE,
    AV_PIX_FMT_RGBA64BE,
    AV_PIX_FMT_RGBA64LE,
    AV_PIX_FMT_BGRA64BE,
    AV_PIX_FMT_BGRA64LE,
    AV_PIX_FMT_YVYU422,
    AV_PIX_FMT_YA16BE,
    AV_PIX_FMT_YA16LE,
    AV_PIX_FMT_GBRAP,
    AV_PIX_FMT_GBRAP16BE,
    AV_PIX_FMT_GBRAP16LE,
    AV_PIX_FMT_QSV,
    AV_PIX_FMT_MMAL,
    AV_PIX_FMT_D3D11VA_VLD,
    AV_PIX_FMT_CUDA,
    AV_PIX_FMT_0RGB,
    AV_PIX_FMT_RGB0,
    AV_PIX_FMT_0BGR,
    AV_PIX_FMT_BGR0,
    AV_PIX_FMT_YUV420P12BE,
    AV_PIX_FMT_YUV420P12LE,
    AV_PIX_FMT_YUV420P14BE,
    AV_PIX_FMT_YUV420P14LE,
    AV_PIX_FMT_YUV422P12BE,
    AV_PIX_FMT_YUV422P12LE,
    AV_PIX_FMT_YUV422P14BE,
    AV_PIX_FMT_YUV422P14LE,
    AV_PIX_FMT_YUV444P12BE,
    AV_PIX_FMT_YUV444P12LE,
    AV_PIX_FMT_YUV444P14BE,
    AV_PIX_FMT_YUV444P14LE,
    AV_PIX_FMT_GBRP12BE,
    AV_PIX_FMT_GBRP12LE,
    AV_PIX_FMT_GBRP14BE,
    AV_PIX_FMT_GBRP14LE,
    AV_PIX_FMT_YUVJ411P,
    AV_PIX_FMT_BAYER_BGGR8,
    AV_PIX_FMT_BAYER_RGGB8,
    AV_PIX_FMT_BAYER_GBRG8,
    AV_PIX_FMT_BAYER_GRBG8,
    AV_PIX_FMT_BAYER_BGGR16LE,
    AV_PIX_FMT_BAYER_BGGR16BE,
    AV_PIX_FMT_BAYER_RGGB16LE,
    AV_PIX_FMT_BAYER_RGGB16BE,
    AV_PIX_FMT_BAYER_GBRG16LE,
    AV_PIX_FMT_BAYER_GBRG16BE,
    AV_PIX_FMT_BAYER_GRBG16LE,
    AV_PIX_FMT_BAYER_GRBG16BE,
    AV_PIX_FMT_XVMC,
    AV_PIX_FMT_YUV440P10LE,
    AV_PIX_FMT_YUV440P10BE,
    AV_PIX_FMT_YUV440P12LE,
    AV_PIX_FMT_YUV440P12BE,
    AV_PIX_FMT_AYUV64LE,
    AV_PIX_FMT_AYUV64BE,
    AV_PIX_FMT_VIDEOTOOLBOX,
    AV_PIX_FMT_P010LE,
    AV_PIX_FMT_P010BE,
    AV_PIX_FMT_GBRAP12BE,
    AV_PIX_FMT_GBRAP12LE,
    AV_PIX_FMT_GBRAP10BE,
    AV_PIX_FMT_GBRAP10LE,
    AV_PIX_FMT_MEDIACODEC,
    AV_PIX_FMT_GRAY12BE,
    AV_PIX_FMT_GRAY12LE,
    AV_PIX_FMT_GRAY10BE,
    AV_PIX_FMT_GRAY10LE,
    AV_PIX_FMT_P016LE,
    AV_PIX_FMT_P016BE,
    AV_PIX_FMT_D3D11,
    AV_PIX_FMT_GRAY9BE,
    AV_PIX_FMT_GRAY9LE,
    AV_PIX_FMT_GBRPF32BE,
    AV_PIX_FMT_GBRPF32LE,
    AV_PIX_FMT_GBRAPF32BE,
    AV_PIX_FMT_GBRAPF32LE,
    AV_PIX_FMT_DRM_PRIME,
    AV_PIX_FMT_OPENCL,
    AV_PIX_FMT_GRAY14BE,
    AV_PIX_FMT_GRAY14LE,
    AV_PIX_FMT_GRAYF32BE,
    AV_PIX_FMT_GRAYF32LE,
    AV_PIX_FMT_NB,
    AVSampleFormat,
    AV_SAMPLE_FMT_NONE,
    AV_SAMPLE_FMT_U8,
    AV_SAMPLE_FMT_S16,
    AV_SAMPLE_FMT_S32,
    AV_SAMPLE_FMT_FLT,
    AV_SAMPLE_FMT_DBL,
    AV_SAMPLE_FMT_U8P,
    AV_SAMPLE_FMT_S16P,
    AV_SAMPLE_FMT_S32P,
    AV_SAMPLE_FMT_FLTP,
    AV_SAMPLE_FMT_DBLP,
    AV_SAMPLE_FMT_S64,
    AV_SAMPLE_FMT_S64P,
    AV_SAMPLE_FMT_NB,
    LIBAVUTIL_VERSION_MAJOR,
    LIBAVUTIL_VERSION_MINOR,
    LIBAVUTIL_VERSION_MICRO,
    LIBAVUTIL_BUILD,
    AES_CTR_KEY_SIZE,
    AES_CTR_IV_SIZE,
    AVAESCTR,
    AVAudioFifo,
    AVCAMELLIA,
    AVCAST5,
    AV_CH_FRONT_LEFT,
    AV_CH_FRONT_RIGHT,
    AV_CH_FRONT_CENTER,
    AV_CH_LOW_FREQUENCY,
    AV_CH_BACK_LEFT,
    AV_CH_BACK_RIGHT,
    AV_CH_FRONT_LEFT_OF_CENTER,
    AV_CH_FRONT_RIGHT_OF_CENTER,
    AV_CH_BACK_CENTER,
    AV_CH_SIDE_LEFT,
    AV_CH_SIDE_RIGHT,
    AV_CH_TOP_CENTER,
    AV_CH_TOP_FRONT_LEFT,
    AV_CH_TOP_FRONT_CENTER,
    AV_CH_TOP_FRONT_RIGHT,
    AV_CH_TOP_BACK_LEFT,
    AV_CH_TOP_BACK_CENTER,
    AV_CH_TOP_BACK_RIGHT,
    AV_CH_STEREO_LEFT,
    AV_CH_STEREO_RIGHT,
    AV_CH_WIDE_LEFT,
    AV_CH_WIDE_RIGHT,
    AV_CH_SURROUND_DIRECT_LEFT,
    AV_CH_SURROUND_DIRECT_RIGHT,
    AV_CH_LOW_FREQUENCY_2,
    AV_CH_LAYOUT_NATIVE,
    AV_CH_LAYOUT_MONO,
    AV_CH_LAYOUT_STEREO,
    AV_CH_LAYOUT_2POINT1,
    AV_CH_LAYOUT_2_1,
    AV_CH_LAYOUT_SURROUND,
    AV_CH_LAYOUT_3POINT1,
    AV_CH_LAYOUT_4POINT0,
    AV_CH_LAYOUT_4POINT1,
    AV_CH_LAYOUT_2_2,
    AV_CH_LAYOUT_QUAD,
    AV_CH_LAYOUT_5POINT0,
    AV_CH_LAYOUT_5POINT1,
    AV_CH_LAYOUT_5POINT0_BACK,
    AV_CH_LAYOUT_5POINT1_BACK,
    AV_CH_LAYOUT_6POINT0,
    AV_CH_LAYOUT_6POINT0_FRONT,
    AV_CH_LAYOUT_HEXAGONAL,
    AV_CH_LAYOUT_6POINT1,
    AV_CH_LAYOUT_6POINT1_BACK,
    AV_CH_LAYOUT_6POINT1_FRONT,
    AV_CH_LAYOUT_7POINT0,
    AV_CH_LAYOUT_7POINT0_FRONT,
    AV_CH_LAYOUT_7POINT1,
    AV_CH_LAYOUT_7POINT1_WIDE,
    AV_CH_LAYOUT_7POINT1_WIDE_BACK,
    AV_CH_LAYOUT_OCTAGONAL,
    AV_CH_LAYOUT_HEXADECAGONAL,
    AV_CH_LAYOUT_STEREO_DOWNMIX,
    AVMatrixEncoding,
    AV_MATRIX_ENCODING_NONE,
    AV_MATRIX_ENCODING_DOLBY,
    AV_MATRIX_ENCODING_DPLII,
    AV_MATRIX_ENCODING_DPLIIX,
    AV_MATRIX_ENCODING_DPLIIZ,
    AV_MATRIX_ENCODING_DOLBYEX,
    AV_MATRIX_ENCODING_DOLBYHEADPHONE,
    AV_MATRIX_ENCODING_NB,
    AVBPrint,
    AVDES,
    AVDownmixType,
    AV_DOWNMIX_TYPE_UNKNOWN,
    AV_DOWNMIX_TYPE_LORO,
    AV_DOWNMIX_TYPE_LTRT,
    AV_DOWNMIX_TYPE_DPLII,
    AV_DOWNMIX_TYPE_NB,
    AVDownmixInfo,
    AVSubsampleEncryptionInfo,
    AVEncryptionInfo,
    AVEncryptionInitInfo,
    AV_HASH_MAX_SIZE,
    AVHashContext,
    AVHWDeviceType,
    AV_HWDEVICE_TYPE_NONE,
    AV_HWDEVICE_TYPE_VDPAU,
    AV_HWDEVICE_TYPE_CUDA,
    AV_HWDEVICE_TYPE_VAAPI,
    AV_HWDEVICE_TYPE_DXVA2,
    AV_HWDEVICE_TYPE_QSV,
    AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
    AV_HWDEVICE_TYPE_D3D11VA,
    AV_HWDEVICE_TYPE_DRM,
    AV_HWDEVICE_TYPE_OPENCL,
    AV_HWDEVICE_TYPE_MEDIACODEC,
    AVHWDeviceInternal,
    AVHWDeviceContext,
    AVHWFramesInternal,
    AVHWFramesContext,
    AVHWFrameTransferDirection,
    AV_HWFRAME_TRANSFER_DIRECTION_FROM,
    AV_HWFRAME_TRANSFER_DIRECTION_TO,
    AVHWFramesConstraints,
    ANONYMOUS_3,
    AV_HWFRAME_MAP_READ,
    AV_HWFRAME_MAP_WRITE,
    AV_HWFRAME_MAP_OVERWRITE,
    AV_HWFRAME_MAP_DIRECT,
    AVCUDADeviceContextInternal,
    AVCUDADeviceContext,
    AVD3D11VADeviceContext,
    AVD3D11FrameDescriptor,
    AVD3D11VAFramesContext,
    ANONYMOUS_4,
    AV_DRM_MAX_PLANES,
    AVDRMObjectDescriptor,
    AVDRMPlaneDescriptor,
    AVDRMLayerDescriptor,
    AVDRMFrameDescriptor,
    AVDRMDeviceContext,
    AVDXVA2DeviceContext,
    AVDXVA2FramesContext,
    AVMediaCodecDeviceContext,
    AVQSVDeviceContext,
    AVQSVFramesContext,
    ANONYMOUS_5,
    AV_VAAPI_DRIVER_QUIRK_USER_SET,
    AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
    AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
    AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
    # AVVAAPIDeviceContext,
    # AVVAAPIFramesContext,
    # AVVAAPIHWConfig,
    # AVVDPAUDeviceContext,
    AVMasteringDisplayMetadata,
    AVContentLightMetadata,
    AVMotionVector,
    AV_OPT_FLAG_ENCODING_PARAM,
    AV_OPT_FLAG_DECODING_PARAM,
    AV_OPT_FLAG_AUDIO_PARAM,
    AV_OPT_FLAG_VIDEO_PARAM,
    AV_OPT_FLAG_SUBTITLE_PARAM,
    AV_OPT_FLAG_EXPORT,
    AV_OPT_FLAG_READONLY,
    AV_OPT_FLAG_BSF_PARAM,
    AV_OPT_FLAG_FILTERING_PARAM,
    AV_OPT_FLAG_DEPRECATED,
    AV_OPT_SEARCH_CHILDREN,
    AV_OPT_SEARCH_FAKE_OBJ,
    AV_OPT_ALLOW_NULL,
    AV_OPT_MULTI_COMPONENT_RANGE,
    AV_OPT_SERIALIZE_SKIP_DEFAULTS,
    AV_OPT_SERIALIZE_OPT_FLAGS_EXACT,
    ANONYMOUS_6,
    AV_OPT_FLAG_IMPLICIT_KEY,
    av_pixelutils_sad_fn,
    AVRC4,
    AVReplayGain,
    AVSphericalProjection,
    AV_SPHERICAL_EQUIRECTANGULAR,
    AV_SPHERICAL_CUBEMAP,
    AV_SPHERICAL_EQUIRECTANGULAR_TILE,
    AVSphericalMapping,
    AV_STEREO3D_FLAG_INVERT,
    AVStereo3DType,
    AV_STEREO3D_2D,
    AV_STEREO3D_SIDEBYSIDE,
    AV_STEREO3D_TOPBOTTOM,
    AV_STEREO3D_FRAMESEQUENCE,
    AV_STEREO3D_CHECKERBOARD,
    AV_STEREO3D_SIDEBYSIDE_QUINCUNX,
    AV_STEREO3D_LINES,
    AV_STEREO3D_COLUMNS,
    AVStereo3DView,
    AV_STEREO3D_VIEW_PACKED,
    AV_STEREO3D_VIEW_LEFT,
    AV_STEREO3D_VIEW_RIGHT,
    AVStereo3D,
    AVTEA,
    AVThreadMessageQueue,
    AVThreadMessageFlags,
    AV_THREAD_MESSAGE_NONBLOCK,
    AV_TIMECODE_STR_SIZE,
    AVTimecodeFlag,
    AV_TIMECODE_FLAG_DROPFRAME,
    AV_TIMECODE_FLAG_24HOURSMAX,
    AV_TIMECODE_FLAG_ALLOWNEGATIVE,
    AVTimecode,
    AVTreeNode,
    AVTWOFISH,
    AVXTEA

const unix = 1
const linux = 1
const FF_LAMBDA_SHIFT = 7
const FF_LAMBDA_SCALE = 1 << FF_LAMBDA_SHIFT
const FF_QP2LAMBDA = 118
const FF_LAMBDA_MAX = 256 * 128 - 1
const FF_QUALITY_SCALE = FF_LAMBDA_SCALE

const AV_NOPTS_VALUE  =  reinterpret(Int64, 0x8000000000000000)

const AV_TIME_BASE = 1000000

struct AVRational
    num::Cint
    den::Cint
end

zero(::Type{AVRational}) = AVRational(0, 1)

const AV_TIME_BASE_Q  =  AVRational(1, AV_TIME_BASE)

# Skipping MacroDefinition: av_int_list_length ( list , term ) av_int_list_length_for_size ( sizeof ( * ( list ) ) , list , term )

const AV_FOURCC_MAX_STRING_SIZE = 32

# Skipping MacroDefinition: av_fourcc2str ( fourcc ) av_fourcc_make_string ( ( char [ AV_FOURCC_MAX_STRING_SIZE ] ) { 0 } , fourcc )

# begin enum AVMediaType
const AVMediaType = Cint
const AVMEDIA_TYPE_UNKNOWN = -1 |> Int32
const AVMEDIA_TYPE_VIDEO = 0 |> Int32
const AVMEDIA_TYPE_AUDIO = 1 |> Int32
const AVMEDIA_TYPE_DATA = 2 |> Int32
const AVMEDIA_TYPE_SUBTITLE = 3 |> Int32
const AVMEDIA_TYPE_ATTACHMENT = 4 |> Int32
const AVMEDIA_TYPE_NB = 5 |> Int32
# end enum AVMediaType

# begin enum AVPictureType
const AVPictureType = UInt32
const AV_PICTURE_TYPE_NONE = 0 |> UInt32
const AV_PICTURE_TYPE_I = 1 |> UInt32
const AV_PICTURE_TYPE_P = 2 |> UInt32
const AV_PICTURE_TYPE_B = 3 |> UInt32
const AV_PICTURE_TYPE_S = 4 |> UInt32
const AV_PICTURE_TYPE_SI = 5 |> UInt32
const AV_PICTURE_TYPE_SP = 6 |> UInt32
const AV_PICTURE_TYPE_BI = 7 |> UInt32
# end enum AVPictureType

const AV_BUFFER_FLAG_READONLY = 1 << 0

struct AVBuffer
end

struct AVBufferRef
    buffer::Ptr{AVBuffer}
    data::Ptr{UInt8}
    size::Cint
end

struct AVBufferPool
end

const AV_DICT_MATCH_CASE = 1
const AV_DICT_IGNORE_SUFFIX = 2
const AV_DICT_DONT_STRDUP_KEY = 4
const AV_DICT_DONT_STRDUP_VAL = 8
const AV_DICT_DONT_OVERWRITE = 16
const AV_DICT_APPEND = 32
const AV_DICT_MULTIKEY = 64

struct AVDictionaryEntry
    key::Cstring
    value::Cstring
end

struct AVDictionary
end

struct AVFifoBuffer
    buffer::Ptr{UInt8}
    rptr::Ptr{UInt8}
    wptr::Ptr{UInt8}
    _end::Ptr{UInt8}
    rndx::UInt32
    wndx::UInt32
end

const AV_NUM_DATA_POINTERS = 8
const AV_FRAME_FLAG_CORRUPT = 1 << 0
const AV_FRAME_FLAG_DISCARD = 1 << 2
const FF_DECODE_ERROR_INVALID_BITSTREAM = 1
const FF_DECODE_ERROR_MISSING_REFERENCE = 2

# begin enum AVFrameSideDataType
const AVFrameSideDataType = UInt32
const AV_FRAME_DATA_PANSCAN = 0 |> UInt32
const AV_FRAME_DATA_A53_CC = 1 |> UInt32
const AV_FRAME_DATA_STEREO3D = 2 |> UInt32
const AV_FRAME_DATA_MATRIXENCODING = 3 |> UInt32
const AV_FRAME_DATA_DOWNMIX_INFO = 4 |> UInt32
const AV_FRAME_DATA_REPLAYGAIN = 5 |> UInt32
const AV_FRAME_DATA_DISPLAYMATRIX = 6 |> UInt32
const AV_FRAME_DATA_AFD = 7 |> UInt32
const AV_FRAME_DATA_MOTION_VECTORS = 8 |> UInt32
const AV_FRAME_DATA_SKIP_SAMPLES = 9 |> UInt32
const AV_FRAME_DATA_AUDIO_SERVICE_TYPE = 10 |> UInt32
const AV_FRAME_DATA_MASTERING_DISPLAY_METADATA = 11 |> UInt32
const AV_FRAME_DATA_GOP_TIMECODE = 12 |> UInt32
const AV_FRAME_DATA_SPHERICAL = 13 |> UInt32
const AV_FRAME_DATA_CONTENT_LIGHT_LEVEL = 14 |> UInt32
const AV_FRAME_DATA_ICC_PROFILE = 15 |> UInt32
const AV_FRAME_DATA_QP_TABLE_PROPERTIES = 16 |> UInt32
const AV_FRAME_DATA_QP_TABLE_DATA = 17 |> UInt32
const AV_FRAME_DATA_S12M_TIMECODE = 18 |> UInt32
# end enum AVFrameSideDataType

# begin enum AVActiveFormatDescription
const AVActiveFormatDescription = UInt32
const AV_AFD_SAME = 8 |> UInt32
const AV_AFD_4_3 = 9 |> UInt32
const AV_AFD_16_9 = 10 |> UInt32
const AV_AFD_14_9 = 11 |> UInt32
const AV_AFD_4_3_SP_14_9 = 13 |> UInt32
const AV_AFD_16_9_SP_14_9 = 14 |> UInt32
const AV_AFD_SP_4_3 = 15 |> UInt32
# end enum AVActiveFormatDescription

struct AVFrameSideData
    _type::AVFrameSideDataType
    data::Ptr{UInt8}
    size::Cint
    metadata::Ptr{AVDictionary}
    buf::Ptr{AVBufferRef}
end

# begin enum AVColorRange
const AVColorRange = UInt32
const AVCOL_RANGE_UNSPECIFIED = 0 |> UInt32
const AVCOL_RANGE_MPEG = 1 |> UInt32
const AVCOL_RANGE_JPEG = 2 |> UInt32
const AVCOL_RANGE_NB = 3 |> UInt32
# end enum AVColorRange

# begin enum AVColorPrimaries
const AVColorPrimaries = UInt32
const AVCOL_PRI_RESERVED0 = 0 |> UInt32
const AVCOL_PRI_BT709 = 1 |> UInt32
const AVCOL_PRI_UNSPECIFIED = 2 |> UInt32
const AVCOL_PRI_RESERVED = 3 |> UInt32
const AVCOL_PRI_BT470M = 4 |> UInt32
const AVCOL_PRI_BT470BG = 5 |> UInt32
const AVCOL_PRI_SMPTE170M = 6 |> UInt32
const AVCOL_PRI_SMPTE240M = 7 |> UInt32
const AVCOL_PRI_FILM = 8 |> UInt32
const AVCOL_PRI_BT2020 = 9 |> UInt32
const AVCOL_PRI_SMPTE428 = 10 |> UInt32
const AVCOL_PRI_SMPTEST428_1 = 10 |> UInt32
const AVCOL_PRI_SMPTE431 = 11 |> UInt32
const AVCOL_PRI_SMPTE432 = 12 |> UInt32
const AVCOL_PRI_JEDEC_P22 = 22 |> UInt32
const AVCOL_PRI_NB = 23 |> UInt32
# end enum AVColorPrimaries

# begin enum AVColorTransferCharacteristic
const AVColorTransferCharacteristic = UInt32
const AVCOL_TRC_RESERVED0 = 0 |> UInt32
const AVCOL_TRC_BT709 = 1 |> UInt32
const AVCOL_TRC_UNSPECIFIED = 2 |> UInt32
const AVCOL_TRC_RESERVED = 3 |> UInt32
const AVCOL_TRC_GAMMA22 = 4 |> UInt32
const AVCOL_TRC_GAMMA28 = 5 |> UInt32
const AVCOL_TRC_SMPTE170M = 6 |> UInt32
const AVCOL_TRC_SMPTE240M = 7 |> UInt32
const AVCOL_TRC_LINEAR = 8 |> UInt32
const AVCOL_TRC_LOG = 9 |> UInt32
const AVCOL_TRC_LOG_SQRT = 10 |> UInt32
const AVCOL_TRC_IEC61966_2_4 = 11 |> UInt32
const AVCOL_TRC_BT1361_ECG = 12 |> UInt32
const AVCOL_TRC_IEC61966_2_1 = 13 |> UInt32
const AVCOL_TRC_BT2020_10 = 14 |> UInt32
const AVCOL_TRC_BT2020_12 = 15 |> UInt32
const AVCOL_TRC_SMPTE2084 = 16 |> UInt32
const AVCOL_TRC_SMPTEST2084 = 16 |> UInt32
const AVCOL_TRC_SMPTE428 = 17 |> UInt32
const AVCOL_TRC_SMPTEST428_1 = 17 |> UInt32
const AVCOL_TRC_ARIB_STD_B67 = 18 |> UInt32
const AVCOL_TRC_NB = 19 |> UInt32
# end enum AVColorTransferCharacteristic

# begin enum AVColorSpace
const AVColorSpace = UInt32
const AVCOL_SPC_RGB = 0 |> UInt32
const AVCOL_SPC_BT709 = 1 |> UInt32
const AVCOL_SPC_UNSPECIFIED = 2 |> UInt32
const AVCOL_SPC_RESERVED = 3 |> UInt32
const AVCOL_SPC_FCC = 4 |> UInt32
const AVCOL_SPC_BT470BG = 5 |> UInt32
const AVCOL_SPC_SMPTE170M = 6 |> UInt32
const AVCOL_SPC_SMPTE240M = 7 |> UInt32
const AVCOL_SPC_YCGCO = 8 |> UInt32
const AVCOL_SPC_YCOCG = 8 |> UInt32
const AVCOL_SPC_BT2020_NCL = 9 |> UInt32
const AVCOL_SPC_BT2020_CL = 10 |> UInt32
const AVCOL_SPC_SMPTE2085 = 11 |> UInt32
const AVCOL_SPC_CHROMA_DERIVED_NCL = 12 |> UInt32
const AVCOL_SPC_CHROMA_DERIVED_CL = 13 |> UInt32
const AVCOL_SPC_ICTCP = 14 |> UInt32
const AVCOL_SPC_NB = 15 |> UInt32
# end enum AVColorSpace

# begin enum AVChromaLocation
const AVChromaLocation = UInt32
const AVCHROMA_LOC_UNSPECIFIED = 0 |> UInt32
const AVCHROMA_LOC_LEFT = 1 |> UInt32
const AVCHROMA_LOC_CENTER = 2 |> UInt32
const AVCHROMA_LOC_TOPLEFT = 3 |> UInt32
const AVCHROMA_LOC_TOP = 4 |> UInt32
const AVCHROMA_LOC_BOTTOMLEFT = 5 |> UInt32
const AVCHROMA_LOC_BOTTOM = 6 |> UInt32
const AVCHROMA_LOC_NB = 7 |> UInt32
# end enum AVChromaLocation

zero(::Type{NTuple{N,P}}) where {N,P<:Ptr} = (N == 1 ? (C_NULL,) : (zero(NTuple{N-1,P})..., C_NULL))
zero(::Type{NTuple{N,T}}) where {N,T} = (N == 1 ? (zero(T),) : (zero(NTuple{N-1,T})..., zero(T)))

struct AVFrame
    data::NTuple{8, Ptr{UInt8}}
    linesize::NTuple{8, Cint}
    extended_data::Ptr{Ptr{UInt8}}
    width::Cint
    height::Cint
    nb_samples::Cint
    format::Cint
    key_frame::Cint
    pict_type::AVPictureType
    sample_aspect_ratio::AVRational
    pts::Int64
    pkt_pts::Int64
    pkt_dts::Int64
    coded_picture_number::Cint
    display_picture_number::Cint
    quality::Cint
    opaque::Ptr{Cvoid}
    error::NTuple{8, UInt64}
    repeat_pict::Cint
    interlaced_frame::Cint
    top_field_first::Cint
    palette_has_changed::Cint
    reordered_opaque::Int64
    sample_rate::Cint
    channel_layout::UInt64
    buf::NTuple{8, Ptr{AVBufferRef}}
    extended_buf::Ptr{Ptr{AVBufferRef}}
    nb_extended_buf::Cint
    side_data::Ptr{Ptr{AVFrameSideData}}
    nb_side_data::Cint
    flags::Cint
    color_range::AVColorRange
    color_primaries::AVColorPrimaries
    color_trc::AVColorTransferCharacteristic
    colorspace::AVColorSpace
    chroma_location::AVChromaLocation
    best_effort_timestamp::Int64
    pkt_pos::Int64
    pkt_duration::Int64
    metadata::Ptr{AVDictionary}
    decode_error_flags::Cint
    channels::Cint
    pkt_size::Cint
    qscale_table::Ptr{Int8}
    qstride::Cint
    qscale_type::Cint
    qp_table_buf::Ptr{AVBufferRef}
    hw_frames_ctx::Ptr{AVBufferRef}
    opaque_ref::Ptr{AVBufferRef}
    crop_top::Csize_t
    crop_bottom::Csize_t
    crop_left::Csize_t
    crop_right::Csize_t
    private_ref::Ptr{AVBufferRef}
end

# begin enum ANONYMOUS_1
const ANONYMOUS_1 = UInt32
const AV_FRAME_CROP_UNALIGNED = 1 |> UInt32
# end enum ANONYMOUS_1

# Skipping MacroDefinition: AV_IS_INPUT_DEVICE ( category ) ( ( ( category ) == AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ) || ( ( category ) == AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ) || ( ( category ) == AV_CLASS_CATEGORY_DEVICE_INPUT ) )
# Skipping MacroDefinition: AV_IS_OUTPUT_DEVICE ( category ) ( ( ( category ) == AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT ) || ( ( category ) == AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ) || ( ( category ) == AV_CLASS_CATEGORY_DEVICE_OUTPUT ) )

const AV_LOG_QUIET = -8
const AV_LOG_PANIC = 0
const AV_LOG_FATAL = 8
const AV_LOG_ERROR = 16
const AV_LOG_WARNING = 24
const AV_LOG_INFO = 32
const AV_LOG_VERBOSE = 40
const AV_LOG_DEBUG = 48
const AV_LOG_TRACE = 56
const AV_LOG_MAX_OFFSET = AV_LOG_TRACE - AV_LOG_QUIET

# Skipping MacroDefinition: AV_LOG_C ( x ) ( ( x ) << 8 )

const AV_LOG_SKIP_REPEATED = 1
const AV_LOG_PRINT_LEVEL = 2

# begin enum ANONYMOUS_2
const ANONYMOUS_2 = UInt32
const AV_CLASS_CATEGORY_NA = 0 |> UInt32
const AV_CLASS_CATEGORY_INPUT = 1 |> UInt32
const AV_CLASS_CATEGORY_OUTPUT = 2 |> UInt32
const AV_CLASS_CATEGORY_MUXER = 3 |> UInt32
const AV_CLASS_CATEGORY_DEMUXER = 4 |> UInt32
const AV_CLASS_CATEGORY_ENCODER = 5 |> UInt32
const AV_CLASS_CATEGORY_DECODER = 6 |> UInt32
const AV_CLASS_CATEGORY_FILTER = 7 |> UInt32
const AV_CLASS_CATEGORY_BITSTREAM_FILTER = 8 |> UInt32
const AV_CLASS_CATEGORY_SWSCALER = 9 |> UInt32
const AV_CLASS_CATEGORY_SWRESAMPLER = 10 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT = 40 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT = 41 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT = 42 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT = 43 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_OUTPUT = 44 |> UInt32
const AV_CLASS_CATEGORY_DEVICE_INPUT = 45 |> UInt32
const AV_CLASS_CATEGORY_NB = 46 |> UInt32
# end enum ANONYMOUS_2

const AVClassCategory = Cint

struct AVOptionRange
    str::Cstring
    value_min::Cdouble
    value_max::Cdouble
    component_min::Cdouble
    component_max::Cdouble
    is_range::Cint
end

struct AVOptionRanges
    range::Ptr{Ptr{AVOptionRange}}
    nb_ranges::Cint
    nb_components::Cint
end

# begin enum AVOptionType
const AVOptionType = UInt32
const AV_OPT_TYPE_FLAGS = 0 |> UInt32
const AV_OPT_TYPE_INT = 1 |> UInt32
const AV_OPT_TYPE_INT64 = 2 |> UInt32
const AV_OPT_TYPE_DOUBLE = 3 |> UInt32
const AV_OPT_TYPE_FLOAT = 4 |> UInt32
const AV_OPT_TYPE_STRING = 5 |> UInt32
const AV_OPT_TYPE_RATIONAL = 6 |> UInt32
const AV_OPT_TYPE_BINARY = 7 |> UInt32
const AV_OPT_TYPE_DICT = 8 |> UInt32
const AV_OPT_TYPE_UINT64 = 9 |> UInt32
const AV_OPT_TYPE_CONST = 10 |> UInt32
const AV_OPT_TYPE_IMAGE_SIZE = 11 |> UInt32
const AV_OPT_TYPE_PIXEL_FMT = 12 |> UInt32
const AV_OPT_TYPE_SAMPLE_FMT = 13 |> UInt32
const AV_OPT_TYPE_VIDEO_RATE = 14 |> UInt32
const AV_OPT_TYPE_DURATION = 15 |> UInt32
const AV_OPT_TYPE_COLOR = 16 |> UInt32
const AV_OPT_TYPE_CHANNEL_LAYOUT = 17 |> UInt32
const AV_OPT_TYPE_BOOL = 18 |> UInt32
# end enum AVOptionType

struct AVOption
    name::Cstring
    help::Cstring
    offset::Cint
    _type::AVOptionType
    default_val::Int64
    min::Cdouble
    max::Cdouble
    flags::Cint
    unit::Cstring
end

struct AVClass
    class_name::Cstring
    item_name::Ptr{Cvoid}
    option::Ptr{AVOption}
    version::Cint
    log_level_offset_offset::Cint
    parent_log_context_offset::Cint
    child_next::Ptr{Cvoid}
    child_class_next::Ptr{Cvoid}
    category::AVClassCategory
    get_category::Ptr{Cvoid}
    query_ranges::Ptr{Cvoid}
end

# Skipping MacroDefinition: DECLARE_ALIGNED ( n , t , v ) t __attribute__ ( ( aligned ( n ) ) ) v
# Skipping MacroDefinition: DECLARE_ASM_ALIGNED ( n , t , v ) t av_used __attribute__ ( ( aligned ( n ) ) ) v
# Skipping MacroDefinition: DECLARE_ASM_CONST ( n , t , v ) static const t av_used __attribute__ ( ( aligned ( n ) ) ) v
# Skipping MacroDefinition: av_malloc_attrib __attribute__ ( ( __malloc__ ) )
# Skipping MacroDefinition: av_alloc_size ( ... )

const AV_PIX_FMT_FLAG_BE = 1 << 0
const AV_PIX_FMT_FLAG_PAL = 1 << 1
const AV_PIX_FMT_FLAG_BITSTREAM = 1 << 2
const AV_PIX_FMT_FLAG_HWACCEL = 1 << 3
const AV_PIX_FMT_FLAG_PLANAR = 1 << 4
const AV_PIX_FMT_FLAG_RGB = 1 << 5
const AV_PIX_FMT_FLAG_PSEUDOPAL = 1 << 6
const AV_PIX_FMT_FLAG_ALPHA = 1 << 7
const AV_PIX_FMT_FLAG_BAYER = 1 << 8
const AV_PIX_FMT_FLAG_FLOAT = 1 << 9
const FF_LOSS_RESOLUTION = 0x0001
const FF_LOSS_DEPTH = 0x0002
const FF_LOSS_COLORSPACE = 0x0004
const FF_LOSS_ALPHA = 0x0008
const FF_LOSS_COLORQUANT = 0x0010
const FF_LOSS_CHROMA = 0x0020

struct AVComponentDescriptor
    plane::Cint
    step::Cint
    offset::Cint
    shift::Cint
    depth::Cint
    step_minus1::Cint
    depth_minus1::Cint
    offset_plus1::Cint
end

struct AVPixFmtDescriptor
    name::Cstring
    nb_components::UInt8
    log2_chroma_w::UInt8
    log2_chroma_h::UInt8
    flags::UInt64
    comp::NTuple{4, AVComponentDescriptor}
    alias::Cstring
end

const AVPALETTE_SIZE = 1024
const AVPALETTE_COUNT = 256

# begin enum AVPixelFormat
const AVPixelFormat = Cint
const AV_PIX_FMT_NONE = -1 |> Int32
const AV_PIX_FMT_YUV420P = 0 |> Int32
const AV_PIX_FMT_YUYV422 = 1 |> Int32
const AV_PIX_FMT_RGB24 = 2 |> Int32
const AV_PIX_FMT_BGR24 = 3 |> Int32
const AV_PIX_FMT_YUV422P = 4 |> Int32
const AV_PIX_FMT_YUV444P = 5 |> Int32
const AV_PIX_FMT_YUV410P = 6 |> Int32
const AV_PIX_FMT_YUV411P = 7 |> Int32
const AV_PIX_FMT_GRAY8 = 8 |> Int32
const AV_PIX_FMT_MONOWHITE = 9 |> Int32
const AV_PIX_FMT_MONOBLACK = 10 |> Int32
const AV_PIX_FMT_PAL8 = 11 |> Int32
const AV_PIX_FMT_YUVJ420P = 12 |> Int32
const AV_PIX_FMT_YUVJ422P = 13 |> Int32
const AV_PIX_FMT_YUVJ444P = 14 |> Int32
const AV_PIX_FMT_UYVY422 = 15 |> Int32
const AV_PIX_FMT_UYYVYY411 = 16 |> Int32
const AV_PIX_FMT_BGR8 = 17 |> Int32
const AV_PIX_FMT_BGR4 = 18 |> Int32
const AV_PIX_FMT_BGR4_BYTE = 19 |> Int32
const AV_PIX_FMT_RGB8 = 20 |> Int32
const AV_PIX_FMT_RGB4 = 21 |> Int32
const AV_PIX_FMT_RGB4_BYTE = 22 |> Int32
const AV_PIX_FMT_NV12 = 23 |> Int32
const AV_PIX_FMT_NV21 = 24 |> Int32
const AV_PIX_FMT_ARGB = 25 |> Int32
const AV_PIX_FMT_RGBA = 26 |> Int32
const AV_PIX_FMT_ABGR = 27 |> Int32
const AV_PIX_FMT_BGRA = 28 |> Int32
const AV_PIX_FMT_GRAY16BE = 29 |> Int32
const AV_PIX_FMT_GRAY16LE = 30 |> Int32
const AV_PIX_FMT_YUV440P = 31 |> Int32
const AV_PIX_FMT_YUVJ440P = 32 |> Int32
const AV_PIX_FMT_YUVA420P = 33 |> Int32
const AV_PIX_FMT_RGB48BE = 34 |> Int32
const AV_PIX_FMT_RGB48LE = 35 |> Int32
const AV_PIX_FMT_RGB565BE = 36 |> Int32
const AV_PIX_FMT_RGB565LE = 37 |> Int32
const AV_PIX_FMT_RGB555BE = 38 |> Int32
const AV_PIX_FMT_RGB555LE = 39 |> Int32
const AV_PIX_FMT_BGR565BE = 40 |> Int32
const AV_PIX_FMT_BGR565LE = 41 |> Int32
const AV_PIX_FMT_BGR555BE = 42 |> Int32
const AV_PIX_FMT_BGR555LE = 43 |> Int32
const AV_PIX_FMT_VAAPI_MOCO = 44 |> Int32
const AV_PIX_FMT_VAAPI_IDCT = 45 |> Int32
const AV_PIX_FMT_VAAPI_VLD = 46 |> Int32
const AV_PIX_FMT_VAAPI = 46 |> Int32
const AV_PIX_FMT_YUV420P16LE = 47 |> Int32
const AV_PIX_FMT_YUV420P16BE = 48 |> Int32
const AV_PIX_FMT_YUV422P16LE = 49 |> Int32
const AV_PIX_FMT_YUV422P16BE = 50 |> Int32
const AV_PIX_FMT_YUV444P16LE = 51 |> Int32
const AV_PIX_FMT_YUV444P16BE = 52 |> Int32
const AV_PIX_FMT_DXVA2_VLD = 53 |> Int32
const AV_PIX_FMT_RGB444LE = 54 |> Int32
const AV_PIX_FMT_RGB444BE = 55 |> Int32
const AV_PIX_FMT_BGR444LE = 56 |> Int32
const AV_PIX_FMT_BGR444BE = 57 |> Int32
const AV_PIX_FMT_YA8 = 58 |> Int32
const AV_PIX_FMT_Y400A = 58 |> Int32
const AV_PIX_FMT_GRAY8A = 58 |> Int32
const AV_PIX_FMT_BGR48BE = 59 |> Int32
const AV_PIX_FMT_BGR48LE = 60 |> Int32
const AV_PIX_FMT_YUV420P9BE = 61 |> Int32
const AV_PIX_FMT_YUV420P9LE = 62 |> Int32
const AV_PIX_FMT_YUV420P10BE = 63 |> Int32
const AV_PIX_FMT_YUV420P10LE = 64 |> Int32
const AV_PIX_FMT_YUV422P10BE = 65 |> Int32
const AV_PIX_FMT_YUV422P10LE = 66 |> Int32
const AV_PIX_FMT_YUV444P9BE = 67 |> Int32
const AV_PIX_FMT_YUV444P9LE = 68 |> Int32
const AV_PIX_FMT_YUV444P10BE = 69 |> Int32
const AV_PIX_FMT_YUV444P10LE = 70 |> Int32
const AV_PIX_FMT_YUV422P9BE = 71 |> Int32
const AV_PIX_FMT_YUV422P9LE = 72 |> Int32
const AV_PIX_FMT_GBRP = 73 |> Int32
const AV_PIX_FMT_GBR24P = 73 |> Int32
const AV_PIX_FMT_GBRP9BE = 74 |> Int32
const AV_PIX_FMT_GBRP9LE = 75 |> Int32
const AV_PIX_FMT_GBRP10BE = 76 |> Int32
const AV_PIX_FMT_GBRP10LE = 77 |> Int32
const AV_PIX_FMT_GBRP16BE = 78 |> Int32
const AV_PIX_FMT_GBRP16LE = 79 |> Int32
const AV_PIX_FMT_YUVA422P = 80 |> Int32
const AV_PIX_FMT_YUVA444P = 81 |> Int32
const AV_PIX_FMT_YUVA420P9BE = 82 |> Int32
const AV_PIX_FMT_YUVA420P9LE = 83 |> Int32
const AV_PIX_FMT_YUVA422P9BE = 84 |> Int32
const AV_PIX_FMT_YUVA422P9LE = 85 |> Int32
const AV_PIX_FMT_YUVA444P9BE = 86 |> Int32
const AV_PIX_FMT_YUVA444P9LE = 87 |> Int32
const AV_PIX_FMT_YUVA420P10BE = 88 |> Int32
const AV_PIX_FMT_YUVA420P10LE = 89 |> Int32
const AV_PIX_FMT_YUVA422P10BE = 90 |> Int32
const AV_PIX_FMT_YUVA422P10LE = 91 |> Int32
const AV_PIX_FMT_YUVA444P10BE = 92 |> Int32
const AV_PIX_FMT_YUVA444P10LE = 93 |> Int32
const AV_PIX_FMT_YUVA420P16BE = 94 |> Int32
const AV_PIX_FMT_YUVA420P16LE = 95 |> Int32
const AV_PIX_FMT_YUVA422P16BE = 96 |> Int32
const AV_PIX_FMT_YUVA422P16LE = 97 |> Int32
const AV_PIX_FMT_YUVA444P16BE = 98 |> Int32
const AV_PIX_FMT_YUVA444P16LE = 99 |> Int32
const AV_PIX_FMT_VDPAU = 100 |> Int32
const AV_PIX_FMT_XYZ12LE = 101 |> Int32
const AV_PIX_FMT_XYZ12BE = 102 |> Int32
const AV_PIX_FMT_NV16 = 103 |> Int32
const AV_PIX_FMT_NV20LE = 104 |> Int32
const AV_PIX_FMT_NV20BE = 105 |> Int32
const AV_PIX_FMT_RGBA64BE = 106 |> Int32
const AV_PIX_FMT_RGBA64LE = 107 |> Int32
const AV_PIX_FMT_BGRA64BE = 108 |> Int32
const AV_PIX_FMT_BGRA64LE = 109 |> Int32
const AV_PIX_FMT_YVYU422 = 110 |> Int32
const AV_PIX_FMT_YA16BE = 111 |> Int32
const AV_PIX_FMT_YA16LE = 112 |> Int32
const AV_PIX_FMT_GBRAP = 113 |> Int32
const AV_PIX_FMT_GBRAP16BE = 114 |> Int32
const AV_PIX_FMT_GBRAP16LE = 115 |> Int32
const AV_PIX_FMT_QSV = 116 |> Int32
const AV_PIX_FMT_MMAL = 117 |> Int32
const AV_PIX_FMT_D3D11VA_VLD = 118 |> Int32
const AV_PIX_FMT_CUDA = 119 |> Int32
const AV_PIX_FMT_0RGB = 120 |> Int32
const AV_PIX_FMT_RGB0 = 121 |> Int32
const AV_PIX_FMT_0BGR = 122 |> Int32
const AV_PIX_FMT_BGR0 = 123 |> Int32
const AV_PIX_FMT_YUV420P12BE = 124 |> Int32
const AV_PIX_FMT_YUV420P12LE = 125 |> Int32
const AV_PIX_FMT_YUV420P14BE = 126 |> Int32
const AV_PIX_FMT_YUV420P14LE = 127 |> Int32
const AV_PIX_FMT_YUV422P12BE = 128 |> Int32
const AV_PIX_FMT_YUV422P12LE = 129 |> Int32
const AV_PIX_FMT_YUV422P14BE = 130 |> Int32
const AV_PIX_FMT_YUV422P14LE = 131 |> Int32
const AV_PIX_FMT_YUV444P12BE = 132 |> Int32
const AV_PIX_FMT_YUV444P12LE = 133 |> Int32
const AV_PIX_FMT_YUV444P14BE = 134 |> Int32
const AV_PIX_FMT_YUV444P14LE = 135 |> Int32
const AV_PIX_FMT_GBRP12BE = 136 |> Int32
const AV_PIX_FMT_GBRP12LE = 137 |> Int32
const AV_PIX_FMT_GBRP14BE = 138 |> Int32
const AV_PIX_FMT_GBRP14LE = 139 |> Int32
const AV_PIX_FMT_YUVJ411P = 140 |> Int32
const AV_PIX_FMT_BAYER_BGGR8 = 141 |> Int32
const AV_PIX_FMT_BAYER_RGGB8 = 142 |> Int32
const AV_PIX_FMT_BAYER_GBRG8 = 143 |> Int32
const AV_PIX_FMT_BAYER_GRBG8 = 144 |> Int32
const AV_PIX_FMT_BAYER_BGGR16LE = 145 |> Int32
const AV_PIX_FMT_BAYER_BGGR16BE = 146 |> Int32
const AV_PIX_FMT_BAYER_RGGB16LE = 147 |> Int32
const AV_PIX_FMT_BAYER_RGGB16BE = 148 |> Int32
const AV_PIX_FMT_BAYER_GBRG16LE = 149 |> Int32
const AV_PIX_FMT_BAYER_GBRG16BE = 150 |> Int32
const AV_PIX_FMT_BAYER_GRBG16LE = 151 |> Int32
const AV_PIX_FMT_BAYER_GRBG16BE = 152 |> Int32
const AV_PIX_FMT_XVMC = 153 |> Int32
const AV_PIX_FMT_YUV440P10LE = 154 |> Int32
const AV_PIX_FMT_YUV440P10BE = 155 |> Int32
const AV_PIX_FMT_YUV440P12LE = 156 |> Int32
const AV_PIX_FMT_YUV440P12BE = 157 |> Int32
const AV_PIX_FMT_AYUV64LE = 158 |> Int32
const AV_PIX_FMT_AYUV64BE = 159 |> Int32
const AV_PIX_FMT_VIDEOTOOLBOX = 160 |> Int32
const AV_PIX_FMT_P010LE = 161 |> Int32
const AV_PIX_FMT_P010BE = 162 |> Int32
const AV_PIX_FMT_GBRAP12BE = 163 |> Int32
const AV_PIX_FMT_GBRAP12LE = 164 |> Int32
const AV_PIX_FMT_GBRAP10BE = 165 |> Int32
const AV_PIX_FMT_GBRAP10LE = 166 |> Int32
const AV_PIX_FMT_MEDIACODEC = 167 |> Int32
const AV_PIX_FMT_GRAY12BE = 168 |> Int32
const AV_PIX_FMT_GRAY12LE = 169 |> Int32
const AV_PIX_FMT_GRAY10BE = 170 |> Int32
const AV_PIX_FMT_GRAY10LE = 171 |> Int32
const AV_PIX_FMT_P016LE = 172 |> Int32
const AV_PIX_FMT_P016BE = 173 |> Int32
const AV_PIX_FMT_D3D11 = 174 |> Int32
const AV_PIX_FMT_GRAY9BE = 175 |> Int32
const AV_PIX_FMT_GRAY9LE = 176 |> Int32
const AV_PIX_FMT_GBRPF32BE = 177 |> Int32
const AV_PIX_FMT_GBRPF32LE = 178 |> Int32
const AV_PIX_FMT_GBRAPF32BE = 179 |> Int32
const AV_PIX_FMT_GBRAPF32LE = 180 |> Int32
const AV_PIX_FMT_DRM_PRIME = 181 |> Int32
const AV_PIX_FMT_OPENCL = 182 |> Int32
const AV_PIX_FMT_GRAY14BE = 183 |> Int32
const AV_PIX_FMT_GRAY14LE = 184 |> Int32
const AV_PIX_FMT_GRAYF32BE = 185 |> Int32
const AV_PIX_FMT_GRAYF32LE = 186 |> Int32
const AV_PIX_FMT_NB = 187 |> Int32
# end enum AVPixelFormat

macro AV_PIX_FMT_NE(be, le)
    Symbol("AV_PIX_FMT_"*string(le))
end
const AV_PIX_FMT_RGB32 = @AV_PIX_FMT_NE(ARGB, BGRA)
const AV_PIX_FMT_RGB32_1 = @AV_PIX_FMT_NE(RGBA, ABGR)
const AV_PIX_FMT_BGR32 = @AV_PIX_FMT_NE(ABGR, RGBA)
const AV_PIX_FMT_BGR32_1 = @AV_PIX_FMT_NE(BGRA, ARGB)
const AV_PIX_FMT_0RGB32 = @AV_PIX_FMT_NE(0RGB, BGR0)
const AV_PIX_FMT_0BGR32 = @AV_PIX_FMT_NE(0BGR, RGB0)
const AV_PIX_FMT_GRAY9 = @AV_PIX_FMT_NE(GRAY9BE, GRAY9LE)
const AV_PIX_FMT_GRAY10 = @AV_PIX_FMT_NE(GRAY10BE, GRAY10LE)
const AV_PIX_FMT_GRAY12 = @AV_PIX_FMT_NE(GRAY12BE, GRAY12LE)
const AV_PIX_FMT_GRAY14 = @AV_PIX_FMT_NE(GRAY14BE, GRAY14LE)
const AV_PIX_FMT_GRAY16 = @AV_PIX_FMT_NE(GRAY16BE, GRAY16LE)
const AV_PIX_FMT_YA16 = @AV_PIX_FMT_NE(YA16BE, YA16LE)
const AV_PIX_FMT_RGB48 = @AV_PIX_FMT_NE(RGB48BE, RGB48LE)
const AV_PIX_FMT_RGB565 = @AV_PIX_FMT_NE(RGB565BE, RGB565LE)
const AV_PIX_FMT_RGB555 = @AV_PIX_FMT_NE(RGB555BE, RGB555LE)
const AV_PIX_FMT_RGB444 = @AV_PIX_FMT_NE(RGB444BE, RGB444LE)
const AV_PIX_FMT_RGBA64 = @AV_PIX_FMT_NE(RGBA64BE, RGBA64LE)
const AV_PIX_FMT_BGR48 = @AV_PIX_FMT_NE(BGR48BE, BGR48LE)
const AV_PIX_FMT_BGR565 = @AV_PIX_FMT_NE(BGR565BE, BGR565LE)
const AV_PIX_FMT_BGR555 = @AV_PIX_FMT_NE(BGR555BE, BGR555LE)
const AV_PIX_FMT_BGR444 = @AV_PIX_FMT_NE(BGR444BE, BGR444LE)
const AV_PIX_FMT_BGRA64 = @AV_PIX_FMT_NE(BGRA64BE, BGRA64LE)
const AV_PIX_FMT_YUV420P9 = @AV_PIX_FMT_NE(YUV420P9BE, YUV420P9LE)
const AV_PIX_FMT_YUV422P9 = @AV_PIX_FMT_NE(YUV422P9BE, YUV422P9LE)
const AV_PIX_FMT_YUV444P9 = @AV_PIX_FMT_NE(YUV444P9BE, YUV444P9LE)
const AV_PIX_FMT_YUV420P10 = @AV_PIX_FMT_NE(YUV420P10BE, YUV420P10LE)
const AV_PIX_FMT_YUV422P10 = @AV_PIX_FMT_NE(YUV422P10BE, YUV422P10LE)
const AV_PIX_FMT_YUV440P10 = @AV_PIX_FMT_NE(YUV440P10BE, YUV440P10LE)
const AV_PIX_FMT_YUV444P10 = @AV_PIX_FMT_NE(YUV444P10BE, YUV444P10LE)
const AV_PIX_FMT_YUV420P12 = @AV_PIX_FMT_NE(YUV420P12BE, YUV420P12LE)
const AV_PIX_FMT_YUV422P12 = @AV_PIX_FMT_NE(YUV422P12BE, YUV422P12LE)
const AV_PIX_FMT_YUV440P12 = @AV_PIX_FMT_NE(YUV440P12BE, YUV440P12LE)
const AV_PIX_FMT_YUV444P12 = @AV_PIX_FMT_NE(YUV444P12BE, YUV444P12LE)
const AV_PIX_FMT_YUV420P14 = @AV_PIX_FMT_NE(YUV420P14BE, YUV420P14LE)
const AV_PIX_FMT_YUV422P14 = @AV_PIX_FMT_NE(YUV422P14BE, YUV422P14LE)
const AV_PIX_FMT_YUV444P14 = @AV_PIX_FMT_NE(YUV444P14BE, YUV444P14LE)
const AV_PIX_FMT_YUV420P16 = @AV_PIX_FMT_NE(YUV420P16BE, YUV420P16LE)
const AV_PIX_FMT_YUV422P16 = @AV_PIX_FMT_NE(YUV422P16BE, YUV422P16LE)
const AV_PIX_FMT_YUV444P16 = @AV_PIX_FMT_NE(YUV444P16BE, YUV444P16LE)
const AV_PIX_FMT_GBRP9 = @AV_PIX_FMT_NE(GBRP9BE, GBRP9LE)
const AV_PIX_FMT_GBRP10 = @AV_PIX_FMT_NE(GBRP10BE, GBRP10LE)
const AV_PIX_FMT_GBRP12 = @AV_PIX_FMT_NE(GBRP12BE, GBRP12LE)
const AV_PIX_FMT_GBRP14 = @AV_PIX_FMT_NE(GBRP14BE, GBRP14LE)
const AV_PIX_FMT_GBRP16 = @AV_PIX_FMT_NE(GBRP16BE, GBRP16LE)
const AV_PIX_FMT_GBRAP10 = @AV_PIX_FMT_NE(GBRAP10BE, GBRAP10LE)
const AV_PIX_FMT_GBRAP12 = @AV_PIX_FMT_NE(GBRAP12BE, GBRAP12LE)
const AV_PIX_FMT_GBRAP16 = @AV_PIX_FMT_NE(GBRAP16BE, GBRAP16LE)
const AV_PIX_FMT_BAYER_BGGR16 = @AV_PIX_FMT_NE(BAYER_BGGR16BE, BAYER_BGGR16LE)
const AV_PIX_FMT_BAYER_RGGB16 = @AV_PIX_FMT_NE(BAYER_RGGB16BE, BAYER_RGGB16LE)
const AV_PIX_FMT_BAYER_GBRG16 = @AV_PIX_FMT_NE(BAYER_GBRG16BE, BAYER_GBRG16LE)
const AV_PIX_FMT_BAYER_GRBG16 = @AV_PIX_FMT_NE(BAYER_GRBG16BE, BAYER_GRBG16LE)
const AV_PIX_FMT_GBRPF32 = @AV_PIX_FMT_NE(GBRPF32BE, GBRPF32LE)
const AV_PIX_FMT_GBRAPF32 = @AV_PIX_FMT_NE(GBRAPF32BE, GBRAPF32LE)
const AV_PIX_FMT_GRAYF32 = @AV_PIX_FMT_NE(GRAYF32BE, GRAYF32LE)
const AV_PIX_FMT_YUVA420P9 = @AV_PIX_FMT_NE(YUVA420P9BE, YUVA420P9LE)
const AV_PIX_FMT_YUVA422P9 = @AV_PIX_FMT_NE(YUVA422P9BE, YUVA422P9LE)
const AV_PIX_FMT_YUVA444P9 = @AV_PIX_FMT_NE(YUVA444P9BE, YUVA444P9LE)
const AV_PIX_FMT_YUVA420P10 = @AV_PIX_FMT_NE(YUVA420P10BE, YUVA420P10LE)
const AV_PIX_FMT_YUVA422P10 = @AV_PIX_FMT_NE(YUVA422P10BE, YUVA422P10LE)
const AV_PIX_FMT_YUVA444P10 = @AV_PIX_FMT_NE(YUVA444P10BE, YUVA444P10LE)
const AV_PIX_FMT_YUVA420P16 = @AV_PIX_FMT_NE(YUVA420P16BE, YUVA420P16LE)
const AV_PIX_FMT_YUVA422P16 = @AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE)
const AV_PIX_FMT_YUVA444P16 = @AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE)
const AV_PIX_FMT_XYZ12 = @AV_PIX_FMT_NE(XYZ12BE, XYZ12LE)
const AV_PIX_FMT_NV20 = @AV_PIX_FMT_NE(NV20BE, NV20LE)
const AV_PIX_FMT_AYUV64 = @AV_PIX_FMT_NE(AYUV64BE, AYUV64LE)
const AV_PIX_FMT_P010 = @AV_PIX_FMT_NE(P010BE, P010LE)
const AV_PIX_FMT_P016 = @AV_PIX_FMT_NE(P016BE, P016LE)

# begin enum AVColorPrimaries
const AVColorPrimaries = UInt32
const AVCOL_PRI_RESERVED0 = 0 |> UInt32
const AVCOL_PRI_BT709 = 1 |> UInt32
const AVCOL_PRI_UNSPECIFIED = 2 |> UInt32
const AVCOL_PRI_RESERVED = 3 |> UInt32
const AVCOL_PRI_BT470M = 4 |> UInt32
const AVCOL_PRI_BT470BG = 5 |> UInt32
const AVCOL_PRI_SMPTE170M = 6 |> UInt32
const AVCOL_PRI_SMPTE240M = 7 |> UInt32
const AVCOL_PRI_FILM = 8 |> UInt32
const AVCOL_PRI_BT2020 = 9 |> UInt32
const AVCOL_PRI_SMPTE428 = 10 |> UInt32
const AVCOL_PRI_SMPTEST428_1 = 10 |> UInt32
const AVCOL_PRI_SMPTE431 = 11 |> UInt32
const AVCOL_PRI_SMPTE432 = 12 |> UInt32
const AVCOL_PRI_JEDEC_P22 = 22 |> UInt32
const AVCOL_PRI_NB = 23 |> UInt32
# end enum AVColorPrimaries

# begin enum AVColorTransferCharacteristic
const AVColorTransferCharacteristic = UInt32
const AVCOL_TRC_RESERVED0 = 0 |> UInt32
const AVCOL_TRC_BT709 = 1 |> UInt32
const AVCOL_TRC_UNSPECIFIED = 2 |> UInt32
const AVCOL_TRC_RESERVED = 3 |> UInt32
const AVCOL_TRC_GAMMA22 = 4 |> UInt32
const AVCOL_TRC_GAMMA28 = 5 |> UInt32
const AVCOL_TRC_SMPTE170M = 6 |> UInt32
const AVCOL_TRC_SMPTE240M = 7 |> UInt32
const AVCOL_TRC_LINEAR = 8 |> UInt32
const AVCOL_TRC_LOG = 9 |> UInt32
const AVCOL_TRC_LOG_SQRT = 10 |> UInt32
const AVCOL_TRC_IEC61966_2_4 = 11 |> UInt32
const AVCOL_TRC_BT1361_ECG = 12 |> UInt32
const AVCOL_TRC_IEC61966_2_1 = 13 |> UInt32
const AVCOL_TRC_BT2020_10 = 14 |> UInt32
const AVCOL_TRC_BT2020_12 = 15 |> UInt32
const AVCOL_TRC_SMPTE2084 = 16 |> UInt32
const AVCOL_TRC_SMPTEST2084 = 16 |> UInt32
const AVCOL_TRC_SMPTE428 = 17 |> UInt32
const AVCOL_TRC_SMPTEST428_1 = 17 |> UInt32
const AVCOL_TRC_ARIB_STD_B67 = 18 |> UInt32
const AVCOL_TRC_NB = 19 |> UInt32
# end enum AVColorTransferCharacteristic

# begin enum AVColorSpace
const AVColorSpace = UInt32
const AVCOL_SPC_RGB = 0 |> UInt32
const AVCOL_SPC_BT709 = 1 |> UInt32
const AVCOL_SPC_UNSPECIFIED = 2 |> UInt32
const AVCOL_SPC_RESERVED = 3 |> UInt32
const AVCOL_SPC_FCC = 4 |> UInt32
const AVCOL_SPC_BT470BG = 5 |> UInt32
const AVCOL_SPC_SMPTE170M = 6 |> UInt32
const AVCOL_SPC_SMPTE240M = 7 |> UInt32
const AVCOL_SPC_YCGCO = 8 |> UInt32
const AVCOL_SPC_YCOCG = 8 |> UInt32
const AVCOL_SPC_BT2020_NCL = 9 |> UInt32
const AVCOL_SPC_BT2020_CL = 10 |> UInt32
const AVCOL_SPC_SMPTE2085 = 11 |> UInt32
const AVCOL_SPC_CHROMA_DERIVED_NCL = 12 |> UInt32
const AVCOL_SPC_CHROMA_DERIVED_CL = 13 |> UInt32
const AVCOL_SPC_ICTCP = 14 |> UInt32
const AVCOL_SPC_NB = 15 |> UInt32
# end enum AVColorSpace

# begin enum AVColorRange
const AVColorRange = UInt32
const AVCOL_RANGE_UNSPECIFIED = 0 |> UInt32
const AVCOL_RANGE_MPEG = 1 |> UInt32
const AVCOL_RANGE_JPEG = 2 |> UInt32
const AVCOL_RANGE_NB = 3 |> UInt32
# end enum AVColorRange

# begin enum AVChromaLocation
const AVChromaLocation = UInt32
const AVCHROMA_LOC_UNSPECIFIED = 0 |> UInt32
const AVCHROMA_LOC_LEFT = 1 |> UInt32
const AVCHROMA_LOC_CENTER = 2 |> UInt32
const AVCHROMA_LOC_TOPLEFT = 3 |> UInt32
const AVCHROMA_LOC_TOP = 4 |> UInt32
const AVCHROMA_LOC_BOTTOMLEFT = 5 |> UInt32
const AVCHROMA_LOC_BOTTOM = 6 |> UInt32
const AVCHROMA_LOC_NB = 7 |> UInt32
# end enum AVChromaLocation

# begin enum AVSampleFormat
const AVSampleFormat = Cint
const AV_SAMPLE_FMT_NONE = -1 |> Int32
const AV_SAMPLE_FMT_U8 = 0 |> Int32
const AV_SAMPLE_FMT_S16 = 1 |> Int32
const AV_SAMPLE_FMT_S32 = 2 |> Int32
const AV_SAMPLE_FMT_FLT = 3 |> Int32
const AV_SAMPLE_FMT_DBL = 4 |> Int32
const AV_SAMPLE_FMT_U8P = 5 |> Int32
const AV_SAMPLE_FMT_S16P = 6 |> Int32
const AV_SAMPLE_FMT_S32P = 7 |> Int32
const AV_SAMPLE_FMT_FLTP = 8 |> Int32
const AV_SAMPLE_FMT_DBLP = 9 |> Int32
const AV_SAMPLE_FMT_S64 = 10 |> Int32
const AV_SAMPLE_FMT_S64P = 11 |> Int32
const AV_SAMPLE_FMT_NB = 12 |> Int32
# end enum AVSampleFormat

# Skipping MacroDefinition: AV_VERSION_INT ( a , b , c ) ( ( a ) << 16 | ( b ) << 8 | ( c ) )
# Skipping MacroDefinition: AV_VERSION_DOT ( a , b , c ) a ## . ## b ## . ## c
# Skipping MacroDefinition: AV_VERSION ( a , b , c ) AV_VERSION_DOT ( a , b , c )
# Skipping MacroDefinition: AV_VERSION_MAJOR ( a ) ( ( a ) >> 16 )
# Skipping MacroDefinition: AV_VERSION_MINOR ( a ) ( ( ( a ) & 0x00FF00 ) >> 8 )
# Skipping MacroDefinition: AV_VERSION_MICRO ( a ) ( ( a ) & 0xFF )

const LIBAVUTIL_VERSION_MAJOR = 56
const LIBAVUTIL_VERSION_MINOR = 22
const LIBAVUTIL_VERSION_MICRO = 100

# Skipping MacroDefinition: LIBAVUTIL_VERSION_INT AV_VERSION_INT ( LIBAVUTIL_VERSION_MAJOR , LIBAVUTIL_VERSION_MINOR , LIBAVUTIL_VERSION_MICRO )
# Skipping MacroDefinition: LIBAVUTIL_VERSION AV_VERSION ( LIBAVUTIL_VERSION_MAJOR , LIBAVUTIL_VERSION_MINOR , LIBAVUTIL_VERSION_MICRO )

# const LIBAVUTIL_BUILD = LIBAVUTIL_VERSION_INT

# Skipping MacroDefinition: LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY ( LIBAVUTIL_VERSION )
# Skipping MacroDefinition: FF_API_VAAPI ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_FRAME_QP ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_PLUS1_MINUS1 ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_ERROR_FRAME ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_PKT_PTS ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_CRYPTO_SIZE_T ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_FRAME_GET_SET ( LIBAVUTIL_VERSION_MAJOR < 57 )
# Skipping MacroDefinition: FF_API_PSEUDOPAL ( LIBAVUTIL_VERSION_MAJOR < 57 )

const AES_CTR_KEY_SIZE = 16
const AES_CTR_IV_SIZE = 8

struct AVAESCTR
end

struct AVAudioFifo
end

struct AVCAMELLIA
end

struct AVCAST5
end

const AV_CH_FRONT_LEFT = 0x00000001
const AV_CH_FRONT_RIGHT = 0x00000002
const AV_CH_FRONT_CENTER = 0x00000004
const AV_CH_LOW_FREQUENCY = 0x00000008
const AV_CH_BACK_LEFT = 0x00000010
const AV_CH_BACK_RIGHT = 0x00000020
const AV_CH_FRONT_LEFT_OF_CENTER = 0x00000040
const AV_CH_FRONT_RIGHT_OF_CENTER = 0x00000080
const AV_CH_BACK_CENTER = 0x00000100
const AV_CH_SIDE_LEFT = 0x00000200
const AV_CH_SIDE_RIGHT = 0x00000400
const AV_CH_TOP_CENTER = 0x00000800
const AV_CH_TOP_FRONT_LEFT = 0x00001000
const AV_CH_TOP_FRONT_CENTER = 0x00002000
const AV_CH_TOP_FRONT_RIGHT = 0x00004000
const AV_CH_TOP_BACK_LEFT = 0x00008000
const AV_CH_TOP_BACK_CENTER = 0x00010000
const AV_CH_TOP_BACK_RIGHT = 0x00020000
const AV_CH_STEREO_LEFT = 0x20000000
const AV_CH_STEREO_RIGHT = 0x40000000
const AV_CH_WIDE_LEFT = UInt64(0x0000000080000000)
const AV_CH_WIDE_RIGHT = UInt64(0x0000000100000000)
const AV_CH_SURROUND_DIRECT_LEFT = UInt64(0x0000000200000000)
const AV_CH_SURROUND_DIRECT_RIGHT = UInt64(0x0000000400000000)
const AV_CH_LOW_FREQUENCY_2 = UInt64(0x0000000800000000)
const AV_CH_LAYOUT_NATIVE = UInt64(0x8000000000000000)
const AV_CH_LAYOUT_MONO = AV_CH_FRONT_CENTER
const AV_CH_LAYOUT_STEREO = AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT
const AV_CH_LAYOUT_2POINT1 = AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_2_1 = AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_SURROUND = AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER
const AV_CH_LAYOUT_3POINT1 = AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_4POINT0 = AV_CH_LAYOUT_SURROUND | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_4POINT1 = AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_2_2 = (AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT) | AV_CH_SIDE_RIGHT
const AV_CH_LAYOUT_QUAD = (AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT) | AV_CH_BACK_RIGHT
const AV_CH_LAYOUT_5POINT0 = (AV_CH_LAYOUT_SURROUND | AV_CH_SIDE_LEFT) | AV_CH_SIDE_RIGHT
const AV_CH_LAYOUT_5POINT1 = AV_CH_LAYOUT_5POINT0 | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_5POINT0_BACK = (AV_CH_LAYOUT_SURROUND | AV_CH_BACK_LEFT) | AV_CH_BACK_RIGHT
const AV_CH_LAYOUT_5POINT1_BACK = AV_CH_LAYOUT_5POINT0_BACK | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_6POINT0 = AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_6POINT0_FRONT = (AV_CH_LAYOUT_2_2 | AV_CH_FRONT_LEFT_OF_CENTER) | AV_CH_FRONT_RIGHT_OF_CENTER
const AV_CH_LAYOUT_HEXAGONAL = AV_CH_LAYOUT_5POINT0_BACK | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_6POINT1 = AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_6POINT1_BACK = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_BACK_CENTER
const AV_CH_LAYOUT_6POINT1_FRONT = AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_LOW_FREQUENCY
const AV_CH_LAYOUT_7POINT0 = (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT) | AV_CH_BACK_RIGHT
const AV_CH_LAYOUT_7POINT0_FRONT = (AV_CH_LAYOUT_5POINT0 | AV_CH_FRONT_LEFT_OF_CENTER) | AV_CH_FRONT_RIGHT_OF_CENTER
const AV_CH_LAYOUT_7POINT1 = (AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_LEFT) | AV_CH_BACK_RIGHT
const AV_CH_LAYOUT_7POINT1_WIDE = (AV_CH_LAYOUT_5POINT1 | AV_CH_FRONT_LEFT_OF_CENTER) | AV_CH_FRONT_RIGHT_OF_CENTER
const AV_CH_LAYOUT_7POINT1_WIDE_BACK = (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_FRONT_LEFT_OF_CENTER) | AV_CH_FRONT_RIGHT_OF_CENTER
const AV_CH_LAYOUT_OCTAGONAL = ((AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT) | AV_CH_BACK_CENTER) | AV_CH_BACK_RIGHT
const AV_CH_LAYOUT_HEXADECAGONAL = (((((((AV_CH_LAYOUT_OCTAGONAL | AV_CH_WIDE_LEFT) | AV_CH_WIDE_RIGHT) | AV_CH_TOP_BACK_LEFT) | AV_CH_TOP_BACK_RIGHT) | AV_CH_TOP_BACK_CENTER) | AV_CH_TOP_FRONT_CENTER) | AV_CH_TOP_FRONT_LEFT) | AV_CH_TOP_FRONT_RIGHT
const AV_CH_LAYOUT_STEREO_DOWNMIX = AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT

# begin enum AVMatrixEncoding
const AVMatrixEncoding = UInt32
const AV_MATRIX_ENCODING_NONE = 0 |> UInt32
const AV_MATRIX_ENCODING_DOLBY = 1 |> UInt32
const AV_MATRIX_ENCODING_DPLII = 2 |> UInt32
const AV_MATRIX_ENCODING_DPLIIX = 3 |> UInt32
const AV_MATRIX_ENCODING_DPLIIZ = 4 |> UInt32
const AV_MATRIX_ENCODING_DOLBYEX = 5 |> UInt32
const AV_MATRIX_ENCODING_DOLBYHEADPHONE = 6 |> UInt32
const AV_MATRIX_ENCODING_NB = 7 |> UInt32
# end enum AVMatrixEncoding

struct AVBPrint
end

struct AVDES
    round_keys::NTuple{3, NTuple{16, UInt64}}
    triple_des::Cint
end

# begin enum AVDownmixType
const AVDownmixType = UInt32
const AV_DOWNMIX_TYPE_UNKNOWN = 0 |> UInt32
const AV_DOWNMIX_TYPE_LORO = 1 |> UInt32
const AV_DOWNMIX_TYPE_LTRT = 2 |> UInt32
const AV_DOWNMIX_TYPE_DPLII = 3 |> UInt32
const AV_DOWNMIX_TYPE_NB = 4 |> UInt32
# end enum AVDownmixType

struct AVDownmixInfo
    preferred_downmix_type::AVDownmixType
    center_mix_level::Cdouble
    center_mix_level_ltrt::Cdouble
    surround_mix_level::Cdouble
    surround_mix_level_ltrt::Cdouble
    lfe_mix_level::Cdouble
end

struct AVSubsampleEncryptionInfo
    bytes_of_clear_data::UInt32
    bytes_of_protected_data::UInt32
end

struct AVEncryptionInfo
    scheme::UInt32
    crypt_byte_block::UInt32
    skip_byte_block::UInt32
    key_id::Ptr{UInt8}
    key_id_size::UInt32
    iv::Ptr{UInt8}
    iv_size::UInt32
    subsamples::Ptr{AVSubsampleEncryptionInfo}
    subsample_count::UInt32
end

struct AVEncryptionInitInfo
    system_id::Ptr{UInt8}
    system_id_size::UInt32
    key_ids::Ptr{Ptr{UInt8}}
    num_key_ids::UInt32
    key_id_size::UInt32
    data::Ptr{UInt8}
    data_size::UInt32
    next::Ptr{AVEncryptionInitInfo}
end

const AV_HASH_MAX_SIZE = 64

struct AVHashContext
end

# begin enum AVHWDeviceType
const AVHWDeviceType = UInt32
const AV_HWDEVICE_TYPE_NONE = 0 |> UInt32
const AV_HWDEVICE_TYPE_VDPAU = 1 |> UInt32
const AV_HWDEVICE_TYPE_CUDA = 2 |> UInt32
const AV_HWDEVICE_TYPE_VAAPI = 3 |> UInt32
const AV_HWDEVICE_TYPE_DXVA2 = 4 |> UInt32
const AV_HWDEVICE_TYPE_QSV = 5 |> UInt32
const AV_HWDEVICE_TYPE_VIDEOTOOLBOX = 6 |> UInt32
const AV_HWDEVICE_TYPE_D3D11VA = 7 |> UInt32
const AV_HWDEVICE_TYPE_DRM = 8 |> UInt32
const AV_HWDEVICE_TYPE_OPENCL = 9 |> UInt32
const AV_HWDEVICE_TYPE_MEDIACODEC = 10 |> UInt32
# end enum AVHWDeviceType

struct AVHWDeviceInternal
end

struct AVHWDeviceContext
    av_class::Ptr{AVClass}
    internal::Ptr{AVHWDeviceInternal}
    _type::AVHWDeviceType
    hwctx::Ptr{Cvoid}
    free::Ptr{Cvoid}
    user_opaque::Ptr{Cvoid}
end

struct AVHWFramesInternal
end

struct AVHWFramesContext
    av_class::Ptr{AVClass}
    internal::Ptr{AVHWFramesInternal}
    device_ref::Ptr{AVBufferRef}
    device_ctx::Ptr{AVHWDeviceContext}
    hwctx::Ptr{Cvoid}
    free::Ptr{Cvoid}
    user_opaque::Ptr{Cvoid}
    pool::Ptr{AVBufferPool}
    initial_pool_size::Cint
    format::AVPixelFormat
    sw_format::AVPixelFormat
    width::Cint
    height::Cint
end

# begin enum AVHWFrameTransferDirection
const AVHWFrameTransferDirection = UInt32
const AV_HWFRAME_TRANSFER_DIRECTION_FROM = 0 |> UInt32
const AV_HWFRAME_TRANSFER_DIRECTION_TO = 1 |> UInt32
# end enum AVHWFrameTransferDirection

struct AVHWFramesConstraints
    valid_hw_formats::Ptr{AVPixelFormat}
    valid_sw_formats::Ptr{AVPixelFormat}
    min_width::Cint
    min_height::Cint
    max_width::Cint
    max_height::Cint
end

# begin enum ANONYMOUS_3
const ANONYMOUS_3 = UInt32
const AV_HWFRAME_MAP_READ = 1 |> UInt32
const AV_HWFRAME_MAP_WRITE = 2 |> UInt32
const AV_HWFRAME_MAP_OVERWRITE = 4 |> UInt32
const AV_HWFRAME_MAP_DIRECT = 8 |> UInt32
# end enum ANONYMOUS_3

struct AVCUDADeviceContextInternal
end

struct AVCUDADeviceContext
    cuda_ctx::Cint
    stream::Cint
    internal::Ptr{AVCUDADeviceContextInternal}
end

struct AVD3D11VADeviceContext
    device::Ptr{Cint}
    device_context::Ptr{Cint}
    video_device::Ptr{Cint}
    video_context::Ptr{Cint}
    lock::Ptr{Cvoid}
    unlock::Ptr{Cvoid}
    lock_ctx::Ptr{Cvoid}
end

struct AVD3D11FrameDescriptor
    texture::Ptr{Cint}
    index::Cint
end

struct AVD3D11VAFramesContext
    texture::Ptr{Cint}
    BindFlags::Cint
    MiscFlags::Cint
end

# begin enum ANONYMOUS_4
const ANONYMOUS_4 = UInt32
const AV_DRM_MAX_PLANES = 4 |> UInt32
# end enum ANONYMOUS_4

struct AVDRMObjectDescriptor
    fd::Cint
    size::Csize_t
    format_modifier::UInt64
end

struct AVDRMPlaneDescriptor
    object_index::Cint
    offset::Cptrdiff_t
    pitch::Cptrdiff_t
end

struct AVDRMLayerDescriptor
    format::UInt32
    nb_planes::Cint
    planes::NTuple{4, AVDRMPlaneDescriptor}
end

struct AVDRMFrameDescriptor
    nb_objects::Cint
    objects::NTuple{4, AVDRMObjectDescriptor}
    nb_layers::Cint
    layers::NTuple{4, AVDRMLayerDescriptor}
end

struct AVDRMDeviceContext
    fd::Cint
end

struct AVDXVA2DeviceContext
    devmgr::Ptr{Cint}
end

struct AVDXVA2FramesContext
    surface_type::Cint
    surfaces::Ptr{Ptr{Cint}}
    nb_surfaces::Cint
    decoder_to_release::Ptr{Cint}
end

struct AVMediaCodecDeviceContext
    surface::Ptr{Cvoid}
end

struct AVQSVDeviceContext
    session::Cint
end

struct AVQSVFramesContext
    surfaces::Ptr{Cint}
    nb_surfaces::Cint
    frame_type::Cint
end

# begin enum ANONYMOUS_5
const ANONYMOUS_5 = UInt32
const AV_VAAPI_DRIVER_QUIRK_USER_SET = 1 |> UInt32
const AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS = 2 |> UInt32
const AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE = 4 |> UInt32
const AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = 8 |> UInt32
# end enum ANONYMOUS_5

# struct AVVAAPIDeviceContext
#     display::VADisplay
#     driver_quirks::UInt32
# end

# struct AVVAAPIFramesContext
#     attributes::Ptr{VASurfaceAttrib}
#     nb_attributes::Cint
#     surface_ids::Ptr{VASurfaceID}
#     nb_surfaces::Cint
# end

# struct AVVAAPIHWConfig
#     config_id::VAConfigID
# end

# struct AVVDPAUDeviceContext
#     device::VdpDevice
#     get_proc_address::Ptr{VdpGetProcAddress}
# end

struct AVMasteringDisplayMetadata
    display_primaries::NTuple{3, NTuple{2, AVRational}}
    white_point::NTuple{2, AVRational}
    min_luminance::AVRational
    max_luminance::AVRational
    has_primaries::Cint
    has_luminance::Cint
end

struct AVContentLightMetadata
    MaxCLL::UInt32
    MaxFALL::UInt32
end

struct AVMotionVector
    source::Int32
    w::UInt8
    h::UInt8
    src_x::Int16
    src_y::Int16
    dst_x::Int16
    dst_y::Int16
    flags::UInt64
    motion_x::Int32
    motion_y::Int32
    motion_scale::UInt16
end

const AV_OPT_FLAG_ENCODING_PARAM = 1
const AV_OPT_FLAG_DECODING_PARAM = 2
const AV_OPT_FLAG_AUDIO_PARAM = 8
const AV_OPT_FLAG_VIDEO_PARAM = 16
const AV_OPT_FLAG_SUBTITLE_PARAM = 32
const AV_OPT_FLAG_EXPORT = 64
const AV_OPT_FLAG_READONLY = 128
const AV_OPT_FLAG_BSF_PARAM = 1 << 8
const AV_OPT_FLAG_FILTERING_PARAM = 1 << 16
const AV_OPT_FLAG_DEPRECATED = 1 << 17
const AV_OPT_SEARCH_CHILDREN = 1 << 0
const AV_OPT_SEARCH_FAKE_OBJ = 1 << 1
const AV_OPT_ALLOW_NULL = 1 << 2
const AV_OPT_MULTI_COMPONENT_RANGE = 1 << 12

# Skipping MacroDefinition: av_opt_set_int_list ( obj , name , val , term , flags ) ( av_int_list_length ( val , term ) > INT_MAX / sizeof ( * ( val ) ) ? AVERROR ( EINVAL ) : av_opt_set_bin ( obj , name , ( const uint8_t * ) ( val ) , av_int_list_length ( val , term ) * sizeof ( * ( val ) ) , flags ) )

const AV_OPT_SERIALIZE_SKIP_DEFAULTS = 0x00000001
const AV_OPT_SERIALIZE_OPT_FLAGS_EXACT = 0x00000002

# begin enum ANONYMOUS_6
const ANONYMOUS_6 = UInt32
const AV_OPT_FLAG_IMPLICIT_KEY = 1 |> UInt32
# end enum ANONYMOUS_6

const av_pixelutils_sad_fn = Ptr{Cvoid}

struct AVRC4
    state::NTuple{256, UInt8}
    x::Cint
    y::Cint
end

struct AVReplayGain
    track_gain::Int32
    track_peak::UInt32
    album_gain::Int32
    album_peak::UInt32
end

# begin enum AVSphericalProjection
const AVSphericalProjection = UInt32
const AV_SPHERICAL_EQUIRECTANGULAR = 0 |> UInt32
const AV_SPHERICAL_CUBEMAP = 1 |> UInt32
const AV_SPHERICAL_EQUIRECTANGULAR_TILE = 2 |> UInt32
# end enum AVSphericalProjection

struct AVSphericalMapping
    projection::AVSphericalProjection
    yaw::Int32
    pitch::Int32
    roll::Int32
    bound_left::UInt32
    bound_top::UInt32
    bound_right::UInt32
    bound_bottom::UInt32
    padding::UInt32
end

const AV_STEREO3D_FLAG_INVERT = 1 << 0

# begin enum AVStereo3DType
const AVStereo3DType = UInt32
const AV_STEREO3D_2D = 0 |> UInt32
const AV_STEREO3D_SIDEBYSIDE = 1 |> UInt32
const AV_STEREO3D_TOPBOTTOM = 2 |> UInt32
const AV_STEREO3D_FRAMESEQUENCE = 3 |> UInt32
const AV_STEREO3D_CHECKERBOARD = 4 |> UInt32
const AV_STEREO3D_SIDEBYSIDE_QUINCUNX = 5 |> UInt32
const AV_STEREO3D_LINES = 6 |> UInt32
const AV_STEREO3D_COLUMNS = 7 |> UInt32
# end enum AVStereo3DType

# begin enum AVStereo3DView
const AVStereo3DView = UInt32
const AV_STEREO3D_VIEW_PACKED = 0 |> UInt32
const AV_STEREO3D_VIEW_LEFT = 1 |> UInt32
const AV_STEREO3D_VIEW_RIGHT = 2 |> UInt32
# end enum AVStereo3DView

struct AVStereo3D
    _type::AVStereo3DType
    flags::Cint
    view::AVStereo3DView
end

struct AVTEA
end

struct AVThreadMessageQueue
end

# begin enum AVThreadMessageFlags
const AVThreadMessageFlags = UInt32
const AV_THREAD_MESSAGE_NONBLOCK = 1 |> UInt32
# end enum AVThreadMessageFlags

const AV_TIMECODE_STR_SIZE = 23

# begin enum AVTimecodeFlag
const AVTimecodeFlag = UInt32
const AV_TIMECODE_FLAG_DROPFRAME = 1 |> UInt32
const AV_TIMECODE_FLAG_24HOURSMAX = 2 |> UInt32
const AV_TIMECODE_FLAG_ALLOWNEGATIVE = 4 |> UInt32
# end enum AVTimecodeFlag

const AVTimecode =

struct AVTreeNode
end

struct AVTWOFISH
end

struct AVXTEA
    key::NTuple{16, UInt32}
end


text:
abstract type AbstractBox end

mutable struct CubicBox <: AbstractBox
    a::Float64
end

struct NonPeriodixBox <: AbstractBox
    nothing
end

CubicBox(a::Unitful.Length) = CubicBox(austrip(a))

mutable struct MoleculeSystem
    atoms::Vector{String}
    mass::Vector{Float64}
    function MoleculeSystem()
        new(Vector{String}(), Vector{Float64}())
    end
    function MoleculeSystem(atoms::AbstractVector{String})
        new(atoms, [MDTools.atom_masses[name] for name in atoms])
    end
end

mutable struct SimulationSystem
    mol::MoleculeSystem
    simbox::CubicBox
    integrator::LeapFrog
    coordinates::Matrix{Float64}
    velocities::Matrix{Float64}
    potential
    function SimulationSystem()
        new(MoleculeSystem(), CubicBox(Inf), LeapFrog(0.5u"fs"),
            Matrix{Float64}(undef,0,0), Matrix{Float64}(undef,0,0), Nothing
        )
    end
end

Base.length(m::MoleculeSystem) = length(m.atoms)

function add!(m::MoleculeSystem, name::AbstractString)
    push!(m.atoms, name)
    push!(m.mass, MDTools.atom_masses[name])
    return m
end

function (*)(n::Integer, m::MoleculeSystem)
    return MoleculeSystem(repeat(m.atoms, n))
end

(*)(m::MoleculeSystem, n::Integer) = n*m

function (+)(m1::MoleculeSystem, m2::MoleculeSystem)
    return MoleculeSystem(vcat(m1.atoms, m2.atoms))
end

function add!(ss::SimulationSystem, m::MoleculeSystem; mindis=3.0u"Å", maxtries=100)
    L = PeriodicEuclidean([ss.simbox.a, ss.simbox.a, ss.simbox.a])
    for i in 1:length(m)
        if size(ss.coordinates,1) == 3
            for j in 1:maxtries
                r = ss.simbox.a .* rand(3,1)
                d=pairwise(L, ss.coordinates, r; dims=2)
                if ! any(d .< austrip(mindis))
                    ss.coordinates = hcat(ss.coordinates, r)
                    ss.mol += MoleculeSystem([m.atoms[i]])
                    break
                end
                j == maxtries && error("Out of tries")
            end

        else
            ss.coordinates = ss.simbox.a .* rand(3,1)
            ss.mol += MoleculeSystem([m.atoms[i]])
        end
    end
    return ss
end

ext: jl


text:
using Documenter
using TransportBasedInference

ENV["GKSwstype"] = "nul"

makedocs(
    modules = [TransportBasedInference],
    sitename = "TransportBasedInference.jl",
    doctest = true,
    clean = true,
    pages = [
        # "Home" => "index.md",
        # "Background" => "background.md",
        # "Tutorials" => [
        #                # "tutorials/1.-Estimation-of-the-Banana-distribution.md",
        #                # "tutorials/2.-Conditional-density-estimation-of-the-Banana-distribution.md",
        #                # "tutorials/3.-Structure-discovery-of-the-Lorenz-96.md"
        # #              # "tutorials/4.-Linear-ensemble-filtering-Lorenz-63.md",
        # #              # "tutorials/5.-Linear-ensemble-filtering-Lorenz-96-with-localization.md",
        # #              # "tutorials/6.-Radial-basis-nonlinear-ensemble-filtering-Lorenz-63.md",
        # #              # "tutorials/7.-Radial-basis-nonlinear-ensemble-filtering-Lorenz-96.md"
        #              ],
        # "Manual" => [#"manual/apidoc.md",
        #              "manual/contribute.md",
        #              "manual/LICENSE.md"]
    ],
    format = Documenter.HTML(
        prettyurls = get(ENV, "CI", nothing) == "true",
        mathengine = MathJax(Dict(
            :TeX => Dict(
                :equationNumbers => Dict(:autoNumber => "AMS"),
                :Macros => Dict()
            )
        ))
    )
)

deploydocs(
     repo = "github.com/mleprovost/TransportBasedInference.jl.git",
     target = "build"
)


text:
export TreeNode, Tree, Mutation
export EvoData, LBIData, TreeNodeData
export have_equal_children

import Base: ==

mutable struct Mutation
	i::Int64
	old
	new
end
function Mutation(x::Tuple{Int64,Any,Any})
	return Mutation(x[1],x[2],x[3])
end
function ==(x::Mutation, y::Mutation)
	mapreduce(f->getfield(x,f)==getfield(y,f), *, fieldnames(Mutation), init=true)
end

"""
	abstract type TreeNodeData

Abstract supertype for all data attached to `TreeNode` objects. The *only* requirement is a field `.tau::Union{Missing, <:Real}` containing the time to the ancestor.
"""
abstract type TreeNodeData end

"""
	mutable struct EvoData <: TreeNodeData

Notable fields
- `q`: number of states for sites
- `sequence::Array{Char,1}`
- `mutations::Array{Mutation,1}
"""
mutable struct EvoData <: TreeNodeData
	q::Int64
	sequence::Array{Char,1}
	mutations::Array{Mutation,1}
	tau::Union{Missing, Float64} # Time to ancestor
	nseg::Int64 # number of segments travelling along upper branch
end
function EvoData(; q = 0., sequence = Array{Char,1}(undef, 0), mutations=Array{Mutation,1}(undef, 0), tau = missing, nseg=1)
	return EvoData(q, sequence, mutations, tau, nseg)
end
function ==(x::EvoData, y::EvoData)
	out = x.q == y.q
	out *= x.sequence == y.sequence
	out *= x.mutations == y.mutations
	out *= x.tau === y.tau  # `===` operates on `missing` returning a bool
	out *= x.nseg === y.nseg
	return out
end

"""
	mutable struct LBIData <: TreeNodeData

Data used to compute the Local Branching Index.
"""
mutable struct LBIData <: TreeNodeData
	tau::Float64
	message_down::Float64
	message_up::Float64
	lbi::Float64
	date
	alive::Bool
end
function LBIData(; tau=0.,
				message_down=0.,
				message_up=0.,
				LBI=0.,
				date=0.,
				alive=true)
	return LBIData(tau, message_down, message_up, LBI, date, alive)
end

"""
	mutable struct TreeNode{T <: TreeNodeData}

Structural information on the tree, *i.e.* topology and branch length.
- `anc::Union{Nothing,TreeNode}`: Ancestor
- `child::Array{TreeNode,1}`: List of children
- `tau::Float64`: Time to ancestor
- `isleaf::Bool`
- `isroot::Bool`
- `data::T`
"""
mutable struct TreeNode{T <: TreeNodeData}
	anc::Union{Nothing,TreeNode{T}}
	child::Array{TreeNode{T},1}
	isleaf::Bool
	isroot::Bool
	label::String
	data::T
end
function TreeNode(data::T;
	anc = nothing,
	child = Array{TreeNode{T},1}(undef, 0),
	isleaf = true,
	isroot = true,
	label = "") where T
	return TreeNode(anc, child, isleaf, isroot, label, data)
end
TreeNode() = TreeNode(EvoData())

"""
	==(x::TreeNode, y::TreeNode)

Equality of labels between `x` and `y`. Checking for other properties of nodes turns out to be quite complicated.
"""
function ==(x::TreeNode, y::TreeNode)
	return x.label == y.label
end

"""
	have_equal_children(x::TreeNode, y::TreeNode)

Check whether `x` and `y` have the same children, independent on order. `==` is used to compare children.
"""
function have_equal_children(x::TreeNode, y::TreeNode)
	out = true
	# Is x.child included in y.child?
	for cx in x.child
		flag = false
		for cy in y.child
			if cx == cy
				flag = true
				break
			end
		end
		out *= flag
		if !out
			return false
		end
	end
	# And the other way around
	for cy in x.child
		flag = false
		for cx in y.child
			if cx == cy
				flag = true
				break
			end
		end
		out *= flag
		if !out
			return false
		end
	end
	return out
end

"""
	mutable struct Tree{T <: TreeNodeData}
"""
mutable struct Tree{T <: TreeNodeData}
	root::Union{Nothing, TreeNode{T}}
	nodes::Dict{Int64, TreeNode{T}}
	lnodes::Dict{String, TreeNode{T}}
	leaves::Dict{Int64, TreeNode{T}}
	lleaves::Dict{fieldtype(TreeNode{T}, :label), TreeNode{T}}
end
function Tree(root::TreeNode{T};
	nodes = Dict{Int64, TreeNode{T}}(),
	lnodes = Dict{String, TreeNode{T}}(),
	leaves = Dict{Int64, TreeNode{T}}(),
	lleaves = Dict{fieldtype(TreeNode{T},:label), TreeNode{T}}()) where T
	return Tree(root, nodes, lnodes, leaves, lleaves)
end
Tree() = Tree(TreeNode())

max_stars_repo_name: PierreBarrat/FluPredictibility

max_issues_repo_name: PierreBarrat/FluPredictibility

max_forks_repo_name: PierreBarrat/FluPredictibility


text:
struct RKParam <: EoSParam
    a::PairParam{Float64}
    b::PairParam{Float64}
    Tc::SingleParam{Float64}
    Pc::SingleParam{Float64}
    Mw::SingleParam{Float64}
end

abstract type RKModel <: ABCubicModel end

struct RK{T <: IdealModel,α,M} <: RKModel
    components::Array{String,1}
    icomponents::UnitRange{Int}
    alpha::α
    mixing::M
    params::RKParam
    idealmodel::T
    absolutetolerance::Float64
    references::Array{String,1}
end

has_sites(::Type{<:RKModel}) = false
has_groups(::Type{<:RKModel}) = false
built_by_macro(::Type{<:RKModel}) = false

function Base.show(io::IO, mime::MIME"text/plain", model::RK)
    return eosshow(io, mime, model)
end

function Base.show(io::IO, model::RK)
    return eosshow(io, model)
end

Base.length(model::RK) = Base.length(model.icomponents)

molecular_weight(model::RK,z=SA[1.0]) = comp_molecular_weight(mw(model),z)

export RK
function RK(components::Vector{String}; idealmodel=BasicIdeal,
    alpha = RKAlpha,
    mixing = vdW1fRule,
    activity = nothing,
    userlocations=String[],
    ideal_userlocations=String[],
    alpha_userlocations = String[],
    mixing_userlocations = String[],
    activity_userlocations = String[],
     verbose=false)
    params = getparams(components, ["properties/critical.csv", "properties/molarmass.csv","SAFT/PCSAFT/PCSAFT_unlike.csv"]; userlocations=userlocations, verbose=verbose)
    k  = params["k"]
    _pc = params["pc"]
    pc = _pc.values
    Mw = params["Mw"]
    _Tc = params["Tc"]
    Tc = _Tc.values
    #T̄c = sum(sqrt.(Tc*Tc')) #is this term correctly calculated? sqrt(Tc*Tc') is a matrix sqrt
    Ωa, Ωb = ab_consts(RK)
    a = epsilon_LorentzBerthelot(SingleParam(params["pc"], @. Ωa*R̄^2*Tc^2/pc), k)
    b = sigma_LorentzBerthelot(SingleParam(params["pc"], @. Ωb*R̄*Tc/pc))

    init_idealmodel = init_model(idealmodel,components,ideal_userlocations,verbose)
    init_alpha = init_model(alpha,components,alpha_userlocations,verbose)
    init_mixing = init_model(mixing,components,activity,mixing_userlocations,activity_userlocations,verbose)
    icomponents = 1:length(components)
    packagedparams = RKParam(a, b, params["Tc"],_pc,Mw)
    references = String[]
    model = RK(components,icomponents,init_alpha,init_mixing,packagedparams,init_idealmodel,1e-12,references)
    return model
end

function ab_consts(::Type{<:RKModel})
    Ωa =  1/(9*(2^(1/3)-1))
    Ωb = (2^(1/3)-1)/3
    return Ωa,Ωb
end

function cubic_abp(model::RKModel, V, T, z)
    n = sum(z)
    a,b = cubic_ab(model,V,T,z,n)
    v = V/n
    p =  R̄*T/(v-b) - a/((v+b)*v)
    return a,b,p
end

function cubic_poly(model::RKModel,p,T,z)
    n = sum(z)
    a,b = cubic_ab(model,p,T,z,n)
    RT⁻¹ = 1/(R̄*T)
    A = a*p* RT⁻¹* RT⁻¹
    B = b*p* RT⁻¹
    _1 = one(a)
    return [-A*B, -B*(B+_1) + A, -_1, _1]
end

function a_res(model::RKModel, V, T, z)
    n = sum(z)
    ā,b̄ = cubic_ab(model,V,T,z,n)
    ρ = n/V
    RT⁻¹ = 1/(R̄*T)
    return -log(1-b̄*ρ) - ā*RT⁻¹*log(b̄*ρ+1)/b̄
    #return -log(V-n*b̄) - ā/(R̄*T*b̄*√(T/T̄c))*log(1+n*b̄/V)
end

cubic_zc(::RKModel) = 1/3

# include("variants/SRK.jl")


text:
using LinearAlgebra

function metodo_potencias(E::Matrix, tol = 1e-10, max_iter = 1000)
    m, n = size(E)
    if m != n
        error("A entrada deve ser uma matriz quadrada")
    end
    iter = 0
    erro = tol + 1
    # criando o vetor chute inicial y0 = [1, 0, 0, ..., 0]
    y0 = zeros(size(E)[1], 1)
    y0[1] = 1
    while erro > tol && iter < max_iter
        x = E * y0
        y = x / norm(x)
        erro = abs(abs(dot(y0,y)) - 1)
        # atualizamos y0 e o contador iter
        y0 = y
        iter = iter + 1
    end
    λ = dot(y0, E*y0)
    return λ, y0, iter
    end

max_stars_repo_name: EleonoraAvello/GrupoBetaPacote

max_issues_repo_name: EleonoraAvello/GrupoBetaPacote

max_forks_repo_name: EleonoraAvello/GrupoBetaPacote


text:
A = AxisArray(reshape(1:24, 2,3,4), .1:.1:.2, .1:.1:.3, .1:.1:.4)
D = similar(A)
D[1,1,1,1,1] = 10
@test @inferred(D[1,1,1,1,1]) == @inferred(D[1]) == D.data[1] == 10
@test @inferred(D[1,1,1,:]) == @inferred(D[1,1,1,1:1]) == @inferred(D[1,1,1,[1]]) == AxisArray([10], Axis{:dim_4}(Base.OneTo(1)))

# Test slices

@test A == A.data
@test A[:,:,:] == A[Axis{:row}(:)] == A[Axis{:col}(:)] == A[Axis{:page}(:)] == A.data[:,:,:]
# Test UnitRange slices
@test @inferred(A[1:2,:,:]) == A.data[1:2,:,:] == @inferred(A[Axis{:row}(1:2)])  == @inferred(A[Axis{1}(1:2)]) == @inferred(A[Axis{:row}(ClosedInterval(-Inf,Inf))]) == @inferred(A[[true,true],:,:])
@test @inferred(view(A,1:2,:,:)) == A.data[1:2,:,:] == @inferred(view(A,Axis{:row}(1:2))) == @inferred(view(A,Axis{1}(1:2))) == @inferred(view(A,Axis{:row}(ClosedInterval(-Inf,Inf)))) == @inferred(view(A,[true,true],:,:))
@test @inferred(A[:,1:2,:]) == A.data[:,1:2,:] == @inferred(A[Axis{:col}(1:2)])  == @inferred(A[Axis{2}(1:2)]) == @inferred(A[Axis{:col}(ClosedInterval(0.0, .25))]) == @inferred(A[:,[true,true,false],:])
@test @view(A[:,1:2,:]) == A.data[:,1:2,:] == @view(A[Axis{:col}(1:2)])  == @view(A[Axis{2}(1:2)]) == @view(A[Axis{:col}(ClosedInterval(0.0, .25))]) == @view(A[:,[true,true,false],:])
@test A[:,:,1:2] == A.data[:,:,1:2] == A[Axis{:page}(1:2)] == A[Axis{3}(1:2)] == A[Axis{:page}(ClosedInterval(-1., .22))] == A[:,:,[true,true,false,false]]
@test @view(A[:,:,1:2]) == @view(A.data[:,:,1:2]) == @view(A[Axis{:page}(1:2)]) == @view(A[Axis{3}(1:2)]) == @view(A[Axis{:page}(ClosedInterval(-1., .22))]) == @view(A[:,:,[true,true,false,false]])
# Test scalar slices
@test A[2,:,:] == A.data[2,:,:] == A[Axis{:row}(2)]
@test A[:,2,:] == A.data[:,2,:] == A[Axis{:col}(2)]
@test A[:,:,2] == A.data[:,:,2] == A[Axis{:page}(2)]

# Test fallback methods
@test A[[1 2; 3 4]] == @view(A[[1 2; 3 4]]) == A.data[[1 2; 3 4]]
VERSION >= v"1.0.0-rc" && @test_throws BoundsError A[]

# Test axis restrictions
@test A[:,:,:].axes == A.axes

@test A[Axis{:row}(1:2)].axes[1].val == A.axes[1].val[1:2]
@test A[Axis{:row}(1:2)].axes[2:3] == A.axes[2:3]

@test A[Axis{:col}(1:2)].axes[2].val == A.axes[2].val[1:2]
@test A[Axis{:col}(1:2)].axes[[1,3]] == A.axes[[1,3]]

@test A[Axis{:page}(1:2)].axes[3].val == A.axes[3].val[1:2]
@test A[Axis{:page}(1:2)].axes[1:2] == A.axes[1:2]

# Linear indexing across multiple dimensions drops tracking of those dims
@test A[:].axes[1].val == 1:length(A)
B2 = reshape(A, Val(2))
B = B2[1:2,:]
@test B.axes[1].val == A.axes[1].val[1:2]
@test B.axes[2].val == 1:Base.trailingsize(A,2)

# Logical indexing
all_inds = collect(1:length(A))
odd_inds = collect(1:2:length(A))
@test @inferred(A[trues(size(A))]) == A[:] == A[all_inds]
@test AxisArrays.axes(A[trues(size(A))]) == AxisArrays.axes(A[all_inds])
@test @inferred(A[isodd.(A)]) == A[1:2:length(A)] == A[odd_inds]
@test AxisArrays.axes(A[isodd.(A)]) == AxisArrays.axes(A[odd_inds])
@test @inferred(A[vec(trues(size(A)))]) == A[:] == A[all_inds]
@test AxisArrays.axes(A[vec(trues(size(A)))]) == AxisArrays.axes(A[all_inds])
@test @inferred(A[vec(isodd.(A))]) == A[1:2:length(A)] == A[odd_inds]
@test AxisArrays.axes(A[vec(isodd.(A))]) == AxisArrays.axes(A[odd_inds])

B = AxisArray(reshape(1:15, 5,3), .1:.1:0.5, [:a, :b, :c])

# Test indexing by Intervals
@test B[ClosedInterval(0.0,  0.5), :] == B[ClosedInterval(0.0,  0.5)] == B[:,:]
@test B[ClosedInterval(0.0,  0.3), :] == B[ClosedInterval(0.0,  0.3)] == B[1:3,:]
@test B[ClosedInterval(0.15, 0.3), :] == B[ClosedInterval(0.15, 0.3)] == B[2:3,:]
@test B[ClosedInterval(0.2,  0.5), :] == B[ClosedInterval(0.2,  0.5)] == B[2:end,:]
@test B[ClosedInterval(0.2,  0.6), :] == B[ClosedInterval(0.2,  0.6)] == B[2:end,:]
@test @view(B[ClosedInterval(0.0,  0.5), :]) == @view(B[ClosedInterval(0.0,  0.5)]) == B[:,:]
@test @view(B[ClosedInterval(0.0,  0.3), :]) == @view(B[ClosedInterval(0.0,  0.3)]) == B[1:3,:]
@test @view(B[ClosedInterval(0.15, 0.3), :]) == @view(B[ClosedInterval(0.15, 0.3)]) == B[2:3,:]
@test @view(B[ClosedInterval(0.2,  0.5), :]) == @view(B[ClosedInterval(0.2,  0.5)]) == B[2:end,:]
@test @view(B[ClosedInterval(0.2,  0.6), :]) == @view(B[ClosedInterval(0.2,  0.6)]) == B[2:end,:]

# Test Categorical indexing
@test @inferred(B[:, :a]) == @view(B[:, :a]) == B[:,1]
@test @inferred(B[:, :c]) == @view(B[:, :c]) == B[:,3]
@test @inferred(B[:, [:a]]) == @view(B[:, [:a]]) == B[:,[1]]
@test @inferred(B[:, [:c]]) == @view(B[:, [:c]]) == B[:,[3]]
@test @inferred(B[:, [:a,:c]]) == @view(B[:, [:a,:c]]) == B[:,[1,3]]

@test B[Axis{:row}(ClosedInterval(0.15, 0.3))] == @view(B[Axis{:row}(ClosedInterval(0.15, 0.3))]) == B[2:3,:]

# Test indexing by Intervals that aren't of the form step:step:last
B = AxisArray(reshape(1:15, 5,3), 1.1:0.1:1.5, [:a, :b, :c])
@test B[ClosedInterval(1.0,  1.5), :] == B[ClosedInterval(1.0,  1.5)] == B[:,:]
@test B[ClosedInterval(1.0,  1.3), :] == B[ClosedInterval(1.0,  1.3)] == B[1:3,:]
@test B[ClosedInterval(1.15, 1.3), :] == B[ClosedInterval(1.15, 1.3)] == B[2:3,:]
@test B[ClosedInterval(1.2,  1.5), :] == B[ClosedInterval(1.2,  1.5)] == B[2:end,:]
@test B[ClosedInterval(1.2,  1.6), :] == B[ClosedInterval(1.2,  1.6)] == B[2:end,:]
@test @view(B[ClosedInterval(1.0,  1.5), :]) == @view(B[ClosedInterval(1.0,  1.5)]) == B[:,:]
@test @view(B[ClosedInterval(1.0,  1.3), :]) == @view(B[ClosedInterval(1.0,  1.3)]) == B[1:3,:]
@test @view(B[ClosedInterval(1.15, 1.3), :]) == @view(B[ClosedInterval(1.15, 1.3)]) == B[2:3,:]
@test @view(B[ClosedInterval(1.2,  1.5), :]) == @view(B[ClosedInterval(1.2,  1.5)]) == B[2:end,:]
@test @view(B[ClosedInterval(1.2,  1.6), :]) == @view(B[ClosedInterval(1.2,  1.6)]) == B[2:end,:]

A = AxisArray(reshape(1:256, 4,4,4,4), Axis{:d1}(.1:.1:.4), Axis{:d2}(1//10:1//10:4//10), Axis{:d3}(["1","2","3","4"]), Axis{:d4}([:a, :b, :c, :d]))
ax1 = AxisArrays.axes(A)[1]
@test A[Axis{:d1}(2)] == A[ax1(2)]
@test A.data[1:2,:,:,:] == A[Axis{:d1}(ClosedInterval(.1,.2))]       == A[ClosedInterval(.1,.2),:,:,:]       == A[ClosedInterval(.1,.2),:,:,:,1]       == A[ClosedInterval(.1,.2)]
@test A.data[:,1:2,:,:] == A[Axis{:d2}(ClosedInterval(1//10,2//10))] == A[:,ClosedInterval(1//10,2//10),:,:] == A[:,ClosedInterval(1//10,2//10),:,:,1] == A[:,ClosedInterval(1//10,2//10)]
@test A.data[:,:,1:2,:] == A[Axis{:d3}(["1","2"])]             == A[:,:,["1","2"],:]             == A[:,:,["1","2"],:,1]             == A[:,:,["1","2"]]
@test A.data[:,:,:,1:2] == A[Axis{:d4}([:a,:b])]               == A[:,:,:,[:a,:b]]               == A[:,:,:,[:a,:b],1]

A = AxisArray(reshape(1:32, 2, 2, 2, 2, 2), .1:.1:.2, .1:.1:.2, .1:.1:.2, [:a, :b], [:c, :d])
@test A[ClosedInterval(.15, .25), ClosedInterval(.05, .15), ClosedInterval(.15, .25), :a] == A.data[2:2, 1:1, 2:2, 1, :]
@test A[Axis{:dim_5}(2)] == A.data[:, :, :, :, 2]

# Test vectors
v = AxisArray(collect(.1:.1:10.0), .1:.1:10.0)
@test v[Colon()] == v
@test v[:] == v.data[:] == v[Axis{:row}(:)]
@test v[3:8] == v.data[3:8] == v[ClosedInterval(.25,.85)] == v[Axis{:row}(3:8)] == v[Axis{:row}(ClosedInterval(.22,.88))]

# Test repeated intervals, for different range types

# First, since integers mean "location" rather than value, we have to
# create a number type from which we build a StepRange but which is
# not an Int.
module IL  # put in a module so this file can be re-run
struct IntLike <: Number
    val::Int
end
IntLike(x::IntLike) = x
Base.one(x::IntLike) = IntLike(0)
Base.zero(x::IntLike) = IntLike(0)
Base.isless(x::IntLike, y::IntLike) = isless(x.val, y.val)
Base.:+(x::IntLike, y::IntLike) = IntLike(x.val+y.val)
Base.:-(x::IntLike, y::IntLike) = IntLike(x.val-y.val)
Base.:/(x::IntLike, y::IntLike) = x.val / y.val
Base.rem(x::IntLike, y::IntLike) = IntLike(rem(x.val, y.val))
Base.div(x::IntLike, y::IntLike) = div(x.val, y.val)
Base.:*(x::IntLike, y::Int) = IntLike(x.val * y)
Base.:*(x::Int, y::IntLike) = y*x
Base.:/(x::IntLike, y::Int) = IntLike(x.val / y)
Base.promote_rule(::Type{IntLike}, ::Type{Int}) = Int
Base.convert(::Type{Int}, x::IntLike) = x.val
using AxisArrays
AxisArrays.axistrait(::AbstractVector{IntLike}) = AxisArrays.Dimensional
end

for (r, Irel) in ((0.1:0.1:10.0, -0.5..0.5),  # FloatRange
                  (22.1:0.1:32.0, -0.5..0.5),
                  (range(0.1, stop=10.0, length=100), -0.51..0.51),  # LinSpace
                  (IL.IntLike(1):IL.IntLike(1):IL.IntLike(100),
                   IL.IntLike(-5)..IL.IntLike(5))) # StepRange
    local A, B
    Iabs = r[20]..r[30]
    A = AxisArray([1:100 -1:-1:-100], r, [:c1, :c2])
    @test A[Iabs, :] == A[atindex(Irel, 25), :] == [20:30 -20:-1:-30]
    @test A[Iabs, :] == A[r[25]+Irel, :] == [20:30 -20:-1:-30]
    @test A[Iabs, [:c1,:c2]] == A[atindex(Irel, 25), [:c1, :c2]] == [20:30 -20:-1:-30]
    @test A[Iabs, :c1] == A[atindex(Irel, 25), :c1] == collect(20:30)
    @test A[atindex(Irel, 25), :c1] == collect(20:30)
    @test A[atindex(Irel, [25, 35]), :c1] == [20:30 30:40]
    @test A[r[[25, 35]] + Irel,  :c1] == [20:30 30:40]
    @test_throws BoundsError A[atindex(Irel, 5), :c1]
    @test_throws BoundsError A[atindex(Irel, [5, 15, 25]), :]

    B = A[r[[25, 35]] + Irel,  :c1]
    @test B[:,:] == B[Irel, :] == [20:30 30:40]
end

# Indexing with CartesianIndex
A = AxisArray(reshape(1:15, 3, 5), :x, :y)
@test A[2,2,CartesianIndex(())] == 5
@test A[2,CartesianIndex(()),2] == 5
@test A[CartesianIndex(()),2,2] == 5
A3 = AxisArray(reshape(1:24, 4, 3, 2), :x, :y, :z)
@test A3[2,CartesianIndex(2,2)] == 18
@test A3[CartesianIndex(2,2),2] == 18
@test A3[CartesianIndex(2,2,2)] == 18

# Extracting the full axis
axx = @inferred(A[Axis{:x}])
@test isa(axx, Axis{:x})
@test axx.val == 1:3
axy = @inferred(A[Axis{:y}])
@test isa(axy, Axis{:y})
@test axy.val == 1:5
@test_throws ArgumentError A[Axis{:z}]

# indexing by value (implicitly) in a dimensional axis
some_dates = DateTime(2016, 1, 2, 0):Hour(1):DateTime(2016, 1, 2, 2)
A1 = AxisArray(reshape(1:6, 2, 3), Axis{:x}(1:2), Axis{:y}(some_dates))
A2 = AxisArray(reshape(1:6, 2, 3), Axis{:x}(1:2), Axis{:y}(collect(some_dates)))
for A in (A1, A2)
    local A
    @test A[:, DateTime(2016, 1, 2, 1)] == [3; 4]
    @test A[:, DateTime(2016, 1, 2, 1) .. DateTime(2016, 1, 2, 2)] == [3 5; 4 6]
    @test_throws BoundsError A[:, DateTime(2016, 1, 2, 3)]
    @test_throws BoundsError A[:, DateTime(2016, 1, 1, 23)]
    try
        A[:, DateTime(2016, 1, 2, 3)]
        @test "unreachable" === false
    catch err
        @test err == BoundsError(A.axes[2].val, DateTime(2016, 1, 2, 3))
    end
end

# Test for the expected exception type given repeated axes
A = AxisArray(rand(2,2), :x, :y)
@test_throws ArgumentError A[Axis{:x}(1), Axis{:x}(1)]
@test_throws ArgumentError A[Axis{:y}(1), Axis{:y}(1)]

# Reductions (issues #66, #62)
@test maximum(A3; dims=1) == reshape([4 16; 8 20; 12 24], 1, 3, 2)
@test maximum(A3; dims=2) == reshape([9 21; 10 22; 11 23; 12 24], 4, 1, 2)
@test maximum(A3; dims=3) == reshape(A3[:,:,2], 4, 3, 1)
acc = zeros(Int, 4, 1, 2)
Base.mapreducedim!(x->x>5, +, acc, A3)
@test acc == reshape([1 3; 2 3; 2 3; 2 3], 4, 1, 2)

# Value axistraits
@testset for typ in (IL.IntLike, Complex{Float32}, DateTime, String, Symbol, Int)
    @test AxisArrays.axistrait(Axis{:foo, Vector{AxisArrays.ExactValue{typ}}}) ===
        AxisArrays.axistrait(Axis{:foo, Vector{AxisArrays.TolValue{typ}}}) ===
        AxisArrays.axistrait(Axis{:bar, Vector{typ}})
end

# Indexing by value using `atvalue`
A = AxisArray([1 2; 3 4], Axis{:x}([1.0,4.0]), Axis{:y}([2.0,6.1]))
@test @inferred(A[atvalue(1.0)]) == @inferred(A[atvalue(1.0), :]) == [1,2]
# `atvalue` doesn't require same type:
@test @inferred(A[atvalue(1)]) == @inferred(A[atvalue(1), :]) ==[1,2]
@test A[atvalue(4.0)] == A[atvalue(4.0),:] == [3,4]
@test A[atvalue(4)] == A[atvalue(4),:] == [3,4]
@test_throws BoundsError A[atvalue(5.0)]
@test @inferred(A[atvalue(1.0), atvalue(2.0)]) == 1
@test @inferred(A[:, atvalue(2.0)]) == [1,3]
@test @inferred(A[Axis{:x}(atvalue(4.0))]) == [3,4]
@test @inferred(A[Axis{:y}(atvalue(6.1))]) == [2,4]
@test @inferred(A[Axis{:x}(atvalue(4.00000001))]) == [3,4]
@test @inferred(A[Axis{:x}(atvalue(2.0, atol=5))]) == [1,2]
@test_throws BoundsError A[Axis{:x}(atvalue(4.00000001, rtol=0))]

# Showing Values
@test sprint(show, AxisArrays.ExactValue(1)) == "ExactValue(1)"
@test sprint(show, AxisArrays.TolValue(1., 0.1)) == "TolValue(1.0, tol=0.1)"

# Indexing with ExactValue on Dimensional axes
A = AxisArray([2.0,4.0,6.1], Axis{:x}([-10,1,3]))
@test @inferred(A[AxisArrays.ExactValue(1)]) == @inferred(A[atvalue(1)]) == 4.0
@test_throws BoundsError A[AxisArrays.ExactValue(2)]

# Indexing by array of values
A = AxisArray([1 2 3 4; 5 6 7 8; 9 10 11 12], -1:1, [5.1, 5.4, 5.7, 5.8])
@test @inferred(A[atvalue(-1), atvalue.([5.1, 5.7])]) == [1, 3]
@test_throws BoundsError A[atvalue.([1,2])]

# Indexing by value into an OffsetArray
A = AxisArray(OffsetArrays.OffsetArray([1 2; 3 4], 0:1, 1:2),
    Axis{:x}([1.0,4.0]), Axis{:y}([2.0,6.1]))
@test_broken @inferred(A[atvalue(4.0)]) == [3,4]
@test @inferred(A[:, atvalue(2.0)]) == OffsetArrays.OffsetArray([1,3], 0:1)
@test_throws BoundsError A[atvalue(5.0)]

# Indexing by value directly is forbidden for indexes that are Real
@test_throws ArgumentError A[4.0]
@test_throws ArgumentError A[BigFloat(1.0)]
@test_throws ArgumentError A[1.0f0]
@test_throws ArgumentError A[:,6.1]

# Indexing with `atvalue` on Categorical axes
A = AxisArray([1 2; 3 4], Axis{:x}([:a, :b]), Axis{:y}(["c", "d"]))
@test @inferred(A[atvalue(:a)]) == @inferred(A[atvalue(:a), :]) == [1,2]
@test @inferred(A[atvalue(:b)]) == @inferred(A[atvalue(:b), :]) == [3,4]
@test_throws ArgumentError A[atvalue(:c)]
@test @inferred(A[atvalue(:a), atvalue("c")]) == 1
@test @inferred(A[:, atvalue("c")]) == [1,3]
@test @inferred(A[Axis{:x}(atvalue(:b))]) == [3,4]
@test @inferred(A[Axis{:y}(atvalue("d"))]) == [2,4]

# Index by mystery types categorically
struct Foo
    x
end
A = AxisArray(1:10, Axis{:x}(map(Foo, 1:10)))
@test A[map(Foo, 3:6)] == collect(3:6)
@test_throws ArgumentError A[map(Foo, 3:11)]
@test A[Foo(4)] == 4
@test_throws ArgumentError A[Foo(0)]

# Test using dates
using Dates: Day, Month
A = AxisArray(1:365, Date(2017,1,1):Day(1):Date(2017,12,31))
@test A[Date(2017,2,1) .. Date(2017,2,28)] == collect(31 .+ (1:28)) # February
@test A[(-Day(13)..Day(14)) + Date(2017,2,14)] == collect(31 .+ (1:28))
@test A[(-Day(14)..Day(14)) + DateTime(2017,2,14,12)] == collect(31 .+ (1:28))
@test A[(Day(0)..Day(6)) + (Date(2017,1,1):Month(1):Date(2017,4,12))] == [1:7 32:38 60:66 91:97]

# Test using index types that AxisArrays doesn't understand
# This example is inspired from Interpolations.jl and would implement linear interpolation
struct WeightedIndex{T}
    idx::Int
    weights::Tuple{T,T}
end
Base.to_indices(A, I::Tuple{Vararg{Union{Int,WeightedIndex}}}) = I
@inline function Base._getindex(::IndexStyle, A::AbstractVector, I::WeightedIndex)
    A[I.idx]*I.weights[1] + A[I.idx+1]*I.weights[2]
end
idx = WeightedIndex(2, (0.2, 0.8))

a = [2, 3, 7]
@test a[idx] ≈ 6.2
aa = AxisArray(a, :x)
@test aa[idx] ≈ 6.2


text:
#!/usr/env/bin julia
using Distributed
@everywhere using Printf, Random, Parameters
@everywhere using ArgParse, HDF5, ProgressMeter

setting = ArgParseSettings()
@add_arg_table setting begin
    "--shuffle"
        arg_type = Bool
        default = false
    "--dst"
        arg_type = String
        default = "data.vw"
    "h5"
        required = true
end
@unpack h5, dst, shuffle = parse_args(ARGS, setting)

@everywhere chunk(xs, n) = collect(Iterators.partition(xs, ceil(Int, length(xs)/n)))

@everywhere function part(x, n = myid() - 1, N = nworkers(); dim = ndims(x))
    (n < 1 || size(x)[dim] < N) && return x
    is = chunk(1:size(x, dim), N)
    i = UnitRange(extrema(is[n])...)
    inds = ntuple(x -> x == dim ? i : (:), ndims(x))
    view(x, inds...)
end

@everywhere function tovw(x, y, w, shuffle)
    x = reshape(x, size(x, 1), :)
    dst = joinpath("/dev/shm", tempname() * ".vw")
    fid = open(dst, "w")
    js = shuffle ? randperm(length(y)) : 1:length(y)
    for j in js
        print(fid, y[j], ' ')
        print(fid, w[j], " |f ")
        @inbounds for i in 1:size(x, 1)
            @printf(fid, "%d:%.4g ", i - 1, x[i, j])
        end
        println(fid)
    end
    close(fid)
    return dst
end

srcs = @showprogress "tovw..." pmap(1:100) do n
    h5open(h5) do fid
        x = part(readmmap(fid["x"]), n, 100)
        y = part(readmmap(fid["y"]), n, 100)
        w = part(readmmap(fid["w"]), n, 100)
        tovw(x, y, w, shuffle)
    end
end
shuffle && shuffle!(srcs)

open(dst, "w") do fid
    @showprogress "pd.concat..." for src in srcs
        write(fid, open(read, src))
        rm(src, force = true)
    end
end

print('\n', dst)


text:
@testset "GorFile" begin

    @testset "GorFile" begin

        left = GorFile(GOR.pkgpath("test", "left.gor"))

        @test eltype(left) == NamedTuple{(:Chrom, :Pos, :Val),Tuple{String,Int64,String}}

        val, state = iterate(left)
        @test val == (Chrom = "chr1", Pos = 1, Val = "l1")
    end

    @testset "Table interface" begin

        using Tables
        left = GorFile(GOR.pkgpath("test", "left.gor"))

        @test Tables.istable(left)
        @test Tables.rowaccess(left)
        @test Tables.schema(left) == Tables.Schema{(:Chrom, :Pos, :Val),Tuple{String,Int64,String}}()

        ri = Tables.rows(left)
        val, state = iterate(ri)
        @test val == (Chrom = "chr1", Pos = 1, Val = "l1")

    end
end


text:
using SciMLBenchmarks
if length(ARGS) == 1
    println("Benchmarking the $(ARGS[1]) folder")
    SciMLBenchmarks.weave_folder(ARGS[1])
elseif length(ARGS) == 2
    println("Benchmarking $(ARGS[1])/$(ARGS[2])")
    SciMLBenchmarks.weave_file(ARGS[1],ARGS[2])
else
    error("Only 1 or 2 arguments allowed!")
end


text:
# 第一章
"""
線形回帰分析の係数と切片
```julia
using Random,Distributions
Random.seed!(123)
#データの生成
N=100
a=rand(Normal(2,1),N)
b=randn(1)
x = randn(N)
y = a.*x .+ b + randn(N)
a1, b1 = min_sq(x,y)
```
"""
function min_sq(x::Vector{T},y::Vector{T}) where {T<:Number}
    x̄ = mean(x)
    ȳ = mean(y)
    β₁ = (x .- x̄)'*(y .- ȳ) / norm(x .- x̄)^2 #傾き
    β₀ = ȳ - β₁ * x̄ #切片
    return  β₁,β₀
end

function expand_matrix(X)
    N = typeof(X) <: Matrix  ?  size(X)[1] :  length(X)
    T = eltype(X)
    return hcat(ones(T,N),X)
end
function insert_ones(X)
    N = typeof(X) <: Matrix  ?  size(X)[1] :  length(X)
    T = eltype(X)
    return hcat(ones(T,N),X)
end

"""
重回帰分析の係数
```julia
n = 100; p =2
β = Float64[1,2,3]
x = randn(n,2)
y = @. β[1] + β[2] * x[:,1] + β[3]*x[:,2] + $randn(n)
MultipleRegression(x,y)

3-element Array{Float64,1}:
 0.8957078029816884
 1.904721221695989
 3.1212560196461494
```
"""
function multiple_regression(x::Matrix{T}, y::Vector{T}) where {T<:Number}
    N,_ = size(x)
    @assert N==length(y)
    X = insert_ones(x)
    return (X'X)\X'y
end
function multiple_regression(x::Vector{T}, y::Vector{T}) where {T<:Number}
    return multiple_regression(x[:,:],y)
end

"""
線形回帰分析でのRSS値
"""
function RSS(x::Vector,y)
    β̂ = min_sq(x,y)
    ŷ = β̂[1]*x .+ β̂[2]
    return (y-ŷ)'*(y-ŷ)
end
function RSS(x::Matrix,y)
    ŷ = insert_ones(x)*multiple_regression(x,y)
    return (y-ŷ)'*(y-ŷ)
end

function TSS(y)
    length(y)==0 && return 0
    Y = y .- mean(y)
    return Y'*Y
end

ESS(x,y) = TSS(y) - RSS(x,y)

R2(x,y) = ESS(x,y)/TSS(y)

function RSE(x::Matrix,y)
    n,p = size(x)
    RSS(x,y) / (n-p-1)
end

function RSE(x::Vector,y)
    RSS(x,y) / (length(x)-2)
end

function Bdiag(x)
    X = insert_ones(x)
    return X'X |> inv |> diag
end

"""
VIF(variance inflation factor)
"""
function VIF(x::Matrix)
    _,ncol= size(x)
    v = Vector{Float64}(undef,ncol)
    for j in 1:ncol
        # index = delete!(Set(1:ncol),j) |> collect
        index = setdiff(1:ncol,j)
        v[j] = 1/(1-R2(x[:,index],x[:,j]))
    end
    return v
end

"""
confident_interval(xp,x,y;α=0.01)

線形回帰における信頼区間(予測したい場所での標準偏差)を返す。
xp:説明変数の予測データ
x:説明変数の学習データ
y:目的変数の学習データ
α:0.01 は99%信頼区間
"""
function confident_interval(xp,x,y;α=0.01)
    N,p = size(x)
    X = insert_ones(x)
    XP = insert_ones(xp)
    typeof(xp) <:Number && (xp =[xp])
    yerror = quantile(TDist(N-p-1),1-α/2) * sqrt.(diag(XP * ((X'X) \ XP')))
end

function prediction_interval(xp,x,y;α=0.01)
    N,p = size(x)
    X = insert_ones(x)
    XP = insert_ones(xp)
    typeof(xp) <:Number && (xp =[xp])
    yerror = quantile(TDist(N-p-1),1-α/2) * sqrt.( 1 .+ diag(XP * ((X'X) \ XP')))
end


text:
using LinearAlgebra
n = 6;
A = rand([1.,10.],n,n)


text:
# finiteEnvironment.jl
# The environment of finite MPS and MPO form of Hamiltonian.
# an be used to do DMRG or calculating physical observables
"""
    struct FiniteEnvironment{S<:EuclideanSpace}
"""
struct FiniteEnvironment{S<:EuclideanSpace}
    left_env::Vector{<:AbstractTensorMap{S,1,2}}
    right_env::Vector{<:AbstractTensorMap{S,2,1}}
end

function initialize_FiniteEnvironment(mps::FiniteMPS, mpo::MPO, final_position::Int)
    spacetype(mps) == spacetype(mpo) || error("mps and mpo must have the same spacetype!")
    mps.canonical_form[1] == :right_canonical ||
        throw(ArgumentError("input mps should be in the right canonical form!"))
    N = length(mps.Ts)
    N == length(mpo.Ws) || error("mps and mpo must have the same length!")
    left_env = append!([TensorMap(undef, codomain(mps.Ts[i],1),
                            codomain(mps.Ts[i],1)*codomain(mpo.Ws[i],1)) for i in 1:N],
                       [TensorMap(undef, domain(mps.Ts[end]),
                            domain(mps.Ts[end])*domain(mpo.Ws[end],2))])
    right_env = append!([TensorMap(undef,codomain(mps.Ts[i],1)*codomain(mpo.Ws[i],1),
                            codomain(mps.Ts[i],1)) for i in 1:N],
                        [TensorMap(undef,domain(mps.Ts[end])*domain(mpo.Ws[end],2),
                            domain(mps.Ts[end]))])
    chi_mpo_left_boundary = dim(codomain(mpo.Ws[1],1))
    chi_mpo_right_boundary = dim(domain(mpo.Ws[end],2))
    left_boundary_matrix = zeros(1,1,chi_mpo_left_boundary)
    right_boundary_matrix = zeros(1,chi_mpo_right_boundary,1)
    left_boundary_matrix[1,1,final_position] = 1
    right_boundary_matrix[1,1,1] = 1
    left_boundary_tensor = TensorMap(left_boundary_matrix, codomain(mps.Ts[1],1),
                                        codomain(mps.Ts[1],1)*codomain(mpo.Ws[1],1))
    right_boundary_tensor = TensorMap(right_boundary_matrix,
                            domain(mps.Ts[end])*domain(mpo.Ws[end],2),domain(mps.Ts[end]))
    left_env[1] = left_boundary_tensor
    right_env[end] = right_boundary_tensor
    env = FiniteEnvironment{spacetype(mps)}(left_env,right_env)
    for i in N:-1:1
        update_right_env(i, mps, mpo, env)
    end
    return env
end

function update_left_env(i::Int, mps::FiniteMPS, mpo::MPO, env::FiniteEnvironment)
    @tensor A_tmp1[c d;b e] := env.left_env[i-1][c;a b]*mps.Ts[i-1][a d; e]
    @tensor A_tmp2[a e;d f] := A_tmp1[a b;c d]*mpo.Ws[i-1][c e;b f]
    @tensor A_tmp3[e;c d] := conj(mps.Ts[i-1][a b;e])*A_tmp2[a b;c d]
    env.left_env[i] = A_tmp3
end

function update_right_env(i::Int, mps::FiniteMPS, mpo::MPO, env::FiniteEnvironment)
    @tensor A_tmp1[d e b;c] := mps.Ts[i][d e;a]*env.right_env[i+1][a b;c]
    @tensor A_tmp2[a e f;d] := mpo.Ws[i][e f;b c]*A_tmp1[a b c;d]
    @tensor A_tmp3[a b;e] := A_tmp2[a b c;d]*conj(mps.Ts[i][e c;d])
    env.right_env[i] = A_tmp3
end


text:
using Cbc
using DataFrames
using Distances
using JuMP
using LinearAlgebra

cities = DataFrame(
    city=[ "New York, NY", "Los Angeles, CA", "Chicago, IL", "Houston, TX", "Philadelphia, PA", "Phoenix, AZ", "San Antonio, TX", "San Diego, CA", "Dallas, TX", "San Jose, CA", "Austin, TX", "Indianapolis, IN", "Jacksonville, FL", "San Francisco, CA", "Columbus, OH", "Charlotte, NC", "Fort Worth, TX", "Detroit, MI", "El Paso, TX", "Memphis, TN"],
    population=[8405837,3884307,2718782,2195914,1553165,1513367,1409019,1355896,1257676,998537,885400,843393,842583,837442,822553,792862,792727,688701,674433,653450],
    lat=[40.7127,34.0522,41.8781,29.7604,39.9525,33.4483,29.4241,32.7157,32.7766,37.3382,30.2671,39.7684,30.3321,37.7749,39.9611,35.2270,32.7554,42.3314,31.7775,35.1495],
    lon=[-74.0059,-118.2436,-87.6297,-95.3698,-75.1652,-112.0740,-98.4936,-117.1610,-96.7969,-121.8863,-97.7430,-86.1580,-81.6556,-122.4194,-82.9987,-80.8431,-97.3307,-83.0457,-106.4424,-90.0489]
)

n = size(cities,1)
k = 3
P = sum(cities.population) / k

dm = Distances.pairwise(Haversine(6372.8), Matrix(cities[:, [3,4]])', dims=2)
dm = LowerTriangular(dm)

model = Model(Cbc.Optimizer)

@variable(model, x[1:n, 1:k], Bin)

for i in 1:n
    @constraint(model, sum(x[i,:]) == 1)
end

α = -2_500_000
β = 2_500_000

for i in 1:k
    @constraint(model, (x' * cities.population)[i] - P <= β)
    @constraint(model, (x' * cities.population)[i] - P >= α)
end

@variable(model, z[1:n,1:n], Bin)

for k in 1:k, i in 1:n, j in 1:n
    @constraint(model, z[i,j] >= x[i,k] + x[j,k] - 1)
end

@objective(model, Min, dot(z,dm));

optimize!(model)

cities.group = zeros(n)

for i in 1:n, j in 1:k
    if round(value.(x)[i,j]) == 1.0
        cities.group[i] = j
    end
end

for group in groupby(cities, :group)
    @show group
    println("")
    @show sum(group.population)
    println("")
end


text:
const cardpbk = 14012298 # Card's public key
const doorpbk = 74241  # Door's public key
# Puzze input

const subjectnum = 7
# Subject number

const transfnum = 20201227
# Number used in the operaration that transform a subject number

# The card transforms the subject number of 7 according to the card's
# secret loop size. The result is called the card's public key (cardpbk).

function findloopzise(pbk)
    val = 1
    for i ∈ 1:typemax(Int)
        # To transform a subject number (subjectnum), start with the value 1.
        # Then, a number of times called the loop size, perform the following steps:

        val *= subjectnum
        # 1. Set the value to itself multiplied by the subject number.

        val %= transfnum
        # 2. Set the value to the remainder after dividing the value
        # by 20201227 (transfnum)

        if val == pbk
            # The card transforms the subject number of 7 according to
            # the card's secret loop size. The result is called the card's public key.
            # Then when val is equal to out public ket we found our secret loop size

            return i # Secret loop size
        end
    end
end

function findencriptkey(cardpbk, doorpbk)
    cardloopsize = findloopzise(cardpbk)
    doorloopsize = findloopzise(doorpbk)

    # You can use either device's loop size with the other device's public key
    # to calculate the encryption key

    subjectnum = doorpbk
    encriptkey₁ = 1
    for i ∈ 1:cardloopsize
        # The card transforms the subject number of the door's public key
        # according to the card's loop size. The result is the encryption key.

        encriptkey₁ *= subjectnum
        encriptkey₁ %= transfnum
    end

    subjectnum = cardpbk
    encriptkey₂ = 1
    for i ∈ 1:doorloopsize
        # Transforming the subject number of cardpbk (the card's public key)
        # with a loop size of doorloopsize produces the encryption key

        encriptkey₂ *= subjectnum
        encriptkey₂ %= transfnum
    end
    return encriptkey₁, encriptkey₂
end

findencriptkey(cardpbk, doorpbk)