ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5789|回复: 1

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

[复制链接]
发表于 2013-10-18 10:42:00 | 显示全部楼层 |阅读模式
我上ffpmeg的doc目录下阅读了muxing.c,还是不会容器封装,求高手指点下方法!
原始数据为h264裸流视频数据。
回复

使用道具 举报

发表于 2013-10-18 12:10:35 | 显示全部楼层

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

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

  13.         if ((!audio_st || audio_time >= STREAM_DURATION) &&
  14.             (!video_st || video_time >= STREAM_DURATION))
  15.             break;

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

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

复制代码
其实主要流程还是在这里
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-4-30 19:12 , Processed in 0.059159 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表