[vlc-commits] packetizer: mpegvideo: read bitrate

Francois Cartegnie git at videolan.org
Wed Jan 29 18:30:13 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jan 28 16:20:50 2020 +0100| [ded153e300376448eb955de5f0e6c792a0729481] | committer: Francois Cartegnie

packetizer: mpegvideo: read bitrate

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

 modules/packetizer/mpegvideo.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c
index 0969d8fe8d..a9322fc877 100644
--- a/modules/packetizer/mpegvideo.c
+++ b/modules/packetizer/mpegvideo.c
@@ -140,7 +140,9 @@ typedef struct
     uint16_t i_h_size_value;
     uint16_t i_v_size_value;
     uint8_t  i_aspect_ratio_info;
+    uint32_t i_bitratelower18;
     /* Extended Sequence properties (MPEG2) */
+    uint16_t i_bitrateupper12;
     bool  b_seq_progressive;
     bool  b_low_delay;
 
@@ -242,6 +244,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_h_size_value = 0;
     p_sys->i_v_size_value = 0;
     p_sys->i_aspect_ratio_info = 0;
+    p_sys->i_bitratelower18 = 0;
+    p_sys->i_bitrateupper12 = 0;
     p_sys->b_seq_progressive = true;
     p_sys->b_low_delay = false;
     p_sys->i_seq_old = 0;
@@ -367,6 +371,11 @@ static void ProcessSequenceParameters( decoder_t *p_dec )
     else
         fmt->i_height = (fmt->i_visible_height + 0x1F) & ~0x1F;
 
+    /* Bitrate */
+    if( p_dec->fmt_out.i_bitrate == 0 )
+        p_dec->fmt_out.i_bitrate = ((p_sys->i_bitrateupper12 << 18) |
+                                    p_sys->i_bitratelower18) * 400;
+
     /* Frame Rate */
     if( fmt->i_frame_rate != (p_sys->dts.i_divider_num >> 1) ||
         fmt->i_frame_rate_base != p_sys->dts.i_divider_den )
@@ -761,7 +770,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
             p_sys->i_seq_old = 0;
         }
     }
-    else if( startcode == SEQUENCE_HEADER_STARTCODE && p_frag->i_buffer >= 8 )
+    else if( startcode == SEQUENCE_HEADER_STARTCODE && p_frag->i_buffer >= 11 )
     {
         /* Sequence header code */
         static const int code_to_frame_rate[16][2] =
@@ -802,6 +811,10 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
                 date_Change( &p_sys->prev_iframe_dts, num, den );
             }
         }
+
+        p_sys->i_bitratelower18 = (p_frag->p_buffer[ 8] << 12) |
+                                  (p_frag->p_buffer[ 9] <<  4) |
+                                  (p_frag->p_buffer[10] & 0x0F);
     }
     else if( startcode == EXTENSION_STARTCODE && p_frag->i_buffer > 4 )
     {
@@ -872,6 +885,9 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
 
                 p_sys->b_seq_progressive =
                     p_frag->p_buffer[5]&0x08 ? true : false;
+
+                p_sys->i_bitrateupper12 = ((p_frag->p_buffer[6] & 0x1F) << 8) | (p_frag->p_buffer[7] >> 1);
+
                 p_sys->b_low_delay =
                     p_frag->p_buffer[9]&0x80 ? true : false;
             }



More information about the vlc-commits mailing list