ffmpeg+SDL2实现的视频播放器(windows版)


博客:http://blog.csdn.net/i_scream_/article/details/52760033 中的代码。 测试环境:win10 64bit+ vs2010/vs2015
资源截图
代码片段和文件信息
/*=========================================================================
* Copyright(C)2016 Chudai.
*
* File name    : audio.c
* Version      : v1.0.0
* Author       : 初代
* Date         : 2016/10/06
* Description  :
* Function list: 1.
*                2.
*                3.
* History      :
*=========================================================================*/
#include “stdafx.h“
/*-----------------------------------------------------------*
 * 头文件                                                    *
 *-----------------------------------------------------------*/
#define __STDC_CONSTANT_MACROS      //ffmpeg要求

#include “player.h“
#include “audio.h“

/*======================================================================
* Author     (作者): i.sshe
* Date       (日期): 2016/10/06
* Others     (其他): 准备audio
*=======================================================================*/
int prepare_audio(PlayerState *ps)
{

ps->paudio_stream = ps->pformat_ctx->streams[ps->audio_stream_index];
ps->paudio_codec_ctx =  ps->paudio_stream->codec;
ps->paudio_codec = avcodec_find_decoder(ps->paudio_codec_ctx->codec_id);
if (ps->paudio_codec == NULL)
    {
         fprintf(ERR_STREAM “Couldn‘t find audio decoder!!!!!!!
“);
         return -1;
    }
//初始化AVCondecContext,以及进行一些处理工作。
avcodec_open2(ps->paudio_codec_ctx ps->paudio_codec NULL);

    return 0;
}


/*======================================================================
* Author     (作者): i.sshe
* Date       (日期): 2016/10/06
* Others     (其他): 播放声音
*=======================================================================*/
int play_audio(PlayerState *ps)
{
    SDL_AudioSpec      wanted_spec;
//    SDL_AudioSpec      spec;
    wanted_spec.freq      = ps->paudio_codec_ctx->sample_rate;
    wanted_spec.format    = AUDIO_S16SYS;
    wanted_spec.channels  = ps->paudio_codec_ctx->channels;
    wanted_spec.silence   = 0;
    wanted_spec.samples   = 1024;     //
    wanted_spec.callback  = audio_callback;
    wanted_spec.userdata  = ps; // ps->paudio_codec_ctx;

    //打开音频设备
    //运行callback
    if (SDL_OpenAudio(&wanted_spec NULL) < 0)
    {
        fprintf(ERR_STREAM “Couldn‘t open audio device
“);
        return -1;
    }

    SDL_PauseAudio(0);

    return 0;
}


/*======================================================================
* Author     (作者): i.sshe
* Date       (日期): 2016/10/06
* Others     (其他): 音频回调函数,打开设备的时候会开线程调用
*=======================================================================*/
void audio_callback(void *userdata uint8_t *stream int len)
{
    PlayerState *ps = (PlayerState *)userdata;
    int  send_data_size = 0;
    int  audio_size = 0;

if (ps->quit == 1)
{
exit(-1);
}


    SDL_memset(stream 0 len);


    while(len > 0)
    {
         if (ps->audio_buf_index >= ps->audio_buf_size)
         {
             //数据已经全部发送,再去取
             audio_size 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-10-09 12:26  player_v1.4.1
     目录           0  2016-10-09 12:25  player_v1.4.1Debug
     文件       41984  2016-10-09 12:26  player_v1.4.1Debugplayer_v1.4.1.exe
     文件      449304  2016-10-09 12:26  player_v1.4.1Debugplayer_v1.4.1.ilk
     文件      715776  2016-10-09 12:26  player_v1.4.1Debugplayer_v1.4.1.pdb
     目录           0  2016-10-09 12:15  player_v1.4.1ipch
     目录           0  2016-10-09 12:22  player_v1.4.1ipchplayer_v1.4.1-a4430eb1
     文件     2359296  2016-10-09 12:22  player_v1.4.1ipchplayer_v1.4.1-a4430eb1player_v1.4.ipch
     目录           0  2016-10-09 12:25  player_v1.4.1player_v1.4.1
     目录           0  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debug
     文件      107066  2016-10-09 12:26  player_v1.4.1player_v1.4.1DebugCL.read.1.tlog
     文件        4470  2016-10-09 12:26  player_v1.4.1player_v1.4.1DebugCL.write.1.tlog
     文件       33202  2016-10-09 12:25  player_v1.4.1player_v1.4.1Debugaudio.obj
     文件        5566  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugcl.command.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink-cvtres.read.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink-cvtres.write.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.11936-cvtres.read.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.11936-cvtres.write.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.11936.read.1.tlog
     文件           2  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.11936.write.1.tlog
     文件        3388  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.command.1.tlog
     文件        7492  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.read.1.tlog
     文件        2244  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debuglink.write.1.tlog
     文件         498  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugmt.command.1.tlog
     文件         498  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugmt.read.1.tlog
     文件         498  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugmt.write.1.tlog
     文件       26011  2016-10-09 12:25  player_v1.4.1player_v1.4.1Debugpacket_queue.obj
     文件         406  2016-10-09 12:25  player_v1.4.1player_v1.4.1Debugplayer_v1.4.1.exe.embed.manifest
     文件         472  2016-10-09 12:25  player_v1.4.1player_v1.4.1Debugplayer_v1.4.1.exe.embed.manifest.res
     文件         381  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugplayer_v1.4.1.exe.intermediate.manifest
     文件          93  2016-10-09 12:26  player_v1.4.1player_v1.4.1Debugplayer_v1.4.1.lastbuildstate
............此处省略215个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)