]> git.sesse.net Git - vlc/blobdiff - modules/codec/theora.c
* equalizer : [0] isn't cool, use a define.
[vlc] / modules / codec / theora.c
index eaceea47b1ca757c61b3d4aa5dd1821719a5b89c..02af93a0272d1f1c5e2f51e81f8c92a757a6fd3b 100644 (file)
@@ -26,6 +26,8 @@
  *****************************************************************************/
 #include <vlc/vlc.h>
 #include <vlc/decoder.h>
+#include <vlc/input.h>
+#include <vlc/sout.h>
 
 #include <ogg/ogg.h>
 
@@ -80,6 +82,11 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+#define ENC_QUALITY_TEXT N_("Encoding quality")
+#define ENC_QUALITY_LONGTEXT N_( \
+  "Allows you to specify a quality between 1 (low) and 10 (high), instead " \
+  "of specifying a particular bitrate. This will produce a VBR stream." )
+
 vlc_module_begin();
     set_description( _("Theora video decoder") );
     set_capability( "decoder", 100 );
@@ -97,8 +104,16 @@ vlc_module_begin();
     set_capability( "encoder", 100 );
     set_callbacks( OpenEncoder, CloseEncoder );
     add_shortcut( "theora" );
+
+#   define ENC_CFG_PREFIX "sout-theora-"
+    add_integer( ENC_CFG_PREFIX "quality", 2, NULL, ENC_QUALITY_TEXT,
+                 ENC_QUALITY_LONGTEXT, VLC_FALSE );
 vlc_module_end();
 
+static const char *ppsz_enc_options[] = {
+    "quality", NULL
+};
+
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
  *****************************************************************************/
@@ -198,12 +213,17 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         p_dec->fmt_out.video.i_width = p_sys->ti.width;
         p_dec->fmt_out.video.i_height = p_sys->ti.height;
 
-        if( p_sys->ti.aspect_denominator )
+        if( p_sys->ti.aspect_denominator && p_sys->ti.aspect_numerator )
+        {
             p_dec->fmt_out.video.i_aspect = ((int64_t)VOUT_ASPECT_FACTOR) *
-                p_sys->ti.aspect_numerator / p_sys->ti.aspect_denominator;
+                ( p_sys->ti.aspect_numerator * p_sys->ti.width ) /
+                ( p_sys->ti.aspect_denominator * p_sys->ti.height );
+        }
         else
+        {
             p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR *
                 p_sys->ti.frame_width / p_sys->ti.frame_height;
+        }
 
         msg_Dbg( p_dec, "%dx%d %.02f fps video, frame content "
                  "is %dx%d with offset (%d,%d).",
@@ -440,6 +460,8 @@ static int OpenEncoder( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t *)p_this;
     encoder_sys_t *p_sys = p_enc->p_sys;
+    vlc_value_t val;
+    int i_quality;
 
     if( p_enc->fmt_out.i_codec != VLC_FOURCC('t','h','e','o') &&
         !p_enc->b_force )
@@ -469,11 +491,12 @@ static int OpenEncoder( vlc_object_t *p_this )
     p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
     p_enc->fmt_out.i_codec = VLC_FOURCC('t','h','e','o');
 
-#define frame_x_offset 0
-#define frame_y_offset 0
-#define video_hzn 25
-#define video_hzd 1
-#define video_q 5
+    sout_CfgParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
+
+    var_Get( p_enc, ENC_CFG_PREFIX "quality", &val );
+    i_quality = val.i_int;
+    if( i_quality > 10 ) i_quality = 10;
+    if( i_quality < 0 ) i_quality = 0;
 
     theora_info_init( &p_sys->ti );
 
@@ -481,14 +504,25 @@ static int OpenEncoder( vlc_object_t *p_this )
     p_sys->ti.height = p_enc->fmt_in.video.i_height;
     p_sys->ti.frame_width = p_enc->fmt_in.video.i_width;
     p_sys->ti.frame_height = p_enc->fmt_in.video.i_height;
-    p_sys->ti.offset_x = frame_x_offset;
-    p_sys->ti.offset_y = frame_y_offset;
-    p_sys->ti.fps_numerator = video_hzn;
-    p_sys->ti.fps_denominator = video_hzd;
+    p_sys->ti.offset_x = 0 /*frame_x_offset*/;
+    p_sys->ti.offset_y = 0/*frame_y_offset*/;
+
+    if( !p_enc->fmt_in.video.i_frame_rate ||
+        !p_enc->fmt_in.video.i_frame_rate_base )
+    {
+        p_sys->ti.fps_numerator = 25;
+        p_sys->ti.fps_denominator = 1;
+    }
+    else
+    {
+        p_sys->ti.fps_numerator = p_enc->fmt_in.video.i_frame_rate;
+        p_sys->ti.fps_denominator = p_enc->fmt_in.video.i_frame_rate_base;
+    }
 
     if( p_enc->fmt_in.video.i_aspect )
     {
-        p_sys->ti.aspect_numerator = p_enc->fmt_in.video.i_aspect;
+        p_sys->ti.aspect_numerator =
+            p_enc->fmt_in.video.i_aspect * p_sys->ti.height / p_sys->ti.width;
         p_sys->ti.aspect_denominator = VOUT_ASPECT_FACTOR;
     }
     else
@@ -498,7 +532,7 @@ static int OpenEncoder( vlc_object_t *p_this )
     }
 
     p_sys->ti.target_bitrate = p_enc->fmt_out.i_bitrate;
-    p_sys->ti.quality = video_q;
+    p_sys->ti.quality = ((float)i_quality) * 6.3;
 
     p_sys->ti.dropframes_p = 0;
     p_sys->ti.quick_p = 1;
@@ -602,7 +636,7 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
     /* Ogg packet to block */
     p_block = block_New( p_enc, oggpacket.bytes );
     memcpy( p_block->p_buffer, oggpacket.packet, oggpacket.bytes );
-    p_block->i_dts = p_block->i_pts = p_pict->date;;
+    p_block->i_dts = p_block->i_pts = p_pict->date;
 
     return p_block;
 }