/*******************
程序功能:
获取多节目码流中的所有节目号,然后选定节目号,将该节目号对应的节目的视频流和音频流从码流中分离出来
*******************/
extern "C"
{
#include "libavformat\avformat.h"
};
int PrintfMediaProgram(char* MediaName)
{
AVFormatContext *pFormatContext = NULL;
pFormatContext = avformat_alloc_context();
if(avformat_open_input(&pFormatContext,MediaName,NULL,NULL)!= 0)
{
avformat_free_context(pFormatContext);
return -1;
}
if(avformat_find_stream_info(pFormatContext,NULL) < 0)
{
avformat_close_input(&pFormatContext);
return -2;
}
av_dump_format(pFormatContext,NULL,MediaName,0);
for(int i=0;i<pFormatContext->nb_programs;i++)
{
printf("第%d个节目的节目号:%d\n",i+1,pFormatContext->programs[i]->id);
}
avformat_close_input(&pFormatContext);
return 0;
}
int MediaSeparate(char *MediaName,int ProgramNumber,char *VideoName,char *AudioName)
{
AVFormatContext *pFormatContext = NULL;
pFormatContext = avformat_alloc_context();
if(avformat_open_input(&pFormatContext,MediaName,NULL,NULL)!= 0)
{
avformat_free_context(pFormatContext);
return -1;
}
if(avformat_find_stream_info(pFormatContext,NULL) < 0)
{
avformat_close_input(&pFormatContext);
return -2;
}
int VideoIndex = -1,AudioIndex = -1;
for(int i=0;i<pFormatContext->nb_programs;i++)
{
if(pFormatContext->programs[i]->id == ProgramNumber)
{
for(int j=0;j<pFormatContext->programs[i]->nb_stream_indexes;j++)
{
if(pFormatContext->streams[pFormatContext->programs[i]->stream_index[j]]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
VideoIndex = pFormatContext->programs[i]->stream_index[j];
if(pFormatContext->streams[pFormatContext->programs[i]->stream_index[j]]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
AudioIndex = pFormatContext->programs[i]->stream_index[j];
}
}
}
FILE *fw_v = fopen(VideoName,"wb");
FILE *fw_a = fopen(AudioName,"wb");
if((fw_v == NULL) || (fw_a == NULL))
{
avformat_close_input(&pFormatContext);
return -3;
}
AVPacket pPacket;
while(av_read_frame(pFormatContext,&pPacket) >= 0)
{
if(pPacket.stream_index == VideoIndex)
{
fwrite(pPacket.data,1,pPacket.size,fw_v);
}
if(pPacket.stream_index == AudioIndex)
fwrite(pPacket.data,1,pPacket.size,fw_a);
av_free_packet(&pPacket);
}
fclose(fw_a);
fclose(fw_v);
avformat_close_input(&pFormatContext);
return 0;
}
int main()
{
av_register_all();
char *FileName = "Media_2.ts";
PrintfMediaProgram(FileName);
printf("请输入节目号:");
int ProgramNumber = 0;
scanf("%d",&ProgramNumber);
MediaSeparate(FileName,ProgramNumber,"Video.h264","Audio.aac");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
FFmpeg_03_视音频流分离
共197个文件
h:98个
tlog:62个
lib:8个
2星 需积分: 45 12 下载量 197 浏览量
2015-08-06
09:48:16
上传
评论
收藏 54.39MB ZIP 举报
温馨提示
FFmpeg系列,之前有发过一部分,但并未系列总结性将功能展现,目前按序号,将常用的发上来,VC2010环境下
资源推荐
资源详情
资源评论
收起资源包目录
FFmpeg_03_视音频流分离 (197个子文件)
FFmpeg.cpp 3KB
Thumbs.db 16KB
avcodec-56.dll 21.33MB
avformat-56.dll 5.73MB
avfilter-5.dll 2.28MB
avdevice-56.dll 1.32MB
avutil-54.dll 482KB
swscale-3.dll 442KB
swresample-1.dll 275KB
postproc-53.dll 129KB
FFmpeg.exe 30KB
FFmpeg.vcxproj.filters 955B
avcodec.h 178KB
avformat.h 103KB
avfilter.h 56KB
opt.h 37KB
pixfmt.h 34KB
frame.h 24KB
avio.h 22KB
swresample.h 20KB
intreadwrite.h 18KB
avdevice.h 18KB
pixdesc.h 15KB
mem.h 14KB
common.h 14KB
old_pix_fmts.h 14KB
avstring.h 13KB
swscale.h 12KB
log.h 10KB
old_codec_ids.h 10KB
samplefmt.h 10KB
buffer.h 10KB
channel_layout.h 9KB
avutil.h 8KB
imgutils.h 8KB
_mingw.h 8KB
vdpau.h 8KB
dict.h 8KB
bprint.h 8KB
parseutils.h 7KB
buffersink.h 7KB
version.h 6KB
xvmc.h 6KB
vda.h 6KB
stdint.h 6KB
inttypes.h 6KB
error.h 5KB
timecode.h 5KB
eval.h 5KB
mathematics.h 5KB
fifo.h 5KB
cpu.h 5KB
buffersrc.h 5KB
audio_fifo.h 4KB
rational.h 4KB
attributes.h 4KB
version.h 4KB
vaapi.h 4KB
dv_profile.h 4KB
stereo3d.h 4KB
hash.h 4KB
asrc_abuffer.h 3KB
downmix_info.h 3KB
display.h 3KB
threadmessage.h 3KB
avfft.h 3KB
postprocess.h 3KB
version.h 3KB
hmac.h 3KB
bswap.h 3KB
crc.h 3KB
timestamp.h 3KB
cast5.h 2KB
d3d11va.h 2KB
file.h 2KB
version.h 2KB
avcodec.h 2KB
dxva2.h 2KB
vorbis_parser.h 2KB
blowfish.h 2KB
twofish.h 2KB
camellia.h 2KB
avassert.h 2KB
base64.h 2KB
pixelutils.h 2KB
lzo.h 2KB
sha512.h 2KB
ripemd.h 2KB
version.h 2KB
lfg.h 2KB
md5.h 2KB
sha.h 2KB
xtea.h 2KB
version.h 2KB
aes.h 2KB
time.h 2KB
intfloat.h 2KB
version.h 2KB
version.h 2KB
replaygain.h 2KB
共 197 条
- 1
- 2
资源评论
- zhanwen07202022-02-13分离之后无法播放
黄忻
- 粉丝: 27
- 资源: 108
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功