BeyondCode 发表于 2013-10-18 10:42:00

如何利用ffpmeg封装h264裸流成Mpg2容器?

我上ffpmeg的doc目录下阅读了muxing.c,还是不会容器封装,求高手指点下方法!
原始数据为h264裸流视频数据。

T-Bagwell 发表于 2013-10-18 12:10:35


    ret = avformat_write_header(oc, NULL);
    if (ret < 0) {
      fprintf(stderr, "Error occurred when opening output file: %s\n",
                av_err2str(ret));
      return 1;
    }   

    if (frame)
      frame->pts = 0;
    for (;;) {
      /* Compute current audio and video time. */
      audio_time = audio_st ? audio_st->pts.val * av_q2d(audio_st->time_base) : 0.0;
      video_time = video_st ? video_st->pts.val * av_q2d(video_st->time_base) : 0.0;

      if ((!audio_st || audio_time >= STREAM_DURATION) &&
            (!video_st || video_time >= STREAM_DURATION))
            break;

      /* write interleaved audio and video frames */
      if (!video_st || (video_st && audio_st && audio_time < video_time)) {
            write_audio_frame(oc, audio_st);
      } else {
            write_video_frame(oc, video_st);
            frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);
      }   
    }   

    /* Write the trailer, if any. The trailer must be written before you
   * close the CodecContexts open when you wrote the header; otherwise
   * av_write_trailer() may try to use memory that was freed on
   * av_codec_close(). */
    av_write_trailer(oc);

其实主要流程还是在这里
页: [1]
查看完整版本: 如何利用ffpmeg封装h264裸流成Mpg2容器?