OSDN Git Service

Don't discard titles during scan just because of a read failure on one or more of...
[handbrake-jp/handbrake-jp-git.git] / libhb / encavcodec.c
index 45c79fd..85aa608 100644 (file)
@@ -21,7 +21,7 @@ void encavcodecClose( hb_work_object_t * );
 
 hb_work_object_t hb_encavcodec =
 {   
-    WORK_DECSUB,
+    WORK_ENCAVCODEC,
     "MPEG-4 encoder (libavcodec)",
     encavcodecInit,
     encavcodecWork,
@@ -65,16 +65,29 @@ 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->mux & HB_MUX_MP4 )
+    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;
     }
+    if( job->mux & HB_MUX_PSP )
+    {
+        context->flags |= CODEC_FLAG_BITEXACT;
+    }
     if( job->grayscale )
     {
         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" );
@@ -110,11 +123,17 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
     }
     pv->context = context;
 
-    if( ( job->mux & HB_MUX_MP4 ) && job->pass != 1 )
+    if( ( job->mux & ( HB_MUX_MP4 | HB_MUX_PSP ) ) && job->pass != 1 )
     {
+#if 0
         /* Hem hem */
         w->config->mpeg4.length = 15;
         memcpy( w->config->mpeg4.bytes, context->extradata + 15, 15 );
+#else
+        w->config->mpeg4.length = context->extradata_size;
+        memcpy( w->config->mpeg4.bytes, context->extradata,
+                context->extradata_size );
+#endif
     }
     
     return 0;
@@ -132,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;
 }
 
 /***********************************************************************
@@ -153,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;
@@ -167,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 );