diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/Makefile | 10 | ||||
-rw-r--r-- | libhb/deinterlace.c | 4 | ||||
-rw-r--r-- | libhb/hb.c | 82 | ||||
-rw-r--r-- | libhb/render.c | 35 |
4 files changed, 73 insertions, 58 deletions
diff --git a/libhb/Makefile b/libhb/Makefile index deba9a30b..f5616dc56 100644 --- a/libhb/Makefile +++ b/libhb/Makefile @@ -39,15 +39,19 @@ CONTRIBS = ../contrib/lib/liba52.a ../contrib/lib/libavformat.a \ ../contrib/lib/libvorbisfile.a ../contrib/lib/libogg.a \ ../contrib/lib/libsamplerate.a ../contrib/lib/libx264.a \ ../contrib/lib/libxvidcore.a ../contrib/lib/libmp4v2.a \ - ../contrib/lib/libmkv.a + ../contrib/lib/libmkv.a ../contrib/lib/libswscale.a else CONTRIBS = ../contrib/lib/liba52.a ../contrib/lib/libavformat.a \ ../contrib/lib/libavcodec.a ../contrib/lib/libavutil.a \ ../contrib/lib/libdca.a ../contrib/lib/libdvdread.a \ ../contrib/lib/libdvdcss.a ../contrib/lib/libfaac.a \ - ../contrib/lib/libmp3lame.a ../contrib/lib/libmpeg2.a \ ../contrib/lib/libmpeg2convert.a ../contrib/lib/libvorbis.a \ ../contrib/lib/libvorbisenc.a ../contrib/lib/libvorbisfile.a \ ../contrib/lib/libogg.a ../contrib/lib/libsamplerate.a \ + ../contrib/lib/libmp3lame.a ../contrib/lib/libmpeg2.a \ + ../contrib/lib/libmpeg2convert.a ../contrib/lib/libvorbis.a \ + ../contrib/lib/libvorbisenc.a ../contrib/lib/libvorbisfile.a \ + ../contrib/lib/libogg.a ../contrib/lib/libsamplerate.a \ ../contrib/lib/libx264.a ../contrib/lib/libxvidcore.a \ - ../contrib/lib/libmp4v2.a ../contrib/lib/libmkv.a + ../contrib/lib/libmp4v2.a ../contrib/lib/libmkv.a \ + ../contrib/lib/libswscale.a endif CFLAGS += -I../contrib/include -D__LIBHB__ -DUSE_PTHREAD -DHB_VERSION=\"$(HB_VERSION)\" -DHB_BUILD=$(HB_BUILD) $(SYSDEF) diff --git a/libhb/deinterlace.c b/libhb/deinterlace.c index fd842064f..1da50d097 100644 --- a/libhb/deinterlace.c +++ b/libhb/deinterlace.c @@ -394,8 +394,8 @@ hb_filter_private_t * hb_deinterlace_init( int pix_fmt, /* Allocate mcdeint specific buffers */
if( pv->mcdeint_mode >= 0 )
{
- avcodec_init();
- register_avcodec( &snow_encoder );
+ avcodec_init();
+ avcodec_register_all();
AVCodec * enc = avcodec_find_encoder( CODEC_ID_SNOW );
diff --git a/libhb/hb.c b/libhb/hb.c index 482b4d773..861da0702 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -1,6 +1,7 @@ #include "hb.h" #include "ffmpeg/avcodec.h" +#include "ffmpeg/swscale.h" struct hb_handle_s { @@ -116,9 +117,7 @@ hb_handle_t * hb_init_real( int verbose, int update_check ) /* libavcodec */ avcodec_init(); - register_avcodec( &mpeg4_encoder ); - register_avcodec( &mp2_decoder ); - register_avcodec( &ac3_encoder ); + avcodec_register_all(); av_register_codec_parser( &mpegaudio_parser); /* Start library thread */ @@ -195,9 +194,7 @@ hb_handle_t * hb_init_dl( int verbose, int update_check ) /* libavcodec */ avcodec_init(); - register_avcodec( &mpeg4_encoder ); - register_avcodec( &mp2_decoder ); - register_avcodec( &ac3_encoder ); + avcodec_register_all(); /* Start library thread */ hb_log( "hb_init: starting libhb thread" ); @@ -312,25 +309,15 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, hb_job_t * job = title->job; char filename[1024]; FILE * file; - uint8_t * buf1, * buf2, * buf3, * buf4, * pen; + uint8_t * pen; uint32_t * p32; - AVPicture pic1, pic2, pic3, pic4; - ImgReSampleContext * context; + AVPicture pic_in, pic_preview, pic_deint, pic_crop, pic_scale; + struct SwsContext * context; int i; - buf1 = malloc( title->width * title->height * 3 / 2 ); - buf2 = malloc( title->width * title->height * 3 / 2 ); - buf3 = malloc( title->width * title->height * 3 / 2 ); - buf4 = malloc( title->width * title->height * 4 ); - avpicture_fill( &pic1, buf1, PIX_FMT_YUV420P, - title->width, title->height ); - avpicture_fill( &pic2, buf2, PIX_FMT_YUV420P, - title->width, title->height ); - avpicture_fill( &pic3, buf3, PIX_FMT_YUV420P, - job->width, job->height ); - avpicture_fill( &pic4, buf4, PIX_FMT_RGBA32, - job->width, job->height ); - + // Allocate the AVPicture frames and fill in + avpicture_alloc( &pic_in, PIX_FMT_YUV420P, title->width, title->height ); + memset( filename, 0, 1024 ); hb_get_tempory_filename( h, filename, "%x%d", @@ -343,26 +330,43 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, return; } - fread( buf1, title->width * title->height * 3 / 2, 1, file ); + fread( pic_in.data[0], title->width * title->height * 3 / 2, 1, file ); fclose( file ); - context = img_resample_full_init( - job->width, job->height, title->width, title->height, - job->crop[0], job->crop[1], job->crop[2], job->crop[3], - 0, 0, 0, 0 ); - if( job->deinterlace ) { - avpicture_deinterlace( &pic2, &pic1, PIX_FMT_YUV420P, - title->width, title->height ); - img_resample( context, &pic3, &pic2 ); + // Allocate picture to deinterlace into and deinterlace + avpicture_alloc( &pic_deint, PIX_FMT_YUV420P, title->width, title->height ); + avpicture_deinterlace( &pic_deint, &pic_in, PIX_FMT_YUV420P, title->width, title->height ); + + av_picture_crop( &pic_crop, &pic_deint, PIX_FMT_YUV420P, job->crop[0], job->crop[2] ); } else { - img_resample( context, &pic3, &pic1 ); + av_picture_crop( &pic_crop, &pic_in, PIX_FMT_YUV420P, job->crop[0], job->crop[2] ); } - img_convert( &pic4, PIX_FMT_RGBA32, &pic3, PIX_FMT_YUV420P, - job->width, job->height ); + + // Allocate picture to scale into, get scaling context and scale + avpicture_alloc( &pic_scale, PIX_FMT_YUV420P, job->width, job->height ); + context = sws_getContext(title->width - (job->crop[2] + job->crop[3]), + title->height - (job->crop[0] + job->crop[1]), + PIX_FMT_YUV420P, + job->width, job->height, PIX_FMT_YUV420P, + SWS_LANCZOS, NULL, NULL, NULL); + sws_scale(context, + pic_crop.data, pic_crop.linesize, + 0, title->height - (job->crop[0] + job->crop[1]), + pic_scale.data, pic_scale.linesize); + + // Allocate RGBA32 preview picture and create preview + avpicture_alloc( &pic_preview, PIX_FMT_RGBA32, job->width, job->height ); + context = sws_getContext(job->width, job->height, PIX_FMT_YUV420P, + job->width, job->height, PIX_FMT_RGBA32, + SWS_LANCZOS, NULL, NULL, NULL); + sws_scale(context, + pic_scale.data, pic_scale.linesize, + 0, job->height, + pic_preview.data, pic_preview.linesize); /* Gray background */ p32 = (uint32_t *) buffer; @@ -382,17 +386,17 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, nextLine = pen + 4 * ( title->width + 2 ); memset( pen, 0xFF, 4 ); pen += 4; - memcpy( pen, buf4 + 4 * job->width * i, 4 * job->width ); + memcpy( pen, pic_preview.data[0] + 4 * job->width * i, 4 * job->width ); pen += 4 * job->width; memset( pen, 0xFF, 4 ); pen = nextLine; } memset( pen, 0xFF, 4 * ( job->width + 2 ) ); - free( buf1 ); - free( buf2 ); - free( buf3 ); - free( buf4 ); + avpicture_free( &pic_preview ); + avpicture_free( &pic_scale ); + if( job->deinterlace ) avpicture_free( &pic_deint ); + avpicture_free( &pic_in ); } /** diff --git a/libhb/render.c b/libhb/render.c index 20b581383..a49bdfada 100644 --- a/libhb/render.c +++ b/libhb/render.c @@ -7,13 +7,15 @@ #include "hb.h" #include "ffmpeg/avcodec.h" +#include "ffmpeg/swscale.h" struct hb_work_private_s { hb_job_t * job; - ImgReSampleContext * context; + struct SwsContext * context; AVPicture pic_tmp_in; + AVPicture pic_tmp_crop; AVPicture pic_tmp_out; hb_buffer_t * buf_scale; hb_fifo_t * subtitle_queue; @@ -102,9 +104,6 @@ int renderWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_job_t * job = pv->job; hb_title_t * title = job->title; hb_buffer_t * in = *buf_in, * buf_tmp_in = *buf_in; - - int title_size = 3 * title->width * title->height / 2; - int job_size = 3 * job->width * job->height / 2; if(!in->data) { @@ -124,7 +123,7 @@ int renderWork( hb_work_object_t * w, hb_buffer_t ** buf_in, } /* Setup render buffer */ - hb_buffer_t * buf_render = hb_buffer_init( job_size ); + hb_buffer_t * buf_render = hb_buffer_init( 3 * job->width * job->height / 2 ); /* Apply filters */ if( job->filters ) @@ -194,8 +193,16 @@ int renderWork( hb_work_object_t * w, hb_buffer_t ** buf_in, avpicture_fill( &pv->pic_tmp_out, buf_render->data, PIX_FMT_YUV420P, job->width, job->height ); - - img_resample( pv->context, &pv->pic_tmp_out, &pv->pic_tmp_in ); + + // Crop; this alters the pointer to the data to point to the correct place for cropped frame + av_picture_crop( &pv->pic_tmp_crop, &pv->pic_tmp_in, PIX_FMT_YUV420P, + job->crop[0], job->crop[2] ); + + // Scale pic_crop into pic_render according to the context set up in renderInit + sws_scale(pv->context, + pv->pic_tmp_crop.data, pv->pic_tmp_crop.linesize, + 0, title->height - (job->crop[0] + job->crop[1]), + pv->pic_tmp_out.data, pv->pic_tmp_out.linesize); hb_buffer_copy_settings( buf_render, buf_tmp_in ); @@ -271,17 +278,17 @@ int renderInit( hb_work_object_t * w, hb_job_t * job ) w->private_data = pv; /* Get title and title size */ - hb_title_t * title = job->title; - int title_size = 3 * title->width * title->height / 2; - + hb_title_t * title = job->title; + /* If crop or scale is specified, setup rescale context */ if( job->crop[0] || job->crop[1] || job->crop[2] || job->crop[3] || job->width != title->width || job->height != title->height ) { - pv->context = img_resample_full_init( - job->width, job->height, title->width, title->height, - job->crop[0], job->crop[1], job->crop[2], job->crop[3], - 0, 0, 0, 0 ); + pv->context = sws_getContext(title->width - (job->crop[2] + job->crop[3]), + title->height - (job->crop[0] + job->crop[1]), + PIX_FMT_YUV420P, + job->width, job->height, PIX_FMT_YUV420P, + SWS_LANCZOS, NULL, NULL, NULL); } /* Setup FIFO queue for subtitle cache */ |