ffmpeg分离ts为h264、aac
来源:互联网 发布:mac outlook 离线文件 编辑:程序博客网 时间:2024/04/30 02:24
把雷神的例子直接拿来的
DeMuxerAndroid.c
#include <jni.h>#include <string.h>#include <stdio.h>#include <android/log.h>#include <libavcodec/avcodec.h>#include <libavformat/avformat.h>#include <libswscale/swscale.h>#include <libavutil/frame.h>#include <libavutil/pixfmt.h>#define LOG_TAG "FFMPEGSample"#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)#include "libavformat/avformat.h"//'1': Use H.264 Bitstream Filter#define USE_H264BSF 1JNIEXPORT jint JNICALL Java_com_example_ffmpegdemuxer_DeMuxerAndroid_Demuxering(JNIEnv * env, jclass obj){AVFormatContext *ifmt_ctx = NULL;AVPacket pkt;int ret, i;int videoindex=-1,audioindex=-1;char *in_filename = "/sdcard/DeMuxer/test.ts";//输入文件名(Input file URL)char *out_filename_v = "/sdcard/DeMuxer/schoool.264";//输出文件名(Output file URL)char *out_filename_a = "/sdcard/DeMuxer/haiou.aac";av_register_all();//输入(Input)if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {LOGI( "Could not open input file.");return -1;}if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {LOGI( "Failed to retrieve input stream information");return -1;}videoindex=-1;for(i=0; i<ifmt_ctx->nb_streams; i++) {if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){videoindex=i;}else if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){audioindex=i;}}//Dump Format------------------LOGI("\nInput Video===========================\n");av_dump_format(ifmt_ctx, 0, in_filename, 0);LOGI("\n======================================\n");FILE *fp_audio=fopen(out_filename_a,"wb+");FILE *fp_video=fopen(out_filename_v,"wb+");/*FIX: H.264 in some container format (FLV, MP4, MKV etc.) need"h264_mp4toannexb" bitstream filter (BSF) *Add SPS,PPS in front of IDR frame *Add start code ("0,0,0,1") in front of NALUH.264 in some container (MPEG2TS) don't need this BSF.*/#if USE_H264BSFAVBitStreamFilterContext* h264bsfc = av_bitstream_filter_init("h264_mp4toannexb");#endifwhile(av_read_frame(ifmt_ctx, &pkt)>=0){if(pkt.stream_index==videoindex){#if USE_H264BSFav_bitstream_filter_filter(h264bsfc, ifmt_ctx->streams[videoindex]->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);#endifLOGI("Write Video Packet. size:%d",pkt.size);LOGI("Write Video Packet.pts---->%d",pkt.pts);fwrite(pkt.data,1,pkt.size,fp_video);}else if(pkt.stream_index==audioindex){/*AAC in some container format (FLV, MP4, MKV etc.) need to add 7 BytesADTS Header in front of AVPacket data manually.Other Audio Codec (MP3...) works well.*/LOGI("Write Audio Packet. size:%d",pkt.size);LOGI("Write Audio Packet.pts--->%d",pkt.pts);fwrite(pkt.data,1,pkt.size,fp_audio);}av_free_packet(&pkt);}#if USE_H264BSFav_bitstream_filter_close(h264bsfc);#endiffclose(fp_video);fclose(fp_audio);avformat_close_input(&ifmt_ctx);if (ret < 0 && ret != AVERROR_EOF) {LOGI( "Error occurred.");return -1;}return 0;}
Android.mk参照复用为ts的mk文件,其他的和复用ts的一样
0 0
- ffmpeg分离ts为h264、aac
- ffmpeg复用h264、aac为ts流
- ffmpeg将ts解封装为h264和aac文件测试代码
- ffmpeg将h264和aac合成ts,内存输入输出
- h264+aac=ts
- tstools封装H264+aac成TS文件
- tstools封装H264+aac成TS文件
- TS 解析 h264 aac 保存到文件
- ffmpeg h264+ts +udp传输
- 使用ffmpeg将mp4文件中的h264码流转为raw h264文件格式或ts文件格式
- hls直播实现源码V2(h264,aac流输入,ffmpeg实现,MFC,VC环境,ts,m3u8)
- ffmpeg实战教程(三)音频PCM采样为AAC,视频YUV编码为H264/HEVC
- FFmpeg合成h264视频流和aac音频流为mp4
- ffmpeg 接收h264+aac并解码
- ffmpeg 使用小记 h264 to ts
- CMMB中的H264和AAC打包成ts流
- CMMB中的H264和AAC打包成ts流
- CMMB中的H264和AAC打包成ts流
- 马士兵谈面试
- Cookie笔记
- 火狐关闭多个标签不要显示警告
- Java设计模式-单例模式(Singleton)
- test
- ffmpeg分离ts为h264、aac
- Android利用sharedpreferences缓存对象和数组数据与文件传输
- java.lang.IllegalArgumentException: you must specify a way to create the tab content
- jQuery搜索插件auntocomplete
- 深入理解PHP中赋值与引用
- 个人网站建立过程中遇到的问题
- java也谈gc
- 算法训练 区间k大数查询
- 22222222222222