transcode: reinit filter-chain when aspect-ratio changes
authorIlkka Ollakka <ileoo@videolan.org>
Sat, 14 Jan 2012 21:20:04 +0000 (23:20 +0200)
committerIlkka Ollakka <ileoo@videolan.org>
Fri, 8 Feb 2013 13:22:30 +0000 (15:22 +0200)
modules/stream_out/transcode/transcode.h
modules/stream_out/transcode/video.c

index 5db1e13..fc8bb41 100644 (file)
@@ -36,6 +36,7 @@ struct sout_stream_sys_t
 
     /* Video */
     vlc_fourcc_t    i_vcodec;   /* codec video (0 if not transcode) */
+    video_format_t  fmt_input_video;
     char            *psz_venc;
     config_chain_t  *p_video_cfg;
     int             i_vbitrate;
index e8ca26d..06dd3e9 100644 (file)
@@ -638,12 +638,41 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_t *id,
                 b_need_duplicate = true;
             }
         }
+        if( unlikely (
+             id->p_encoder->p_module &&
+             !video_format_IsSimilar( &p_sys->fmt_input_video, &id->p_decoder->fmt_out.video )
+            )
+          )
+        {
+            msg_Info( p_stream, "aspect-ratio changed, reiniting. %i -> %i : %i -> %i.",
+                        p_sys->fmt_input_video.i_sar_num, id->p_decoder->fmt_out.video.i_sar_num,
+                        p_sys->fmt_input_video.i_sar_den, id->p_decoder->fmt_out.video.i_sar_den
+                    );
+            /* Close filters */
+            if( id->p_f_chain )
+                filter_chain_Delete( id->p_f_chain );
+            id->p_f_chain = NULL;
+            if( id->p_uf_chain )
+                filter_chain_Delete( id->p_uf_chain );
+            id->p_uf_chain = NULL;
+
+            /* Reinitialize filters */
+            id->p_encoder->fmt_out.video.i_width  = p_sys->i_width & ~1;
+            id->p_encoder->fmt_out.video.i_height = p_sys->i_height & ~1;
+            id->p_encoder->fmt_out.video.i_sar_num = id->p_encoder->fmt_out.video.i_sar_den = 0;
+
+            transcode_video_encoder_init( p_stream, id );
+            transcode_video_filter_init( p_stream, id );
+            memcpy( &p_sys->fmt_input_video, &id->p_decoder->fmt_out.video, sizeof(video_format_t));
+        }
+
 
         if( unlikely( !id->p_encoder->p_module ) )
         {
             transcode_video_encoder_init( p_stream, id );
 
             transcode_video_filter_init( p_stream, id );
+            memcpy( &p_sys->fmt_input_video, &id->p_decoder->fmt_out.video, sizeof(video_format_t));
 
             if( transcode_video_encoder_open( p_stream, id ) != VLC_SUCCESS )
             {