int64_t sync_opts;
/* video only */
int video_resample; /* video_resample and video_crop are mutually exclusive */
- AVPicture pict_tmp; /* temporary image for resampling */
+ AVFrame pict_tmp; /* temporary image for resampling */
ImgReSampleContext *img_resample_ctx; /* for image resampling */
int video_crop; /* video_resample and video_crop are mutually exclusive */
int *frame_size, AVOutputStream *audio_sync)
{
int nb_frames, i, ret;
- AVPicture *final_picture, *formatted_picture;
- AVPicture picture_format_temp, picture_crop_temp;
+ AVFrame *final_picture, *formatted_picture;
+ AVFrame picture_format_temp, picture_crop_temp;
static uint8_t *video_buffer= NULL;
uint8_t *buf = NULL, *buf1 = NULL;
AVCodecContext *enc, *dec;
enum PixelFormat target_pixfmt;
-
+
#define VIDEO_BUFFER_SIZE (1024*1024)
+ avcodec_get_frame_defaults(&picture_format_temp);
+ avcodec_get_frame_defaults(&picture_crop_temp);
+
enc = &ost->st->codec;
dec = &ist->st->codec;
if (!buf)
return;
formatted_picture = &picture_format_temp;
- avpicture_fill(formatted_picture, buf, target_pixfmt, dec->width, dec->height);
+ avpicture_fill((AVPicture*)formatted_picture, buf, target_pixfmt, dec->width, dec->height);
- if (img_convert(formatted_picture, target_pixfmt,
+ if (img_convert((AVPicture*)formatted_picture, target_pixfmt,
(AVPicture *)in_picture, dec->pix_fmt,
dec->width, dec->height) < 0) {
goto the_end;
}
} else {
- formatted_picture = (AVPicture *)in_picture;
+ formatted_picture = in_picture;
}
/* XXX: resampling could be done before raw format conversion in
/* XXX: only works for YUV420P */
if (ost->video_resample) {
final_picture = &ost->pict_tmp;
- img_resample(ost->img_resample_ctx, final_picture, formatted_picture);
+ img_resample(ost->img_resample_ctx, (AVPicture*)final_picture, (AVPicture*)formatted_picture);
if (ost->padtop || ost->padbottom || ost->padleft || ost->padright) {
- fill_pad_region(final_picture, enc->height, enc->width,
+ fill_pad_region((AVPicture*)final_picture, enc->height, enc->width,
ost->padtop, ost->padbottom, ost->padleft, ost->padright,
padcolor);
}
if (!buf)
return;
final_picture = &picture_format_temp;
- avpicture_fill(final_picture, buf, enc->pix_fmt, enc->width, enc->height);
+ avpicture_fill((AVPicture*)final_picture, buf, enc->pix_fmt, enc->width, enc->height);
- if (img_convert(final_picture, enc->pix_fmt,
- &ost->pict_tmp, PIX_FMT_YUV420P,
+ if (img_convert((AVPicture*)final_picture, enc->pix_fmt,
+ (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P,
enc->width, enc->height) < 0) {
if (verbose >= 0)
}
}
- fill_pad_region(final_picture, enc->height, enc->width,
+ fill_pad_region((AVPicture*)final_picture, enc->height, enc->width,
ost->padtop, ost->padbottom, ost->padleft, ost->padright,
padcolor);
if (!buf)
return;
final_picture = &picture_format_temp;
- avpicture_fill(final_picture, buf, enc->pix_fmt, enc->width, enc->height);
+ avpicture_fill((AVPicture*)final_picture, buf, enc->pix_fmt, enc->width, enc->height);
- if (img_convert(final_picture, enc->pix_fmt,
- &ost->pict_tmp, PIX_FMT_YUV420P,
+ if (img_convert((AVPicture*)final_picture, enc->pix_fmt,
+ (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P,
enc->width, enc->height) < 0) {
if (verbose >= 0)
enc->coded_frame = old_frame;
} else {
AVFrame big_picture;
-
- avcodec_get_frame_defaults(&big_picture);
- *(AVPicture*)&big_picture= *final_picture;
+
+ big_picture= *final_picture;
/* better than nothing: use input picture interlaced
settings */
big_picture.interlaced_frame = in_picture->interlaced_frame;
big_picture.quality = ist->st->quality;
}else
big_picture.quality = ost->st->quality;
+ big_picture.pict_type = 0;
ret = avcodec_encode_video(enc,
video_buffer, VIDEO_BUFFER_SIZE,
&big_picture);
ost->padleft = frame_padleft;
ost->padbottom = frame_padbottom;
ost->padright = frame_padright;
- if( avpicture_alloc( &ost->pict_tmp, PIX_FMT_YUV420P,
+ if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P,
codec->width, codec->height ) )
goto fail;
} else {
ost->video_resample = 1;
ost->video_crop = 0; // cropping is handled as part of resample
- if( avpicture_alloc( &ost->pict_tmp, PIX_FMT_YUV420P,
+ if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, PIX_FMT_YUV420P,
codec->width, codec->height ) )
goto fail;
+ avcodec_get_frame_defaults(&ost->pict_tmp);
ost->img_resample_ctx = img_resample_full_init(
ost->st->codec.width, ost->st->codec.height,
#define FFMPEG_VERSION_INT 0x000408
#define FFMPEG_VERSION "0.4.8"
-#define LIBAVCODEC_BUILD 4708
+#define LIBAVCODEC_BUILD 4709
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION
\
/**\
* Motion vector table\
- * - encoding: unused\
+ * - encoding: set by user\
* - decoding: set by lavc\
*/\
int16_t (*motion_val[2])[2];\
/**\
* Macroblock type table\
* mb_type_base + mb_width + 2\
- * - encoding: unused\
+ * - encoding: set by user\
* - decoding: set by lavc\
*/\
uint32_t *mb_type;\
* - decoding: set by lavc\
*/\
short *dct_coeff;\
+\
+ /**\
+ * Motion referece frame index\
+ * - encoding: set by user\
+ * - decoding: set by lavc\
+ */\
+ int8_t *ref_index[2];
#define FF_QSCALE_TYPE_MPEG1 0
#define FF_QSCALE_TYPE_MPEG2 1
#define FF_BUFFER_TYPE_INTERNAL 1
#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
-#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base)
+#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base), all other tables are not shared
#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything
* - decoding: set by execute()
*/
void *thread_opaque;
+
+ /**
+ * Motion estimation threshold.
+ *
+ * - encoding: set by user
+ * - decoding: set by user
+ */
+ void *me_threshold;
} AVCodecContext;
dst->interlaced_frame = src->interlaced_frame;
dst->top_field_first = src->top_field_first;
- if(src->motion_val[0] && src->motion_val[0] != dst->motion_val[0]){
+ if(s->avctx->me_threshold){
+ if(!src->motion_val[0])
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n");
+ if(!src->mb_type)
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n");
+ if(!src->ref_index[0])
+ av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n");
if(src->motion_subsample_log2 != dst->motion_subsample_log2)
av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesnt match!\n");
- else{
+
+ memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0]));
+
+ for(i=0; i<2; i++){
int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
int height= ((16*s->mb_height)>>src->motion_subsample_log2);
- for(i=0; i<2; i++)
- memcpy(dst->motion_val[i], src->motion_val[i], stride*height*sizeof(int16_t));
+ if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){
+ memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t));
+ }
+ if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){
+ memcpy(dst->ref_index[i], src->ref_index[i], s->mb_stride*s->mb_height*sizeof(int8_t)); //FIXME init this too
+ }
}
}
}
for(i=0; i<2; i++){
CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t))
pic->motion_val[i]= pic->motion_val_base[i]+2;
+ CHECKED_ALLOCZ(pic->ref_index[i], mb_array_size * sizeof(int8_t))
}
pic->motion_subsample_log2= 3;
}