ffmpeg将flv解封装为h264和mp3文件测试代码
2016-08-28 13:45
501 查看
#include <stdio.h> #define __STDC_CONSTANT_MACROS #ifdef _WIN32 extern "C"{ #include "libavformat/avformat.h" }; #else #ifdef __cplusplus extern "C"{ #endif #include <libavformat/avformat.h> #ifdef __cplusplus }; #endif #endif int main(int argc, char* argv[]){ AVFormatContext *ifmt_ctx = NULL; AVPacket pkt; int ret, i; int videoindex = -1, audioindex = -1; const char *in_filename = "in.flv"; const char *out_filename_v = "out.h264"; const char *out_filename_a = "out.mp3"; av_register_all(); if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) { printf("Could not open input file."); return -1; } if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) { printf("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; } } printf("===========================\Input Video===========================\n"); av_dump_format(ifmt_ctx, 0, in_filename, 0); printf("==================================================================\n"); FILE *fp_audio = fopen(out_filename_a, "wb+"); FILE *fp_video = fopen(out_filename_v, "wb+"); while (av_read_frame(ifmt_ctx, &pkt) >= 0) { if (pkt.stream_index == videoindex) { printf("Write Video Packet. size:%d\tpts:%lld\n", pkt.size, pkt.pts); fwrite(pkt.data, 1, pkt.size, fp_video); } else if (pkt.stream_index == audioindex) { /*注意:FLV/MP4/MKV等格式中的AAC码流(上述封装格式中的AAC的AVPacket中的数据缺失了7字节的ADTS文件头)*/ printf("Write Audio Packet. size:%d\tpts:%lld\n", pkt.size, pkt.pts); fwrite(pkt.data, 1, pkt.size, fp_audio); } av_free_packet(&pkt); } fclose(fp_video); fclose(fp_audio); avformat_close_input(&ifmt_ctx); if (ret < 0 && ret != AVERROR_EOF) { printf("Error occurred.\n"); return -1; } return 0; }
相关文章推荐
- ffmpeg将ts解封装为h264和aac文件测试代码
- FFMPEG 从rtsp抓取流,转存为flv文件。C语言代码方式.
- ffmpeg的yuv压缩h264测试代码
- 使用ffmpeg将BMP图片编码为x264视频文件,将H264视频保存为BMP图片,yuv视频文件保存为图片的代码
- ffmpeg将mp4解封装为yuv以及pcm测试代码
- 实现用FFmpeg接收RTSP,把H264视频和AAC音频录制成MP4文件(附完整代码)
- 使用ffmpeg将BMP图片编码为x264视频文件,将H264视频保存为BMP图片,yuv视频文件保存为图片的代码
- 提取FLV视频文件中的音频到MP3文件(代码)
- ffmpeg将mp4解封装为yuv以及pcm测试代码2
- ffmpeg的h264转yuv实例测试代码
- 使用ffmpeg将BMP图片编码为x264视频文件,将H264视频保存为BMP图片,yuv视频文件保存为图片的代码
- 使用ffmpeg进行视频文件转换成FLV整理
- 安装和使用ffmpeg转换视频为flv文件
- 怎么利用ffmpeg和AviSynth给在windows下面为flv文件加水印
- 推荐几种在网页中播放FLV文件的代码
- 推荐几种在网页中播放FLV文件的代码
- messageflow 客户端之间传送文件 测试代码 手稿
- 用java程序调用ffmpeg执行视频文件格式转换flv
- 使用ffmpeg进行视频文件转换成FLV整理
- ASP.NET实现在线播放FLV视频文件的代码