简易改写Ffmpeg
2015-02-06 12:26
141 查看
防止调用Ffmpeg 的方法时导致主线程退出
注意: 需要对应修改exit_program()!!
源代码:
//register_exit(ffmpeg_cleanup); 这个可以不需要了
用 ffmpeg_cleanup(0);
代替 exit_program(received_nb_signals ? 255 : main_return_code);
读取文件信息:
int ff_PrintFile(char * filepath)
{
AVFormatContext * pFormatContext=NULL;
av_register_all();
pFormatContext = avformat_alloc_context();
if(avformat_open_input(&pFormatContext,filepath,NULL,NULL)!=0)
{
printf("Can not open the media file you specified!\n");
return -1;
}
if(avformat_find_stream_info(pFormatContext, NULL) < 0){
return -1;
}
av_dump_format(pFormatContext, 0, filepath, 0);
printf("\n****************file information*****************\n");
int video_stream=-1;
int audio_stream=-1;
int i=0;
for (i = 0; i < (int)pFormatContext->nb_streams; i++) {
AVStream* ist = pFormatContext->streams[i];
printf(" Stream #%d: timebase={num=%d, den=%d}\n", i, ist->time_base.num, ist->time_base.den);
if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
video_stream=i;
}
if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
{
audio_stream=i;
}
}
if(audio_stream==-1&&video_stream==-1)return -1;
printf("\n");
printf("input:%s",pFormatContext->iformat->long_name);
AVCodecContext *pCodecCtx,*pCodecCtx_au;
if(video_stream!=-1)
{
pCodecCtx=pFormatContext->streams[video_stream]->codec;
printf("size:%d x %d",pCodecCtx->width,pCodecCtx->height);
float framerate_temp=(pFormatContext->streams[video_stream]->r_frame_rate.num)/(pFormatContext->streams[video_stream]->r_frame_rate.den);
printf("framerate:%5.2ffps",framerate_temp);
}
printf("\n");
if(audio_stream!=-1)
{
pCodecCtx_au=pFormatContext->streams[audio_stream]->codec;
//pCodec_au=avcodec_find_decoder(pCodecCtx_au->codec_id);
//printf("%s",pCodecCtx_au->codec->name);
printf("profile:%d",pCodecCtx_au->profile);
printf("level:%d",pCodecCtx_au->level);
printf("sample_rate:%d",pCodecCtx_au->sample_rate);
printf("channels:%d",pCodecCtx_au->channels);
}
printf("bit_rate:%5.2fkbps",pFormatContext->bit_rate/1000.0);
int tns, thh, tmm, tss;
tns = (pFormatContext->duration)/1000000;
thh = tns / 3600;
tmm = (tns % 3600) / 60;
tss = (tns % 60);
printf("\n");
printf("duration:%02d:%02d:%02d",thh,tmm,tss);
printf("\n");
AVDictionaryEntry *m = NULL;
while(m=av_dict_get(pFormatContext->metadata,"",m,AV_DICT_IGNORE_SUFFIX))
{
printf("%s:",m->key);
printf("%s",m->value);
printf("\n");
}
printf("\n****************file information*****************\n");
avformat_close_input(&pFormatContext);
return 0;
}
修改文件作者和专辑等信息
可在opt 下方法open_output_file添加
av_dict_set(&oc->metadata, "artist", "ffedu", AV_DICT_MATCH_CASE);
av_dict_set(&oc->metadata, "album", "ffedu", AV_DICT_MATCH_CASE);
注意: 需要对应修改exit_program()!!
源代码:
//register_exit(ffmpeg_cleanup); 这个可以不需要了
用 ffmpeg_cleanup(0);
代替 exit_program(received_nb_signals ? 255 : main_return_code);
读取文件信息:
int ff_PrintFile(char * filepath)
{
AVFormatContext * pFormatContext=NULL;
av_register_all();
pFormatContext = avformat_alloc_context();
if(avformat_open_input(&pFormatContext,filepath,NULL,NULL)!=0)
{
printf("Can not open the media file you specified!\n");
return -1;
}
if(avformat_find_stream_info(pFormatContext, NULL) < 0){
return -1;
}
av_dump_format(pFormatContext, 0, filepath, 0);
printf("\n****************file information*****************\n");
int video_stream=-1;
int audio_stream=-1;
int i=0;
for (i = 0; i < (int)pFormatContext->nb_streams; i++) {
AVStream* ist = pFormatContext->streams[i];
printf(" Stream #%d: timebase={num=%d, den=%d}\n", i, ist->time_base.num, ist->time_base.den);
if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
video_stream=i;
}
if(pFormatContext->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
{
audio_stream=i;
}
}
if(audio_stream==-1&&video_stream==-1)return -1;
printf("\n");
printf("input:%s",pFormatContext->iformat->long_name);
AVCodecContext *pCodecCtx,*pCodecCtx_au;
if(video_stream!=-1)
{
pCodecCtx=pFormatContext->streams[video_stream]->codec;
printf("size:%d x %d",pCodecCtx->width,pCodecCtx->height);
float framerate_temp=(pFormatContext->streams[video_stream]->r_frame_rate.num)/(pFormatContext->streams[video_stream]->r_frame_rate.den);
printf("framerate:%5.2ffps",framerate_temp);
}
printf("\n");
if(audio_stream!=-1)
{
pCodecCtx_au=pFormatContext->streams[audio_stream]->codec;
//pCodec_au=avcodec_find_decoder(pCodecCtx_au->codec_id);
//printf("%s",pCodecCtx_au->codec->name);
printf("profile:%d",pCodecCtx_au->profile);
printf("level:%d",pCodecCtx_au->level);
printf("sample_rate:%d",pCodecCtx_au->sample_rate);
printf("channels:%d",pCodecCtx_au->channels);
}
printf("bit_rate:%5.2fkbps",pFormatContext->bit_rate/1000.0);
int tns, thh, tmm, tss;
tns = (pFormatContext->duration)/1000000;
thh = tns / 3600;
tmm = (tns % 3600) / 60;
tss = (tns % 60);
printf("\n");
printf("duration:%02d:%02d:%02d",thh,tmm,tss);
printf("\n");
AVDictionaryEntry *m = NULL;
while(m=av_dict_get(pFormatContext->metadata,"",m,AV_DICT_IGNORE_SUFFIX))
{
printf("%s:",m->key);
printf("%s",m->value);
printf("\n");
}
printf("\n****************file information*****************\n");
avformat_close_input(&pFormatContext);
return 0;
}
修改文件作者和专辑等信息
可在opt 下方法open_output_file添加
av_dict_set(&oc->metadata, "artist", "ffedu", AV_DICT_MATCH_CASE);
av_dict_set(&oc->metadata, "album", "ffedu", AV_DICT_MATCH_CASE);
相关文章推荐
- 『转』credential Provider 简易改写攻略
- FFMPEG+SDL2.0流媒体开发3---简易MP4视频播放器,提取MP4的H264视频序列解码并且显示
- 用JavaCV改写“100行代码实现最简单的基于FFMPEG+SDL的视频播放器 ”
- Ffmpeg 安装,改写Ffmpeg并封装成so
- 使用ffmpeg和nginx搭建一个简易的HLS服务器(2)-参考
- Web直播系列2——nginx+ffmpeg+ckplayer的简易直播平台
- ffmpeg实战教程(二)用SDL播放YUV,并结合ffmpeg实现简易播放器
- Ubuntu16.04,ffmpeg搭建简易监控环境
- credential Provider 简易改写攻略
- 简易的$_GET获取改写过滤函数
- 使用 HttpClient 和 HtmlParser 实现简易爬虫
- OPENCV2.3 + FFMPEG + Visual Studio 2008 的坑爹之旅
- ffmpeg+ffserver媒体服务搭建小记
- 最简单的基于FFmpeg的移动端例子:Android 视频解码器
- ffmpeg常用命令及其使用
- 简易解说拉格朗日对偶(Lagrange duality)
- 利用ffmpeg来进行视频解码的完整示例代码
- HDU 2083 简易版之最短距离
- ffmpeg相关调研
- ffmpeg 学习资料