⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.c

📁 mpeg4 video codec mpeg4 video codec
💻 C
📖 第 1 页 / 共 2 页
字号:
    s->qmin= 2;    s->qmax= 31;    s->mb_lmin= FF_QP2LAMBDA * 2;    s->mb_lmax= FF_QP2LAMBDA * 31;    s->rc_eq= "tex^qComp";    s->qcompress= 0.5;    s->max_qdiff= 3;    s->b_quant_factor=1.25;    s->b_quant_offset=1.25;    s->i_quant_factor=-0.8;    s->i_quant_offset=0.0;    s->error_concealment= 3;    s->error_resilience= 1;    s->workaround_bugs= FF_BUG_AUTODETECT;    s->time_base.num=0;s->time_base.den=1;// (AVRational){0,1};    s->gop_size= 50;    s->me_method= ME_EPZS;    s->get_buffer= avcodec_default_get_buffer;    s->release_buffer= avcodec_default_release_buffer;    s->get_format= avcodec_default_get_format;    s->execute= avcodec_default_execute;    s->thread_count=1;    s->me_subpel_quality=8;    s->lmin= FF_QP2LAMBDA * s->qmin;    s->lmax= FF_QP2LAMBDA * s->qmax;    s->sample_aspect_ratio.num=0;s->sample_aspect_ratio.den=1;// = (AVRational){0,1};    s->ildct_cmp= FF_CMP_VSAD;    s->profile= FF_PROFILE_UNKNOWN;    s->level= FF_LEVEL_UNKNOWN;    s->me_penalty_compensation= 256;    s->pix_fmt= PIX_FMT_NONE;    s->frame_skip_cmp= FF_CMP_DCTMAX;    s->nsse_weight= 8;        s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;    s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;    s->palctrl = NULL;    s->reget_buffer= avcodec_default_reget_buffer;}/** * allocates a AVCodecContext and set it to defaults. * this can be deallocated by simply calling free()  */AVCodecContext *avcodec_alloc_context(void){    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));        if(avctx==NULL) return NULL;        avcodec_get_context_defaults(avctx);        return avctx;}void avcodec_get_frame_defaults(AVFrame *pic){    memset(pic, 0, sizeof(AVFrame));    pic->pts= AV_NOPTS_VALUE;    pic->key_frame= 1;}/** * allocates a AVPFrame and set it to defaults. * this can be deallocated by simply calling free()  */AVFrame *avcodec_alloc_frame(void){    AVFrame *pic= av_malloc(sizeof(AVFrame));        if(pic==NULL) return NULL;        avcodec_get_frame_defaults(pic);        return pic;}int avcodec_open(AVCodecContext *avctx, AVCodec *codec){    int ret= -1;        entangled_thread_counter++;    if(entangled_thread_counter != 1){        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");        goto end;    }    if(avctx->codec)        goto end;    avctx->codec = codec;    avctx->codec_id = codec->id;    avctx->frame_number = 0;    if (codec->priv_data_size > 0) {    avctx->priv_data = av_mallocz(codec->priv_data_size);    if (!avctx->priv_data)             goto end;    } else {        avctx->priv_data = NULL;    }    if(avctx->coded_width && avctx->coded_height)        avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);    else if(avctx->width && avctx->height)        avcodec_set_dimensions(avctx, avctx->width, avctx->height);    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){        av_freep(&avctx->priv_data);        goto end;    }    ret = avctx->codec->init(avctx);    if (ret < 0) {        av_freep(&avctx->priv_data);        goto end;    }    ret=0;end:    entangled_thread_counter--;        return ret;    }int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,                          const short *samples){    if(buf_size < FF_MIN_BUFFER_SIZE && 0){        av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");        return -1;    }    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){        int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);    avctx->frame_number++;    return ret;    }else        return 0;}int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,                          const AVFrame *pict){    if(buf_size < FF_MIN_BUFFER_SIZE){        av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");        return -1;    }    if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))        return -1;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){        int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);        avctx->frame_number++;        emms_c(); //needed to avoid an emms_c() call before every return;    return ret;    }else        return 0;}int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,                             const AVSubtitle *sub){    int ret;    ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);    avctx->frame_number++;    return ret;}/**  * decode a frame.  * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param buf_size the size of the buffer in bytes * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero * @return -1 if error, otherwise return the number of * bytes used.  */int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,                          int *got_picture_ptr,                         uint8_t *buf, int buf_size){    int ret;	    *got_picture_ptr= 0;    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))        return -1;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){    ret = avctx->codec->decode(avctx, picture, got_picture_ptr,                                buf, buf_size);        emms_c(); //needed to avoid an emms_c() call before every return;    if (*got_picture_ptr)                                   avctx->frame_number++;    }else        ret= 0;    return ret;}/* decode an audio frame. return -1 if error, otherwise return the   *number of bytes used. If no frame could be decompressed,   *frame_size_ptr is zero. Otherwise, it is the decompressed frame   *size in BYTES. */int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,                          int *frame_size_ptr,                         uint8_t *buf, int buf_size){    int ret;    *frame_size_ptr= 0;    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){    ret = avctx->codec->decode(avctx, samples, frame_size_ptr,                                buf, buf_size);    avctx->frame_number++;    }else        ret= 0;    return ret;}/* decode a subtitle message. return -1 if error, otherwise return the   *number of bytes used. If no subtitle could be decompressed,   *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,                            int *got_sub_ptr,                            const uint8_t *buf, int buf_size){    int ret;    *got_sub_ptr = 0;    ret = avctx->codec->decode(avctx, sub, got_sub_ptr,                                (uint8_t *)buf, buf_size);    if (*got_sub_ptr)        avctx->frame_number++;    return ret;}int avcodec_close(AVCodecContext *avctx){    entangled_thread_counter++;    if(entangled_thread_counter != 1){        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");        entangled_thread_counter--;        return -1;    }    if (avctx->codec && avctx->codec->close)        avctx->codec->close(avctx);    avcodec_default_free_buffers(avctx);    av_freep(&avctx->priv_data);    avctx->codec = NULL;    entangled_thread_counter--;    return 0;}AVCodec *avcodec_find_encoder(enum CodecID id){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->encode != NULL && p->id == id)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_encoder_by_name(const char *name){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->encode != NULL && strcmp(name,p->name) == 0)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_decoder(enum CodecID id){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->decode != NULL && p->id == id)            return p;        p = p->next;    }    return NULL;}AVCodec *avcodec_find_decoder_by_name(const char *name){    AVCodec *p;    p = first_avcodec;    while (p) {        if (p->decode != NULL && strcmp(name,p->name) == 0)            return p;        p = p->next;    }    return NULL;}unsigned avcodec_version( void ){  return LIBAVCODEC_VERSION_INT;}unsigned avcodec_build( void ){  return LIBAVCODEC_BUILD;}/* must be called before any other functions */void avcodec_init(void){    /*static*/ int inited = 0;    if (inited != 0)	return;    inited = 1;#if __STDC_VERSION__ < 199901L    {    extern void avpicture_init_pixfmtinfo(void);    avpicture_init_pixfmtinfo();    } #endif        dsputil_static_init();}/** * Flush buffers, should be called when seeking or when swicthing to a different stream. */void avcodec_flush_buffers(AVCodecContext *avctx){    if(avctx->codec->flush)        avctx->codec->flush(avctx);}void avcodec_default_free_buffers(AVCodecContext *s){    int i, j;    if(s->internal_buffer==NULL) return;        for(i=0; i<INTERNAL_BUFFER_SIZE; i++){        InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];        for(j=0; j<4; j++){            av_freep(&buf->base[j]);            buf->data[j]= NULL;        }    }    av_freep(&s->internal_buffer);        s->internal_buffer_count=0;}char av_get_pict_type_char(int pict_type){    switch(pict_type){    case I_TYPE: return 'I';     case P_TYPE: return 'P';     case B_TYPE: return 'B';     case S_TYPE: return 'S';     case SI_TYPE:return 'i';     case SP_TYPE:return 'p';     default:     return '?';    }}/* av_log API */static int av_log_level = AV_LOG_INFO;static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl){    static int print_prefix=1;    AVClass* avc= ptr ? *(AVClass**)ptr : NULL;    if(level>av_log_level)	return;#undef fprintf    if(print_prefix && avc) {	    fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);    }#define fprintf please_use_av_log    print_prefix= strstr(fmt, "\n") != NULL;    vfprintf(stderr, fmt, vl);}static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;void av_log(void* avcl, int level, const char *fmt, ...){    va_list vl;    va_start(vl, fmt);    av_vlog(avcl, level, fmt, vl);    va_end(vl);}void av_vlog(void* avcl, int level, const char *fmt, va_list vl){    av_log_callback(avcl, level, fmt, vl);}int av_log_get_level(void){    return av_log_level;}void av_log_set_level(int level){    av_log_level = level;}void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)){    av_log_callback = callback;}#if !defined(HAVE_THREADS)int avcodec_thread_init(AVCodecContext *s, int thread_count){    return -1;}#endifunsigned int av_xiphlacing(unsigned char *s, unsigned int v){    unsigned int n = 0;    while(v >= 0xff) {        *s++ = 0xff;        v -= 0xff;        n++;    }    *s = v;    n++;    return n;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -