使用ffmpeg播放视频文件的过程

本文中,红色字体部分是涉及到的ffmpeg部分,其他函数是视频显示部分或者内部封装函数(文中没有给出实现)。

本文的主要目的,在于记录播放视频文件时用到的ffmpeg函数,及其用法。

typedef struct _zl_player_param
{
HWND hwnd; //display window handle
char filename[256]; //add for file playback
} zl_player_param;

typedef struct _zl_player
{
//ffmpeg struct
AVCodecContext   * pCodecCtx;
AVCodec   * pCodec;
struct SwsContext    * pSwsCtx;
zl_video_context   * pVideoCtx; //for video display

//add for file playback
AVFormatContext *pFormatCtx;
int                                    videoStream; //视频流编号

//player state
int abort; //abort marker
} zl_player;

初始化播放器/
zl_player * zl_init_file_player(zl_player_param *param)
{
int ret = 0;

if (param == NULL)
{
return NULL;
}

zl_player *player = (zl_player *)malloc(sizeof(zl_player));
if (NULL == player)
{
printf("ERROR(%d): <zl_player> create player failed!\n", ERROR_MALLOC_PLAYER_SPACE);
}
memset(player, 0, sizeof(zl_player));

//register ffmpeg codec
av_register_all();
if ( avformat_open_input(&player->pFormatCtx, param->filename, NULL, NULL) != 0)//avformat_open_input
{
printf("ERROR(%d): <zl_player> avformat_open_input error!\n", ERROR_MALLOC_PLAYER_SPACE);
return NULL;
}
if ( avformat_find_stream_info(player->pFormatCtx, NULL) < 0)
{
printf("ERROR(%d): <zl_player> avformat_find_stream_info error!\n", ERROR_MALLOC_PLAYER_SPACE);
return NULL;
}

av_dump_format(player->pFormatCtx, 0, param->filename, FALSE);

//现在 pFormatCtx->streams 中已经有所有流了,因此现在我们遍历它找到第一条视频流
player->videoStream = -1;
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值