memoの最近のブログ記事

メモ

| コメント(0) | トラックバック(0)



苦戦中. うう...


avcodec_encode_video



int attribute_align_arg 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 than 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, pict);
avctx->frame_number++;
emms_c(); //needed to avoid an emms_c() call before every return;

return ret;
}else
return 0;
}

AVCodec



typedef struct AVCodec {
/**
* Name of the codec implementation.
* The name is globally unique among encoders and among decoders (but an
* encoder and a decoder can share the same name).
* This is the primary way to find a codec from the user perspective.
*/
const char *name;
enum CodecType type;
enum CodecID id;
int priv_data_size;
int (*init)(AVCodecContext *);
int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
int (*close)(AVCodecContext *);
int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
/**
* Codec capabilities.
* see CODEC_CAP_*
*/
int capabilities;
struct AVCodec *next;
/**
* Flush buffers.
* Will be called when seeking
*/
void (*flush)(AVCodecContext *);
const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
/**
* Descriptive name for the codec, meant to be more human readable than name.
* You should use the NULL_IF_CONFIG_SMALL() macro to define it.
*/
const char *long_name;
const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
} AVCodec;

int ff_xvid_encode_frame(AVCodecContext *avctx,
                         unsigned char *frame, int buf_size, void *data) {
    int xerr, i;
    char *tmp;
    struct xvid_context *x = avctx->priv_data;
    AVFrame *picture = data;
    AVFrame *p = &(x->encoded_picture);

xvid_enc_frame_t xvid_enc_frame;
xvid_enc_stats_t xvid_enc_stats;

/* Start setting up the frame */
memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame));
xvid_enc_frame.version = XVID_VERSION;
memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats));
xvid_enc_stats.version = XVID_VERSION;
*p = *picture;

/* Let Xvid know where to put the frame. */
xvid_enc_frame.bitstream = frame;
xvid_enc_frame.length = buf_size;

/* Initialize input image fields */
if( avctx->pix_fmt != PIX_FMT_YUV420P ) {
av_log(avctx, AV_LOG_ERROR, "Xvid: Color spaces other than 420p not supported\n");
return -1;
}

xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */

for( i = 0; i < 4; i++ ) {
xvid_enc_frame.input.plane[i] = picture->data[i];
xvid_enc_frame.input.stride[i] = picture->linesize[i];
}

/* Encoder Flags */
xvid_enc_frame.vop_flags = x->vop_flags;
xvid_enc_frame.vol_flags = x->vol_flags;
xvid_enc_frame.motion = x->me_flags;
xvid_enc_frame.type = XVID_TYPE_AUTO;

/* Pixel aspect ratio setting */
if (avctx->sample_aspect_ratio.num < 1 || avctx->sample_aspect_ratio.num > 255 ||
avctx->sample_aspect_ratio.den < 1 || avctx->sample_aspect_ratio.den > 255) {
av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n",
avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
return -1;
}
xvid_enc_frame.par = XVID_PAR_EXT;
xvid_enc_frame.par_width = avctx->sample_aspect_ratio.num;
xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;

/* Quant Setting */
if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
else xvid_enc_frame.quant = 0;

/* Matrices */
xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
xvid_enc_frame.quant_inter_matrix = x->inter_matrix;

/* Encode */
xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE,
&xvid_enc_frame, &xvid_enc_stats);

/* Two-pass log buffer swapping */
avctx->stats_out = NULL;
if( x->twopassbuffer ) {
tmp = x->old_twopassbuffer;
x->old_twopassbuffer = x->twopassbuffer;
x->twopassbuffer = tmp;
x->twopassbuffer[0] = 0;
if( x->old_twopassbuffer[0] != 0 ) {
avctx->stats_out = x->old_twopassbuffer;
}
}

if( 0 <= xerr ) {
p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
if( xvid_enc_stats.type == XVID_TYPE_PVOP )
p->pict_type = FF_P_TYPE;
else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
p->pict_type = FF_B_TYPE;
else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
p->pict_type = FF_S_TYPE;
else
p->pict_type = FF_I_TYPE;
if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
p->key_frame = 1;
if( x->quicktime_format )
return xvid_strip_vol_header(avctx, frame,
xvid_enc_stats.hlength, xerr);
} else
p->key_frame = 0;

return xerr;
} else {
av_log(avctx, AV_LOG_ERROR, "Xvid: Encoding Error Occurred: %i\n", xerr);
return -1;
}
}

このアーカイブについて

このページには、過去に書かれたブログ記事のうちmemoカテゴリに属しているものが含まれています。

前のカテゴリはLinuxです。

次のカテゴリはMIDIです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

ウェブページ

Powered by Movable Type 4.32-ja