]> git.sesse.net Git - vlc/commitdiff
* modules/stream_out/transcode.c: couple of fixes.
authorGildas Bazin <gbazin@videolan.org>
Thu, 9 Oct 2003 18:53:01 +0000 (18:53 +0000)
committerGildas Bazin <gbazin@videolan.org>
Thu, 9 Oct 2003 18:53:01 +0000 (18:53 +0000)
* modules/codec/theora.c, modules/mux/ogg.c: proper granulepos generation for theora streams.
* modules/mux/ogg.c: ignore pts from headers.

modules/codec/theora.c
modules/mux/ogg.c
modules/stream_out/transcode.c

index beb4cf42af7099136ffe0ce4cff931e1d69e108d..ac2462443ce6af86e4e9b1eaa9cb798377ea6e38 100644 (file)
@@ -2,7 +2,7 @@
  * theora.c: theora decoder module making use of libtheora.
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: theora.c,v 1.11 2003/10/09 11:48:41 gbazin Exp $
+ * $Id: theora.c,v 1.12 2003/10/09 18:53:00 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -696,7 +696,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_pict->date;//oggpacket.granulepos;
+    p_block->i_dts = p_block->i_pts = p_pict->date;;
 
     return p_block;
 }
index 9845ca9f24fbbb8a9dc6967bd27f2b28e894aac8..b2a7f31293d0ad54ad7ca61d054d93a66edf3400 100644 (file)
@@ -2,7 +2,7 @@
  * ogg.c: ogg muxer module for vlc
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ogg.c,v 1.15 2003/10/09 11:48:41 gbazin Exp $
+ * $Id: ogg.c,v 1.16 2003/10/09 18:53:01 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@netcourrier.com>
@@ -174,6 +174,7 @@ static int MuxGetStream( sout_mux_t *p_mux, int *pi_stream, mtime_t *pi_dts )
             sout_buffer_t *p_buf;
 
             p_buf = sout_FifoShow( p_fifo );
+            if( p_buf->i_dts ) // To ignore vorbis and theora header packets
             if( i_stream < 0 || p_buf->i_dts < i_dts )
             {
                 i_dts = p_buf->i_dts;
@@ -211,6 +212,7 @@ typedef struct
     mtime_t i_length;
     int     i_packet_no;
     int     i_serial_no;
+    int     i_keyframe_granule_shift; /* Theora only */
     ogg_stream_state os;
 
     oggds_header_t oggds_header;
@@ -606,6 +608,21 @@ static sout_buffer_t *OggCreateHeader( sout_mux_t *p_mux, mtime_t i_dts )
             }
             p_og = sout_BufferDuplicate( p_mux->p_sout,
                                          p_stream->pp_sout_headers[0] );
+
+            /* Get keyframe_granule_shift for theora granulepos calculation */
+            if( p_stream->i_fourcc == VLC_FOURCC( 't', 'h', 'e', 'o' ) )
+            {
+                int i_keyframe_frequency_force = 1 << (op.packet[36] >> 3);
+
+                /* granule_shift = i_log( frequency_force -1 ) */
+                p_stream->i_keyframe_granule_shift = 0;
+                i_keyframe_frequency_force--;
+                while( i_keyframe_frequency_force )
+                {
+                    p_stream->i_keyframe_granule_shift++;
+                    i_keyframe_frequency_force >>= 1;
+                }
+            }
         }
         else
         {
@@ -866,7 +883,9 @@ static int Mux( sout_mux_t *p_mux )
         {
             if( p_stream->i_fourcc == VLC_FOURCC( 't', 'h', 'e', 'o' ) )
             {
-                op.granulepos = op.packetno; /* FIXME */
+                /* FIXME, we assume only keyframes and 25fps */
+               op.granulepos = ( ( i_dts - p_sys->i_start_dts ) * I64C(25)
+                    / I64C(1000000) ) << p_stream->i_keyframe_granule_shift;
             }
             else
                 op.granulepos = ( i_dts - p_sys->i_start_dts ) * I64C(10) /
index 1ed1720def7b8e0e83e4cc3b7ca5a8e4b88f68ad..57cb8987463157cccb8332e1ec1b57935a548c8a 100644 (file)
@@ -2,7 +2,7 @@
  * transcode.c
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: transcode.c,v 1.39 2003/10/09 12:31:05 gbazin Exp $
+ * $Id: transcode.c,v 1.40 2003/10/09 18:53:01 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -1223,7 +1223,7 @@ static int transcode_video_ffmpeg_new( sout_stream_t *p_stream,
 
 
     /* find encoder */
-    id->ff_enc = NULL;
+    id->ff_enc = id->ff_enc_c = NULL;
     i_ff_codec = get_ff_codec( id->f_dst.i_fourcc );
     if( i_ff_codec != 0 )
     {
@@ -1395,7 +1395,7 @@ static void transcode_video_ffmpeg_close ( sout_stream_t *p_stream, sout_stream_
     }
 
     free( id->ff_dec_c );
-    free( id->ff_enc_c );
+    if( id->ff_enc_c ) free( id->ff_enc_c );
     free( id->p_buffer );
 }
 
@@ -1637,7 +1637,8 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
         }
 
         /* Set the pts of the frame being encoded (segfaults with mpeg4!)*/
-        if( id->f_dst.i_fourcc == VLC_FOURCC( 'm', 'p', 'g', 'v' ) )
+        if( id->p_encoder ||
+            id->f_dst.i_fourcc == VLC_FOURCC( 'm', 'p', 'g', 'v' ) )
             frame->pts = p_sys->i_output_pts;
         else
             frame->pts = 0;
@@ -1675,6 +1676,8 @@ static int transcode_video_ffmpeg_process( sout_stream_t *p_stream,
                 sout_buffer_t *p_out;
                 p_out = sout_BufferNew( p_stream->p_sout, p_block->i_buffer );
                 memcpy( p_out->p_buffer, p_block->p_buffer, p_block->i_buffer);
+                p_out->i_dts = p_block->i_dts;
+                p_out->i_pts = p_block->i_pts;
                 sout_BufferChain( out, p_out );
                 block_Release( p_block );
             }