ffmpeg转码之TS转PS
来源:互联网 发布:eve目标证据数据 编辑:程序博客网 时间:2024/04/30 02:26
Remux:无损的取出HD-DVD和BluRay-DVD里面的视频和音频数据,重新封装到另一种容器。
根据ffmpeg的sample例子remuxing写了一个ts转ps的例子。
写了一个ts转ps的demo。ts数据从文件中读取。
ffmpeg怎么从从内存中获取看这篇博文http://blog.csdn.net/rootusers/article/details/42551935
然后将ts流转换为ps流,存储在内存中。
下面是代码:
<pre name="code" class="cpp">extern "C"{#include "libavformat/avformat.h"}FILE *file = NULL;int write_packet(void *opaque, uint8_t *buf, int buf_size){//printf("write data\n");if (file)fwrite(buf, buf_size, 1, file);//可以写文件,也可以通过协议发出去return 0;}int main(int argc, char **argv){fopen_s(&file, "output.dat", "ab+");//输出ps数据到文件if (file == NULL)printf("open output file failed\n");AVIOContext* pb = NULL;AVOutputFormat *ofmt = (AVOutputFormat*)av_mallocz(sizeof(AVOutputFormat));//输出格式AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;AVPacket pkt;const char *in_filename, *out_filename;int ret, i;in_filename = "nihao.ts";//源文件av_register_all();if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {fprintf(stderr, "Could not open input file '%s'", in_filename);goto end;}if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {fprintf(stderr, "Failed to retrieve input stream information");goto end;}av_dump_format(ifmt_ctx, 0, in_filename, 0);uint8_t* buf = (uint8_t*)av_mallocz(sizeof(uint8_t)* 32768);pb = avio_alloc_context(buf, 32768, 0, NULL, NULL, write_packet, NULL);//avformat_alloc_output_context2(&ofmt_ctx, NULL, "dvd", NULL/*out_filename*/);//设置输出视频的格式为Mpegs-ps,在ffmpeg定义为dvdif (!ofmt_ctx) {fprintf(stderr, "Could not create output context\n");ret = AVERROR_UNKNOWN;goto end;}ofmt_ctx->pb = pb;//这个是关键,指定ps输出的方式//ofmt_ctx->flags = AVFMT_FLAG_CUSTOM_IO;//dvdprintf("output format:%s[%s]\n", ofmt_ctx->oformat->name, ofmt_ctx->oformat->long_name);ofmt = ofmt_ctx->oformat;//输出环境上下文的初始化for (i = 0; i < ifmt_ctx->nb_streams; i++) {AVStream *in_stream = ifmt_ctx->streams[i];//Add a new stream to a media fileAVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);if (!out_stream) {fprintf(stderr, "Failed allocating output stream\n");ret = AVERROR_UNKNOWN;goto end;}ret = avcodec_copy_context(out_stream->codec, in_stream->codec);if (ret < 0) {fprintf(stderr, "Failed to copy context from input to output stream codec context\n");goto end;}out_stream->codec->codec_tag = 0;if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;}av_dump_format(ofmt_ctx, 0, NULL, 1);ret = avformat_write_header(ofmt_ctx, NULL);if (ret < 0) {fprintf(stderr, "Error occurred when opening output file\n");goto end;}//实现REMUXINGwhile (1) {AVStream *in_stream, *out_stream;ret = av_read_frame(ifmt_ctx, &pkt);if (ret < 0)break;in_stream = ifmt_ctx->streams[pkt.stream_index];out_stream = ofmt_ctx->streams[pkt.stream_index];pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);pkt.pos = -1;ret = av_interleaved_write_frame(ofmt_ctx, &pkt);if (ret < 0) {fprintf(stderr, "Error muxing packet\n");break;}av_free_packet(&pkt);}av_write_trailer(ofmt_ctx);end:avformat_close_input(&ifmt_ctx);/* close output */if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))avio_close(ofmt_ctx->pb);avformat_free_context(ofmt_ctx);if (ret < 0 && ret != AVERROR_EOF) {return 1;}return 0;}
0 0
- ffmpeg转码之TS转PS
- ffmpeg MP4转TS
- ffmpeg转TS流
- ffmpeg 转ts文件命令
- ffmpeg转mp4为ts 命令行实现
- 有关视频传输中TS、PS的释疑(转)
- ffmpeg 视频转ts切片并生成m3u8播放列表文件
- ffmpeg ts
- TS流解析之TS包头解析(转)
- PES,TS,PS,mpeg-ts,mpeg-ps
- FFmpeg 学习之 Mediainfo 读取多信道 TS 视频码流
- MKV转码为TS
- ES、TS、PS流
- ES、TS、PS流
- ES、TS、PS流
- PS and TS
- ES、TS、PS流
- TS,PS,ES
- servlet 文件下载
- opencv说明文档
- OC 便利构造器对象
- 深入浅出数据仓库中SQL性能优化之Hive篇
- solr-4.10.3 安装在windows 7 并集成IK分词器
- ffmpeg转码之TS转PS
- hexo博客出现command not found解决方案
- 修复iOS7下leftBarButtonItem位置相比之前版本靠右的问题
- ios绘图
- 昨赘作祝祝茁兹啄奏壮字庄谞尊庄昨宗紫
- R语言实现数据抽样&创建训练集和测试集
- 1015.Reversible Primes
- 滋祝谆族租篆走滓宗遵撞座足滓字住桌作
- 解决WPF中popup跟随移动问题