OSDN Git Service

CLI: Missed file from SubRip - a symptom of too many views and patches
[handbrake-jp/handbrake-jp-git.git] / libhb / enctheora.c
index 5941468..29dfed1 100644 (file)
@@ -42,10 +42,10 @@ int enctheoraInit( hb_work_object_t * w, hb_job_t * job )
     ti.offset_x = ti.offset_y = 0;
     ti.fps_numerator = job->vrate;
     ti.fps_denominator = job->vrate_base;
-    if (job->pixel_ratio)
+    if( job->anamorphic.mode )
     {
-        ti.aspect_numerator = job->pixel_aspect_width;
-        ti.aspect_denominator = job->pixel_aspect_height;
+        ti.aspect_numerator = job->anamorphic.par_width;
+        ti.aspect_denominator = job->anamorphic.par_height;
     }
     else
     {
@@ -63,7 +63,7 @@ int enctheoraInit( hb_work_object_t * w, hb_job_t * job )
     ti.keyframe_mindistance = 8;
     ti.noise_sensitivity = 1;
     ti.sharpness = 0;
-    if (job->vquality < 0.0 || job->vquality > 1.0)
+    if (job->vquality < 0.0)
     {
         ti.target_bitrate = job->vbitrate * 1000;
         ti.keyframe_data_target_bitrate = job->vbitrate * 1000 * 1.5;
@@ -72,7 +72,15 @@ int enctheoraInit( hb_work_object_t * w, hb_job_t * job )
     else
     {
         ti.target_bitrate = 0;
-        ti.quality = 63 * job->vquality;
+        
+        if( job->vquality > 0 && job->vquality < 1 )
+        {
+            ti.quality = 63 * job->vquality;            
+        }
+        else
+        {
+            ti.quality = job->vquality;
+        }
     }
 
     theora_encode_init( &pv->theora, &ti );
@@ -122,39 +130,37 @@ int enctheoraWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
     hb_buffer_t * in = *buf_in, * buf;
     yuv_buffer yuv;
     ogg_packet op;
-    static int last_p = 0;
-
-    memset(&op, 0, sizeof(op));
-    memset(&yuv, 0, sizeof(yuv));
 
-    /* If this is the last empty frame, we're done */
-    if(!in->data)
+    if ( in->size <= 0 )
     {
-        if (!last_p)
-        {
-            last_p++;
-            goto finish;
-        }
-       *buf_out        = NULL;
+        // EOF on input - send it downstream & say we're done.
+        // XXX may need to flush packets via a call to
+        //  theora_encode_packetout(&pv->theora, 1, &op);
+        // but we don't have a timestamp to put on those packets so we
+        // drop them for now.
+        *buf_out = in;
+        *buf_in = NULL;
        return HB_WORK_DONE;
     }
 
+    memset(&op, 0, sizeof(op));
+    memset(&yuv, 0, sizeof(yuv));
+
     yuv.y_width = job->width;
     yuv.y_height = job->height;
     yuv.y_stride = job->width;
 
-    yuv.uv_width = job->width / 2;
-    yuv.uv_height = job->height / 2;
-    yuv.uv_stride = job->width / 2;
+    yuv.uv_width = (job->width + 1) / 2;
+    yuv.uv_height = (job->height + 1) / 2;
+    yuv.uv_stride = yuv.uv_width;
 
     yuv.y = in->data;
     yuv.u = in->data + job->width * job->height;
-    yuv.v = in->data + job->width * job->height * 5/4;
+    yuv.v = in->data + ( job->width * job->height ) + ( yuv.uv_width * yuv.uv_height );
 
     theora_encode_YUVin(&pv->theora, &yuv);
 
-finish:
-    theora_encode_packetout(&pv->theora, last_p, &op);
+    theora_encode_packetout(&pv->theora, 0, &op);
 
     buf = hb_buffer_init( op.bytes + sizeof(op) );
     memcpy(buf->data, &op, sizeof(op));