我知道这样是错的,请有FFMPEG相关开发经验的朋友指点一下

maya8maya85 2016-08-04 01:14:13
流程是这样,选择文件-》播放-》中止播放-》重新选文件-》播放
我想问的是,为什么第二次选文件播放的时候,视频信息怎么都变0了?长啊,宽啊,总时长啊,是我哪里写错了?
主要的代码
//获取视频的长宽和总时长信息
void get_videoinfo()
{
av_register_all();
avformat_network_init();

vs = (VideoState *)av_mallocz(sizeof(VideoState));

AVFormatContext *pFormatCtx = NULL;

pFormatCtx = avformat_alloc_context();

unsigned char *aviobuffer = (unsigned char *)av_malloc(32768);
AVIOContext *avio = avio_alloc_context(aviobuffer, 32768, 0, NULL, read_buffer, NULL, NULL);
pFormatCtx->pb = avio;
pFormatCtx->flags = AVFMT_FLAG_CUSTOM_IO;

int x = avformat_open_input(&pFormatCtx, NULL, NULL, NULL);//中止播放后重新选文件也返回0

int y = avformat_find_stream_info(pFormatCtx, NULL);//中止播放后重新选文件也返回0

currentvwidth = pFormatCtx->streams[0]->codec->width;//中止播放后重新选文件变0了!!!!!!!!!!!!!!!!!
currentvheight = pFormatCtx->streams[0]->codec->height;//中止播放后重新选文件变0了!!!!!!!!!!!!!!!!!
currentvduration = (int)pFormatCtx->duration;//中止播放后重新选文件变0了!!!!!!!!!!!!!!!!!

//avcodec_close(pFormatCtx->streams[0]->codec);
avformat_close_input(&pFormatCtx);

pFormatCtx = NULL;
av_freep(vs);
vs = NULL;
avformat_network_deinit();
}

//中止播放的代码是这样的
vs->quit = true;
SDL_PauseAudio(true);
IsPlaying = false;

SDL_Event event;
event.type = FF_QUIT_EVENT;
event.user.data1 = vs;
SDL_PushEvent(&event);
SDL_WaitThread(vs->decode_tid, NULL);//等待线程停止

//播放的函数
bool StartPlay()
{
int dwNum = WideCharToMultiByte(CP_ACP, NULL, outfile, -1, NULL, 0, NULL, FALSE);
char *filepath = new char[dwNum];
if (!filepath) delete[] filepath;
WideCharToMultiByte(CP_ACP, NULL, outfile, -1, filepath, dwNum, NULL, FALSE);

av_register_all();
avformat_network_init();

if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO))
{
avformat_network_deinit();
return true;
}

vs = (VideoState *)av_mallocz(sizeof(VideoState));
if (!vs)
{
avformat_network_deinit();
SDL_Quit();
return true;
}
av_strlcpy(vs->file, filepath, sizeof(vs->file));
vs->pictq_mutex = SDL_CreateMutex();
vs->pictq_cond = SDL_CreateCond();

video_open(vs);
schedule_refresh(vs, 100);
vs->decode_tid = SDL_CreateThread(decode_thread, "decode_thread", vs);


if (!vs->decode_tid)
{
SDL_DestroyMutex(vs->pictq_mutex);
SDL_DestroyCond(vs->pictq_cond);
av_freep(vs);
vs = NULL;
avformat_network_deinit();
SDL_Quit();
return true;
}

event_loop(vs);

return true;
}
...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
maya8maya85 2016-08-05
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
[quote=引用 4 楼 maya8maya85 的回复:] [quote=引用 3 楼 zhao4zhong1 的回复:] http://blog.csdn.net/leixiaohua1020/article/details/42658139
赵四就喜欢发链接,实际上他都没看好帖子[/quote] 逝者难道不是有FFMPEG相关开发经验的朋友?[/quote] 做视频的谁不知道雷神。不发链接都知道。
赵4老师 2016-08-05
  • 打赏
  • 举报
回复
引用 4 楼 maya8maya85 的回复:
[quote=引用 3 楼 zhao4zhong1 的回复:] http://blog.csdn.net/leixiaohua1020/article/details/42658139
赵四就喜欢发链接,实际上他都没看好帖子[/quote] 逝者难道不是有FFMPEG相关开发经验的朋友?
maya8maya85 2016-08-05
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
http://blog.csdn.net/leixiaohua1020/article/details/42658139
赵四就喜欢发链接,实际上他都没看好帖子
maya8maya85 2016-08-04
  • 打赏
  • 举报
回复
引用 1 楼 oyljerry 的回复:
是不是所有的初始化有没有重新做
我不知道,请你看看啊
oyljerry 2016-08-04
  • 打赏
  • 举报
回复
是不是所有的初始化有没有重新做

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧