]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/encoder.c
* modules/codec/ffmpeg/*, modules/stream_out/switcher.c: fix compilation with new...
[vlc] / modules / codec / ffmpeg / encoder.c
index d7a7647b218965450680ca78507aa4dcf9700662..59c64a70f2160d37ee4d5435c58cee1755bb2533 100644 (file)
@@ -43,6 +43,9 @@
 #if LIBAVCODEC_BUILD < 4704
 #   define AV_NOPTS_VALUE 0
 #endif
+#if LIBAVCODEC_BUILD < 4684
+#    define FF_QP2LAMBDA 118
+#endif
 
 #include "ffmpeg.h"
 
@@ -144,7 +147,7 @@ struct encoder_sys_t
 };
 
 static const char *ppsz_enc_options[] = {
-    "keyint", "bframes", "vt", "qmin", "qmax", "hq", "strict_rc",
+    "keyint", "bframes", "vt", "qmin", "qmax", "hq", "strict-rc",
     "rc-buffer-size", "rc-buffer-aggressivity", "pre-me", "hurry-up",
     "interlace", "i-quant-factor", "noise-reduction", "mpeg4-matrix",
     "trellis", "qscale", "strict", NULL
@@ -153,8 +156,8 @@ static const char *ppsz_enc_options[] = {
 /*****************************************************************************
  * OpenEncoder: probe the encoder
  *****************************************************************************/
-extern int16_t ff_mpeg4_default_intra_matrix[];
-extern int16_t ff_mpeg4_default_non_intra_matrix[];
+extern int16_t IMPORT_SYMBOL ff_mpeg4_default_intra_matrix[];
+extern int16_t IMPORT_SYMBOL ff_mpeg4_default_non_intra_matrix[];
 
 int E_(OpenEncoder)( vlc_object_t *p_this )
 {
@@ -325,8 +328,13 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
         p_context->width = p_enc->fmt_in.video.i_width;
         p_context->height = p_enc->fmt_in.video.i_height;
 
+#if LIBAVCODEC_BUILD >= 4754
+        p_context->time_base.num = p_enc->fmt_in.video.i_frame_rate_base;
+        p_context->time_base.den = p_enc->fmt_in.video.i_frame_rate;
+#else
         p_context->frame_rate = p_enc->fmt_in.video.i_frame_rate;
         p_context->frame_rate_base= p_enc->fmt_in.video.i_frame_rate_base;
+#endif
 
         /* Defaults from ffmpeg.c */
         p_context->qblur = 0.5;
@@ -348,9 +356,8 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
                    VOUT_ASPECT_FACTOR, 1 << 30 /* something big */ );
         av_reduce( &p_context->sample_aspect_ratio.num,
                    &p_context->sample_aspect_ratio.den,
-                   i_aspect_num *
-                   (int64_t)p_context->height / p_context->width,
-                   i_aspect_den, 1 << 30 /* something big */ );
+                   i_aspect_num * (int64_t)p_context->height,
+                   i_aspect_den * (int64_t)p_context->width, 1 << 30 );
 #else
         p_context->aspect_ratio = ((float)p_enc->fmt_in.video.i_aspect) /
             VOUT_ASPECT_FACTOR;
@@ -359,6 +366,21 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
         p_sys->p_buffer_out = malloc( AVCODEC_MAX_VIDEO_FRAME_SIZE );
 
         p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0');
+        p_context->pix_fmt = E_(GetFfmpegChroma)( p_enc->fmt_in.i_codec );
+#if LIBAVCODEC_BUILD >= 4714
+        if( p_codec->pix_fmts )
+        {
+            const enum PixelFormat *p = p_codec->pix_fmts;
+            for( ; *p != -1; p++ )
+            {
+                if( *p == p_context->pix_fmt ) break;
+            }
+            if( *p == -1 ) p_context->pix_fmt = p_codec->pix_fmts[0];
+            p_enc->fmt_in.i_codec = E_(GetVlcChroma)( p_context->pix_fmt );
+        }
+#else
+        p_enc->fmt_in.i_codec = E_(GetVlcChroma)( p_context->pix_fmt );
+#endif
 
         if ( p_sys->b_strict_rc )
         {
@@ -423,6 +445,10 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
     }
     else if( p_enc->fmt_in.i_cat == AUDIO_ES )
     {
+        /* work around bug in libmp3lame encoding */
+        if( i_codec_id == CODEC_ID_MP3 && p_enc->fmt_in.audio.i_channels > 2 )
+            p_enc->fmt_in.audio.i_channels = 2;
+
         p_enc->fmt_in.i_codec  = AOUT_FMT_S16_NE;
         p_context->sample_rate = p_enc->fmt_in.audio.i_rate;
         p_context->channels    = p_enc->fmt_in.audio.i_channels;
@@ -606,11 +632,11 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
     /* Let ffmpeg select the frame type */
     frame.pict_type = 0;
 
-    frame.repeat_pict = p_pict->i_nb_fields;
+    frame.repeat_pict = 2 - p_pict->i_nb_fields;
 
 #if LIBAVCODEC_BUILD >= 4685
     frame.interlaced_frame = !p_pict->b_progressive;
-    frame.top_field_first = p_pict->b_top_field_first;
+    frame.top_field_first = !!p_pict->b_top_field_first;
 #endif
 
 #if LIBAVCODEC_BUILD < 4702