OSDN Git Service

MacGUI: Implements a part of the NSTableView delegate in ChapterTitles so that pressi...
[handbrake-jp/handbrake-jp-git.git] / libhb / encavcodec.c
index f046069..5e55b00 100644 (file)
@@ -1,12 +1,12 @@
 /* $Id: encavcodec.c,v 1.23 2005/10/13 23:47:06 titer Exp $
 
    This file is part of the HandBrake source code.
-   Homepage: <http://handbrake.m0k.org/>.
+   Homepage: <http://handbrake.fr/>.
    It may be used under the terms of the GNU General Public License. */
 
 #include "hb.h"
 
-#include "ffmpeg/avcodec.h"
+#include "libavcodec/avcodec.h"
 
 struct hb_work_private_s
 {
@@ -20,19 +20,19 @@ int  encavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
 void encavcodecClose( hb_work_object_t * );
 
 hb_work_object_t hb_encavcodec =
-{   
+{
     WORK_ENCAVCODEC,
     "MPEG-4 encoder (libavcodec)",
     encavcodecInit,
     encavcodecWork,
     encavcodecClose
-}; 
+};
 
 int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
 {
     AVCodec * codec;
     AVCodecContext * context;
-    
+
     hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
     w->private_data = pv;
 
@@ -65,6 +65,15 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
     context->gop_size  = 10 * job->vrate / job->vrate_base;
     context->pix_fmt   = PIX_FMT_YUV420P;
 
+    if( job->pixel_ratio )
+    {
+        context->sample_aspect_ratio.num = job->pixel_aspect_width;
+        context->sample_aspect_ratio.den = job->pixel_aspect_height;
+
+        hb_log( "encavcodec: encoding with stored aspect %d/%d",
+                job->pixel_aspect_width, job->pixel_aspect_height );
+    }
+
     if( job->mux & ( HB_MUX_MP4 | HB_MUX_PSP ) )
     {
         context->flags |= CODEC_FLAG_GLOBAL_HEADER;
@@ -78,7 +87,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
         context->flags |= CODEC_FLAG_GRAY;
     }
 
-    if( job->pass )
+    if( job->pass != 0 && job->pass != -1 )
     {
         char filename[1024]; memset( filename, 0, 1024 );
         hb_get_tempory_filename( job->h, filename, "ffmpeg.log" );
@@ -126,7 +135,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
                 context->extradata_size );
 #endif
     }
-    
+
     return 0;
 }
 
@@ -142,12 +151,15 @@ void encavcodecClose( hb_work_object_t * w )
     if( pv->context )
     {
         hb_log( "encavcodec: closing libavcodec" );
+        avcodec_flush_buffers( pv->context );
         avcodec_close( pv->context );
     }
     if( pv->file )
     {
         fclose( pv->file );
     }
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
@@ -163,6 +175,12 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
     AVFrame  * frame;
     hb_buffer_t * in = *buf_in, * buf;
 
+    if(!in->data)
+    {
+       *buf_out        = NULL;
+       return HB_WORK_DONE;
+    }
+
     frame              = avcodec_alloc_frame();
     frame->data[0]     = in->data;
     frame->data[1]     = frame->data[0] + job->width * job->height;
@@ -177,7 +195,7 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
                                       frame );
     buf->start = in->start;
     buf->stop  = in->stop;
-    buf->key   = pv->context->coded_frame->key_frame;
+    buf->frametype   = pv->context->coded_frame->key_frame ? HB_FRAME_KEY : HB_FRAME_REF;
 
     av_free( frame );