[vlc-commits] transcode: update the encoder input format after we know the last filter output

Steve Lhomme git at videolan.org
Mon Jan 18 08:08:33 UTC 2021


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Jan 13 14:45:23 2021 +0100| [9de28aa252d920dcd889215b398f4879ef1575f8] | committer: Steve Lhomme

transcode: update the encoder input format after we know the last filter output

This is done before the actual encoder that will be used is created.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9de28aa252d920dcd889215b398f4879ef1575f8
---

 modules/stream_out/transcode/encoder/encoder.c | 11 ++++++++++-
 modules/stream_out/transcode/encoder/encoder.h |  6 +++++-
 modules/stream_out/transcode/encoder/video.c   | 15 +++++++++++++++
 modules/stream_out/transcode/video.c           |  4 ++--
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/modules/stream_out/transcode/encoder/encoder.c b/modules/stream_out/transcode/encoder/encoder.c
index 2c89332663..6958a8dc72 100644
--- a/modules/stream_out/transcode/encoder/encoder.c
+++ b/modules/stream_out/transcode/encoder/encoder.c
@@ -124,10 +124,19 @@ const es_format_t *transcode_encoder_format_out( const transcode_encoder_t *p_en
     return &p_enc->p_encoder->fmt_out;
 }
 
-void transcode_encoder_update_format_in( transcode_encoder_t *p_enc, const es_format_t *fmt )
+void transcode_encoder_update_format_in( transcode_encoder_t *p_enc, const es_format_t *fmt,
+                                         const transcode_encoder_config_t *p_cfg )
 {
     es_format_Clean( &p_enc->p_encoder->fmt_in );
     es_format_Copy( &p_enc->p_encoder->fmt_in, fmt );
+    switch (fmt->i_cat)
+    {
+        case VIDEO_ES:
+            transcode_encoder_video_set_src(p_enc->p_encoder, &fmt->video, p_cfg);
+            break;
+        default:
+            break;
+    }
 }
 
 void transcode_encoder_update_format_out( transcode_encoder_t *p_enc, const es_format_t *fmt )
diff --git a/modules/stream_out/transcode/encoder/encoder.h b/modules/stream_out/transcode/encoder/encoder.h
index 30a8354770..22b1d7d1b2 100644
--- a/modules/stream_out/transcode/encoder/encoder.h
+++ b/modules/stream_out/transcode/encoder/encoder.h
@@ -65,7 +65,8 @@ void transcode_encoder_config_clean( transcode_encoder_config_t * );
 
 const es_format_t *transcode_encoder_format_in( const transcode_encoder_t * );
 const es_format_t *transcode_encoder_format_out( const transcode_encoder_t * );
-void transcode_encoder_update_format_in( transcode_encoder_t *, const es_format_t * );
+void transcode_encoder_update_format_in( transcode_encoder_t *, const es_format_t *,
+                                         const transcode_encoder_config_t * );
 void transcode_encoder_update_format_out( transcode_encoder_t *, const es_format_t * );
 
 block_t * transcode_encoder_encode( transcode_encoder_t *, void * );
@@ -91,6 +92,9 @@ void transcode_encoder_video_configure( vlc_object_t *p_obj,
                                         vlc_video_context *vctx_in,
                                         transcode_encoder_t *p_enc );
 
+void transcode_encoder_video_set_src( encoder_t *, const video_format_t *,
+                                      const transcode_encoder_config_t * );
+
 void transcode_video_framerate_apply( const video_format_t *p_src,
                                             video_format_t *p_dst );
 void transcode_video_sar_apply( const video_format_t *p_src,
diff --git a/modules/stream_out/transcode/encoder/video.c b/modules/stream_out/transcode/encoder/video.c
index 2ba109a1af..683d9031af 100644
--- a/modules/stream_out/transcode/encoder/video.c
+++ b/modules/stream_out/transcode/encoder/video.c
@@ -209,6 +209,21 @@ static void transcode_video_size_config_apply( vlc_object_t *p_obj,
     }
 }
 
+void transcode_encoder_video_set_src(encoder_t *p_encoder, const video_format_t *p_src,
+                                     const transcode_encoder_config_t *p_cfg)
+{
+    video_format_t *p_enc_in = &p_encoder->fmt_in.video;
+    if( p_cfg->video.fps.num )
+    {
+        p_enc_in->i_frame_rate = p_cfg->video.fps.num;
+        p_enc_in->i_frame_rate_base = __MAX(p_cfg->video.fps.den, 1);
+    }
+    p_enc_in->orientation = ORIENT_NORMAL;
+
+    /* Modify to requested sizes/scale */
+    transcode_video_size_config_apply( VLC_OBJECT(p_encoder), p_src, p_cfg, p_enc_in );
+}
+
 void transcode_encoder_video_configure( vlc_object_t *p_obj,
                                         const video_format_t *p_dec_out,
                                         const transcode_encoder_config_t *p_cfg,
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 1eb26cc292..079ab4ada6 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -316,10 +316,10 @@ static int transcode_video_filters_init( sout_stream_t *p_stream,
         filter_chain_AppendFromString( id->p_uf_chain, p_cfg->psz_filters );
         p_src = filter_chain_GetFmtOut( id->p_uf_chain );
         debug_format( p_stream, p_src );
-   }
+    }
 
     /* Update encoder so it matches filters output */
-    transcode_encoder_update_format_in( id->encoder, p_src );
+    transcode_encoder_update_format_in( id->encoder, p_src, id->p_enccfg );
 
     /* SPU Sources */
     if( p_cfg->video.psz_spu_sources )



More information about the vlc-commits mailing list