]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '884f7c975f0af25febe86660e87bf3b2165a0309'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 26 Jul 2014 19:04:31 +0000 (21:04 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 26 Jul 2014 19:04:31 +0000 (21:04 +0200)
* commit '884f7c975f0af25febe86660e87bf3b2165a0309':
  output example: set the stream timebase

Conflicts:
doc/examples/muxing.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
doc/examples/muxing.c

index ea5c78e28928644ee23416e6d859d492577bc7d4,239fe5b3ebbd08ded23a30ad9b3d394d574e4dd2..72131139ef13de9c0efc6779bcc9d1eb99206979
@@@ -101,56 -81,24 +101,58 @@@ static void add_stream(OutputStream *os
          exit(1);
      }
  
 -    ost->st = avformat_new_stream(oc, codec);
 +    ost->st = avformat_new_stream(oc, *codec);
      if (!ost->st) {
 -        fprintf(stderr, "Could not alloc stream\n");
 +        fprintf(stderr, "Could not allocate stream\n");
          exit(1);
      }
 -
 +    ost->st->id = oc->nb_streams-1;
      c = ost->st->codec;
  
 -    /* put sample parameters */
 -    c->sample_fmt  = AV_SAMPLE_FMT_S16;
 -    c->bit_rate    = 64000;
 -    c->sample_rate = 44100;
 -    c->channels    = 2;
 -    c->channel_layout = AV_CH_LAYOUT_STEREO;
 +    switch ((*codec)->type) {
 +    case AVMEDIA_TYPE_AUDIO:
 +        c->sample_fmt  = (*codec)->sample_fmts ?
 +            (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
 +        c->bit_rate    = 64000;
 +        c->sample_rate = 44100;
 +        c->channels    = 2;
 +        c->channel_layout = AV_CH_LAYOUT_STEREO;
++        ost->st->time_base = (AVRational){ 1, c->sample_rate };
 +        break;
 +
 +    case AVMEDIA_TYPE_VIDEO:
 +        c->codec_id = codec_id;
 +
 +        c->bit_rate = 400000;
 +        /* Resolution must be a multiple of two. */
 +        c->width    = 352;
 +        c->height   = 288;
 +        /* timebase: This is the fundamental unit of time (in seconds) in terms
 +         * of which frame timestamps are represented. For fixed-fps content,
 +         * timebase should be 1/framerate and timestamp increments should be
 +         * identical to 1. */
-         c->time_base.den = STREAM_FRAME_RATE;
-         c->time_base.num = 1;
++        ost->st->time_base = (AVRational){ 1, STREAM_FRAME_RATE };
++        c->time_base       = ost->st->time_base;
++
 +        c->gop_size      = 12; /* emit one intra frame every twelve frames at most */
 +        c->pix_fmt       = STREAM_PIX_FMT;
 +        if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
 +            /* just for testing, we also add B frames */
 +            c->max_b_frames = 2;
 +        }
 +        if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
 +            /* Needed to avoid using macroblocks in which some coeffs overflow.
 +             * This does not happen with normal video, it just happens here as
 +             * the motion of the chroma plane does not match the luma plane. */
 +            c->mb_decision = 2;
 +        }
 +    break;
  
 -    ost->st->time_base = (AVRational){ 1, c->sample_rate };
 +    default:
 +        break;
 +    }
  
 -    // some formats want stream headers to be separate
 +    /* Some formats want stream headers to be separate. */
      if (oc->oformat->flags & AVFMT_GLOBALHEADER)
          c->flags |= CODEC_FLAG_GLOBAL_HEADER;
  }