Browse code

user selectable packet_size and mux_rate

Originally committed as revision 3566 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2004/10/07 07:29:30
Showing 3 changed files
... ...
@@ -200,6 +200,9 @@ static int audio_disable = 0;
200 200
 static int audio_channels = 1;
201 201
 static int audio_codec_id = CODEC_ID_NONE;
202 202
 
203
+static int mux_rate= 0;
204
+static int mux_packet_size= 0;
205
+
203 206
 static int64_t recording_time = 0;
204 207
 static int64_t start_time = 0;
205 208
 static int64_t rec_timestamp = 0;
... ...
@@ -3290,6 +3293,9 @@ static void opt_output_file(const char *filename)
3290 3290
         exit(1);
3291 3291
     }
3292 3292
 
3293
+    oc->packet_size= mux_packet_size;
3294
+    oc->mux_rate= mux_rate;
3295
+
3293 3296
     /* reset some options */
3294 3297
     file_oformat = NULL;
3295 3298
     file_iformat = NULL;
... ...
@@ -3649,6 +3655,9 @@ static void opt_target(const char *arg)
3649 3649
 
3650 3650
         audio_bit_rate = 224000;
3651 3651
         audio_sample_rate = 44100;
3652
+        
3653
+        mux_packet_size= 2324;
3654
+        mux_rate= 2352 * 75 * 8;
3652 3655
 
3653 3656
     } else if(!strcmp(arg, "svcd")) {
3654 3657
 
... ...
@@ -3668,6 +3677,8 @@ static void opt_target(const char *arg)
3668 3668
         audio_bit_rate = 224000;
3669 3669
         audio_sample_rate = 44100;
3670 3670
 
3671
+        mux_packet_size= 2324;
3672
+
3671 3673
     } else if(!strcmp(arg, "dvd")) {
3672 3674
 
3673 3675
         opt_video_codec("mpeg2video");
... ...
@@ -3865,6 +3876,10 @@ const OptionDef options[] = {
3865 3865
     { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" },
3866 3866
     { "dv1394", OPT_EXPERT | OPT_GRAB, {(void*)opt_dv1394}, "set DV1394 grab", "" },
3867 3867
     { "ad", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_GRAB, {(void*)opt_audio_device}, "set audio device", "device" },
3868
+ 
3869
+    /* muxer options */   
3870
+    { "muxrate", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&mux_rate}, "set mux rate", "rate" },
3871
+    { "packetsize", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&mux_packet_size}, "set packet size", "size" },
3868 3872
     { NULL, },
3869 3873
 };
3870 3874
 
... ...
@@ -302,6 +302,9 @@ typedef struct AVFormatContext {
302 302
     /* av_seek_frame() support */
303 303
     int64_t data_offset; /* offset of the first packet */
304 304
     int index_built;
305
+    
306
+    int mux_rate;
307
+    int packet_size;
305 308
 } AVFormatContext;
306 309
 
307 310
 typedef struct AVPacketList {
... ...
@@ -256,11 +256,11 @@ static int mpeg_mux_init(AVFormatContext *ctx)
256 256
     s->is_mpeg2 = (ctx->oformat == &mpeg2vob_mux || ctx->oformat == &mpeg2svcd_mux || ctx->oformat == &mpeg2dvd_mux);
257 257
     s->is_dvd = (ctx->oformat == &mpeg2dvd_mux);
258 258
     
259
-    if (s->is_vcd || s->is_svcd)
260
-        s->packet_size = 2324; /* VCD/SVCD packet size */
259
+    if(ctx->packet_size)
260
+        s->packet_size = ctx->packet_size;
261 261
     else
262 262
         s->packet_size = 2048;
263
-
263
+       
264 264
     s->vcd_padding_bytes_written = 0;
265 265
     s->vcd_padding_bitrate=0;
266 266
         
... ...
@@ -354,6 +354,16 @@ static int mpeg_mux_init(AVFormatContext *ctx)
354 354
         else if (stream->id==VIDEO_ID)
355 355
             video_bitrate += codec_rate;
356 356
     }
357
+    
358
+    if(ctx->mux_rate){
359
+        s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50);
360
+    } else {
361
+        /* we increase slightly the bitrate to take into account the
362
+           headers. XXX: compute it exactly */
363
+        bitrate += bitrate*5/100;
364
+        bitrate += 10000;
365
+        s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
366
+    }
357 367
 
358 368
     if (s->is_vcd) {
359 369
         double overhead_rate;
... ...
@@ -365,7 +375,7 @@ static int mpeg_mux_init(AVFormatContext *ctx)
365 365
            rate you get a different value because the real pack size is 2324,
366 366
            not 2352. But the standard explicitly specifies that the mux_rate
367 367
            field in the header must have this value.*/
368
-        s->mux_rate=2352 * 75 / 50;    /* = 3528*/
368
+//        s->mux_rate=2352 * 75 / 50;    /* = 3528*/
369 369
 
370 370
         /* The VCD standard states that the muxed stream must be
371 371
            exactly 75 packs / second (the data rate of a single speed cdrom).
... ...
@@ -382,13 +392,6 @@ static int mpeg_mux_init(AVFormatContext *ctx)
382 382
         
383 383
         /* Add padding so that the full bitrate is 2324*75 bytes/sec */
384 384
         s->vcd_padding_bitrate = 2324 * 75 * 8 - (bitrate + overhead_rate);
385
-
386
-    } else {
387
-        /* we increase slightly the bitrate to take into account the
388
-           headers. XXX: compute it exactly */
389
-        bitrate += bitrate*5/100;
390
-        bitrate += 10000;
391
-        s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
392 385
     }
393 386
     
394 387
     if (s->is_vcd || s->is_mpeg2)
... ...
@@ -972,6 +975,7 @@ retry:
972 972
     }
973 973
 
974 974
     if(timestamp_packet){
975
+//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i);
975 976
         es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size);
976 977
     }else{
977 978
         assert(fifo_size(&stream->fifo, stream->fifo.rptr) == trailer_size);