summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbrjake <[email protected]>2007-08-01 17:13:36 +0000
committerjbrjake <[email protected]>2007-08-01 17:13:36 +0000
commit8cb0b130a99d34794a9223553478ca23830f9f2c (patch)
treee7366073daaff12f0fb74c38493bb04b41034371
parent6bf190d7481c23c148c5fa737a6174f62a4fcf3c (diff)
Implements libswscale in HandBrake, giving it Lanczos scaling! This major enhancement comes to us courtesy of superdump, who deserves much praise and glory. To make this work, ffmpeg's been updated to a recent revision.
Darwin contrib binary pack ++ to 0016. Includes fresh ffmpeg and libswscale as well as the recently-patched libmp4v2. I've also added the configure option --disable-sdl to libmpeg2 in the contrib/Jamfile, because without it jam always fails for me and I'm sick of adding it in every time. Hopefully this doesn't break anything for anyone, but if it does it's just a one-word change. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@778 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--Jamfile2
-rw-r--r--MacOsXContribBinariesVersion.txt2
-rw-r--r--contrib/Jamfile15
-rw-r--r--contrib/patch-ffmpeg.patch170
-rw-r--r--contrib/version_ffmpeg.txt2
-rw-r--r--libhb/Makefile10
-rw-r--r--libhb/deinterlace.c4
-rw-r--r--libhb/hb.c82
-rw-r--r--libhb/render.c35
-rw-r--r--macosx/HandBrake.xcodeproj/project.pbxproj16
10 files changed, 187 insertions, 151 deletions
diff --git a/Jamfile b/Jamfile
index a84abd2e4..656df3853 100644
--- a/Jamfile
+++ b/Jamfile
@@ -16,7 +16,7 @@ HANDBRAKE_LIBS = libhb.a
contrib/lib/libvorbis.a contrib/lib/libvorbisenc.a
contrib/lib/libogg.a contrib/lib/libsamplerate.a
contrib/lib/libx264.a contrib/lib/libxvidcore.a
- contrib/lib/libmkv.a ;
+ contrib/lib/libmkv.a contrib/lib/libswscale.a ;
if $(OS) = UNKNOWN
{
diff --git a/MacOsXContribBinariesVersion.txt b/MacOsXContribBinariesVersion.txt
index cd5c28d7e..000f20c23 100644
--- a/MacOsXContribBinariesVersion.txt
+++ b/MacOsXContribBinariesVersion.txt
@@ -1 +1 @@
-0015
+0016
diff --git a/contrib/Jamfile b/contrib/Jamfile
index 5b6c08ee5..d99672666 100644
--- a/contrib/Jamfile
+++ b/contrib/Jamfile
@@ -48,14 +48,8 @@ LibA52 $(SUBDIR)/lib/liba52.a : $(SUBDIR)/a52dec.tar.gz ;
# libavcodec
rule LibAvCodec
{
- FFMPEG_PATCH = "patch -p1 < ../patch-ffmpeg.patch" ;
- if $(OS) = MACOSX && $(OSPLAT) = X86
- {
- FFMPEG_OPTIONS = --enable-memalign-hack ;
- # This patch simply don't apply correctly so don't try to do it
- # FFMPEG_PATCH += " && patch -p1 < ../patch-ffmpeg-macintel.patch" ;
- }
- else if $(OS) = CYGWIN
+ FFMPEG_PATCH = "patch -p0 < ../patch-ffmpeg.patch" ;
+ if $(OS) = CYGWIN
{
FFMPEG_PATCH += " && patch -p1 < ../patch-ffmpeg-cygwin.patch " ;
}
@@ -67,7 +61,7 @@ actions LibAvCodec
cd `dirname $(>)` && CONTRIB=`pwd` &&
rm -rf ffmpeg && tar xzf ffmpeg.tar.gz &&
cd ffmpeg && $(FFMPEG_PATCH) &&
- ./configure --prefix=$CONTRIB $(FFMPEG_OPTIONS) --enable-gpl --disable-audio-beos --enable-shared --enable-static&&
+ ./configure --prefix=$CONTRIB $(FFMPEG_OPTIONS) --enable-gpl --enable-swscaler --disable-decoders --enable-decoder=mp2 --disable-encoders --enable-encoder=mpeg4 --enable-encoder=mp2 --enable-encoder=ac3 --enable-encoder=snow --disable-audio-beos --enable-shared --enable-static &&
make && make install &&
strip -S $CONTRIB/lib/libavcodec.a
}
@@ -85,6 +79,7 @@ actions LibAvUtil
}
LibAvUtil $(SUBDIR)/lib/libavutil.a : $(SUBDIR)/lib/libavcodec.a ;
LibAvUtil $(SUBDIR)/lib/libavformat.a : $(SUBDIR)/lib/libavcodec.a ;
+LibAvUtil $(SUBDIR)/lib/libswscale.a : $(SUBDIR)/lib/libavcodec.a ;
# CSS doesn't work on Cygwin/Windows as of now, so don't use it.
if $(OS) != CYGWIN
@@ -243,7 +238,7 @@ actions LibMpeg2
{
cd `dirname $(>)` && CONTRIB=`pwd` &&
rm -rf mpeg2dec && tar xzf mpeg2dec.tar.gz && cd mpeg2dec &&
- ./configure --prefix=$CONTRIB --disable-shared &&
+ ./configure --prefix=$CONTRIB --disable-shared --disable-sdl &&
make && make install &&
strip -S $CONTRIB/lib/libmpeg2.a
}
diff --git a/contrib/patch-ffmpeg.patch b/contrib/patch-ffmpeg.patch
index cc70c9a75..c8b9f5288 100644
--- a/contrib/patch-ffmpeg.patch
+++ b/contrib/patch-ffmpeg.patch
@@ -1,53 +1,50 @@
-diff -Naur t/ffmpeg/configure ffmpeg/configure
---- t/ffmpeg/configure 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/configure 2007-01-13 20:41:28.000000000 +0100
-@@ -674,7 +674,7 @@
- 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
- mmx="no"
- ;;
--*20010315*) echo "BeBits gcc"
-+*20010315*|2.95.3*) echo "BeBits gcc"
- add_cflags "-fno-expensive-optimizations"
- ;;
- esac
-diff -Naur t/ffmpeg/libavformat/Makefile ffmpeg/libavformat/Makefile
---- t/ffmpeg/libavformat/Makefile 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/libavformat/Makefile 2007-01-13 20:41:28.000000000 +0100
-@@ -58,6 +58,7 @@
- OBJS-$(CONFIG_TGP_MUXER) += movenc.o riff.o isom.o
- OBJS-$(CONFIG_MP4_MUXER) += movenc.o riff.o isom.o
- OBJS-$(CONFIG_PSP_MUXER) += movenc.o riff.o isom.o
-+OBJS-$(CONFIG_IPOD_MUXER) += movenc.o riff.o isom.o
- OBJS-$(CONFIG_TG2_MUXER) += movenc.o riff.o isom.o
- OBJS-$(CONFIG_MP3_DEMUXER) += mp3.o
- OBJS-$(CONFIG_MP2_MUXER) += mp3.o
-diff -Naur t/ffmpeg/libavformat/allformats.c ffmpeg/libavformat/allformats.c
---- t/ffmpeg/libavformat/allformats.c 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/libavformat/allformats.c 2007-01-13 20:41:28.000000000 +0100
-@@ -91,6 +91,9 @@
- REGISTER_MUXDEMUX(IMAGE2PIPE, image2pipe);
- REGISTER_DEMUXER (INGENIENT, ingenient);
- REGISTER_DEMUXER (IPMOVIE, ipmovie);
-+#ifdef CONFIG_IPOD_MUXER
-+ REGISTER_MUXER (IPOD, ipod);
+Index: configure
+===================================================================
+--- configure (revision 9814)
++++ configure (working copy)
+@@ -1095,7 +1095,7 @@
+ 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
+ mmx="no"
+ ;;
+- *20010315*) echo "BeBits gcc"
++ *20010315*|2.95.3*) echo "BeBits gcc"
+ add_cflags "-fno-expensive-optimizations"
+ ;;
+ esac
+Index: libavformat/Makefile
+===================================================================
+--- libavformat/Makefile (revision 9814)
++++ libavformat/Makefile (working copy)
+@@ -69,6 +69,7 @@
+ OBJS-$(CONFIG_IMAGE2PIPE_MUXER) += img2.o
+ OBJS-$(CONFIG_INGENIENT_DEMUXER) += raw.o
+ OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o
++OBJS-$(CONFIG_IPOD_MUXER) += movenc.o riff.o isom.o
+ OBJS-$(CONFIG_M4V_DEMUXER) += raw.o
+ OBJS-$(CONFIG_M4V_MUXER) += raw.o
+ OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o riff.o
+Index: libavformat/tcp.c
+===================================================================
+--- libavformat/tcp.c (revision 9814)
++++ libavformat/tcp.c (working copy)
+@@ -88,11 +88,13 @@
+ break;
+ }
+
++#ifndef __BEOS__
+ /* test error */
+ optlen = sizeof(ret);
+ getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
+ if (ret != 0)
+ goto fail;
+#endif
- REGISTER_MUXDEMUX(M4V, m4v);
- REGISTER_DEMUXER (MATROSKA, matroska);
- REGISTER_MUXDEMUX(MJPEG, mjpeg);
-diff -Naur t/ffmpeg/libavformat/allformats.h ffmpeg/libavformat/allformats.h
---- t/ffmpeg/libavformat/allformats.h 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/libavformat/allformats.h 2007-01-13 20:41:28.000000000 +0100
-@@ -77,6 +77,7 @@
- extern AVOutputFormat mov_muxer;
- extern AVOutputFormat tgp_muxer;
- extern AVOutputFormat mp4_muxer;
-+extern AVOutputFormat ipod_muxer;
- extern AVOutputFormat psp_muxer;
- extern AVOutputFormat tg2_muxer;
- extern AVInputFormat mp3_demuxer;
-diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
---- t/ffmpeg/libavformat/movenc.c 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/libavformat/movenc.c 2007-01-13 20:41:28.000000000 +0100
+ }
+ s->fd = fd;
+ return 0;
+Index: libavformat/movenc.c
+===================================================================
+--- libavformat/movenc.c (revision 9814)
++++ libavformat/movenc.c (working copy)
@@ -36,6 +36,7 @@
#define MODE_PSP 3 // example working PSP command line:
// ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
@@ -64,7 +61,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
long sampleSize;
int hasKeyframes;
int hasBframes;
-@@ -598,6 +600,18 @@
+@@ -572,6 +574,18 @@
return tag;
}
@@ -83,7 +80,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
{
offset_t pos = url_ftell(pb);
-@@ -647,8 +661,21 @@
+@@ -621,9 +635,22 @@
mov_write_d263_tag(pb);
else if(track->enc->codec_id == CODEC_ID_SVQ3)
mov_write_svq3_tag(pb);
@@ -102,12 +99,13 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
+ put_be32(pb, 0x0000039C);
+ }
+ }
-+
-+ mov_write_colr_tag(pb);
++ mov_write_colr_tag(pb);
++
return updateSize (pb, pos);
}
-@@ -700,46 +727,18 @@
+
+@@ -674,46 +701,18 @@
return atom_size;
}
@@ -115,7 +113,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
/* Time to sample atom */
static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
{
-- Time2Sample *stts_entries;
+- MOV_stts_t *stts_entries;
- uint32_t entries = -1;
- uint32_t atom_size;
- int i;
@@ -161,7 +159,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
}
static int mov_write_dref_tag(ByteIOContext *pb)
-@@ -929,6 +928,10 @@
+@@ -911,6 +910,10 @@
/* Track width and height, for visual only */
if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
@@ -172,7 +170,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
if( !sample_aspect_ratio ) sample_aspect_ratio = 1;
put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
put_be32(pb, track->enc->height*0x10000);
-@@ -1340,6 +1343,8 @@
+@@ -1322,6 +1325,8 @@
for (i=0; i<mov->nb_streams; i++) {
if(mov->tracks[i].entry <= 0) continue;
@@ -181,7 +179,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
mov->tracks[i].time = mov->time;
mov->tracks[i].trackID = i+1;
}
-@@ -1387,6 +1392,8 @@
+@@ -1369,6 +1374,8 @@
put_tag(pb, "MSNV");
else if ( mov->mode == MODE_MP4 )
put_tag(pb, "isom");
@@ -190,7 +188,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
else
put_tag(pb, "qt ");
-@@ -1398,6 +1405,8 @@
+@@ -1380,6 +1387,8 @@
put_tag(pb, "3g2a");
else if ( mov->mode == MODE_PSP )
put_tag(pb, "MSNV");
@@ -199,7 +197,7 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
else if ( mov->mode == MODE_MP4 )
put_tag(pb, "mp41");
else
-@@ -1479,7 +1488,8 @@
+@@ -1466,7 +1475,8 @@
else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3G2;
else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
@@ -209,20 +207,23 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
mov_write_ftyp_tag(pb,s);
if ( mov->mode == MODE_PSP ) {
if ( s->nb_streams != 2 ) {
-@@ -1500,10 +1510,12 @@
+@@ -1487,6 +1497,7 @@
if(st->codec->codec_type == CODEC_TYPE_VIDEO){
track->tag = mov_find_video_codec_tag(s, track);
track->timescale = st->codec->time_base.den;
+ track->sampleDuration = st->codec->time_base.num;
av_set_pts_info(st, 64, 1, st->codec->time_base.den);
+ if (track->timescale > 100000)
+ av_log(NULL, AV_LOG_WARNING,
+@@ -1496,6 +1507,7 @@
}else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
track->tag = mov_find_audio_codec_tag(s, track);
track->timescale = st->codec->sample_rate;
+ track->sampleDuration = st->codec->frame_size;
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
- switch(track->enc->codec_id){
- case CODEC_ID_MP3:
-@@ -1689,6 +1701,21 @@
+ if(!st->codec->frame_size){
+ av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
+@@ -1675,6 +1687,21 @@
.flags = AVFMT_GLOBALHEADER,
};
#endif
@@ -244,20 +245,29 @@ diff -Naur t/ffmpeg/libavformat/movenc.c ffmpeg/libavformat/movenc.c
#ifdef CONFIG_PSP_MUXER
AVOutputFormat psp_muxer = {
"psp",
-diff -Naur t/ffmpeg/libavformat/tcp.c ffmpeg/libavformat/tcp.c
---- t/ffmpeg/libavformat/tcp.c 2007-01-13 12:58:43.000000000 +0100
-+++ ffmpeg/libavformat/tcp.c 2007-01-13 20:41:28.000000000 +0100
-@@ -114,11 +114,13 @@
- break;
- }
-
-+#ifndef __BEOS__
- /* test error */
- optlen = sizeof(ret);
- getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
- if (ret != 0)
- goto fail;
+Index: libavformat/allformats.c
+===================================================================
+--- libavformat/allformats.c (revision 9814)
++++ libavformat/allformats.c (working copy)
+@@ -89,6 +89,9 @@
+ REGISTER_MUXDEMUX(IMAGE2PIPE, image2pipe);
+ REGISTER_DEMUXER (INGENIENT, ingenient);
+ REGISTER_DEMUXER (IPMOVIE, ipmovie);
++#ifdef CONFIG_IPOD_MUXER
++ REGISTER_MUXER (IPOD, ipod);
+#endif
- }
- s->fd = fd;
- return 0;
+ if (!ENABLE_NUT_DEMUXER) REGISTER_DEMUXER (LIBNUT, libnut);
+ REGISTER_MUXER (LIBNUT, libnut);
+ REGISTER_MUXDEMUX(M4V, m4v);
+Index: libavformat/allformats.h
+===================================================================
+--- libavformat/allformats.h (revision 9814)
++++ libavformat/allformats.h (working copy)
+@@ -142,6 +142,7 @@
+ extern AVOutputFormat image2pipe_muxer;
+ extern AVOutputFormat image_muxer;
+ extern AVOutputFormat imagepipe_muxer;
++extern AVOutputFormat ipod_muxer;
+ extern AVOutputFormat libnut_muxer;
+ extern AVOutputFormat m4v_muxer;
+ extern AVOutputFormat mjpeg_muxer;
diff --git a/contrib/version_ffmpeg.txt b/contrib/version_ffmpeg.txt
index 2d6acd66c..15e9b5e0d 100644
--- a/contrib/version_ffmpeg.txt
+++ b/contrib/version_ffmpeg.txt
@@ -1 +1 @@
-http://download.m0k.org/handbrake/contrib/ffmpeg-7444.tar.gz
+http://download.m0k.org/handbrake/contrib/ffmpeg-9816.tar.gz
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 */
diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj
index f84b24880..c000e20d4 100644
--- a/macosx/HandBrake.xcodeproj/project.pbxproj
+++ b/macosx/HandBrake.xcodeproj/project.pbxproj
@@ -892,6 +892,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
"-ldl",
"-flat_namespace",
"-read_only_relocs",
@@ -950,6 +951,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
"-ldl",
"-flat_namespace",
"-read_only_relocs",
@@ -1006,6 +1008,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
"-ldl",
"-flat_namespace",
"-read_only_relocs",
@@ -1062,6 +1065,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
"-ldl",
"-flat_namespace",
"-read_only_relocs",
@@ -1142,6 +1146,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PRODUCT_NAME = HandBrake;
SECTORDER_FLAGS = "";
@@ -1191,6 +1196,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = "Instant HandBrake";
@@ -1232,6 +1238,7 @@
"-lz",
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = HandBrakeCLI;
@@ -1374,6 +1381,7 @@
"-lz",
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = HandBrakeCLI;
@@ -1416,6 +1424,7 @@
"-lz",
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = HandBrakeCLI;
@@ -1456,6 +1465,7 @@
"-lz",
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = HandBrakeCLI;
@@ -1503,6 +1513,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = "Instant HandBrake";
@@ -1550,6 +1561,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = "Instant HandBrake";
@@ -1595,6 +1607,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PREBINDING = NO;
PRODUCT_NAME = "Instant HandBrake";
@@ -1647,6 +1660,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PRODUCT_NAME = HandBrake;
SECTORDER_FLAGS = "";
@@ -1701,6 +1715,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PRODUCT_NAME = HandBrake;
SECTORDER_FLAGS = "";
@@ -1753,6 +1768,7 @@
../contrib/lib/libxvidcore.a,
../contrib/lib/libdca.a,
../contrib/lib/libmkv.a,
+ ../contrib/lib/libswscale.a,
);
PRODUCT_NAME = HandBrake;
SECTORDER_FLAGS = "";