中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

seo網(wǎng)站關(guān)鍵詞優(yōu)化軟件邁步者seo

seo網(wǎng)站關(guān)鍵詞優(yōu)化軟件,邁步者seo,營(yíng)銷(xiāo)管理軟件,網(wǎng)站的構(gòu)造1.簡(jiǎn)介 這里引入FFmpeg庫(kù),獲取音頻流數(shù)據(jù),然后通過(guò)FFmpeg將視頻流解碼成pcm原始數(shù)據(jù),再將pcm數(shù)據(jù)送入到SDL庫(kù)中實(shí)現(xiàn)音頻播放。 2.FFmpeg的操作流程 注冊(cè)API:av_register_all()構(gòu)建輸入AVFormatContext上下文:avform…

1.簡(jiǎn)介

這里引入FFmpeg庫(kù),獲取音頻流數(shù)據(jù),然后通過(guò)FFmpeg將視頻流解碼成pcm原始數(shù)據(jù),再將pcm數(shù)據(jù)送入到SDL庫(kù)中實(shí)現(xiàn)音頻播放。

2.FFmpeg的操作流程

  • 注冊(cè)API:av_register_all()
  • 構(gòu)建輸入AVFormatContext上下文:avformat_open_input()
  • 查找音視頻流信息:avformat_find_stream_info()
  • 查找解碼器:avcodec_find_decoder()
  • 打開(kāi)解碼器:avcodec_open2()
  • 然后通過(guò)while循環(huán),不停的讀取數(shù)據(jù):av_read_frame()
  • 幀解碼:avcodec_send_packet()和avcodec_receive_frame()
  • 重采樣:swr_convert()

3.SDL音頻播放流程

SDL播放音頻的流程如下:

  • 初始化音頻子系統(tǒng):SDL_Init()。
  • 設(shè)置音頻參數(shù):SDL_AudioSpec。
  • 設(shè)置回調(diào)函數(shù):SDL_AudioCallback。
  • 打開(kāi)音頻設(shè)備:SDL_OpenAudio()。
  • 打開(kāi)pcm文件,讀取數(shù)據(jù)。
  • 開(kāi)始播放:SDL_PauseAudio()。

4.示例

#include <stdio.h>
#include <SDL.h>
#include <memory>extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libswresample/swresample.h"
};static  Uint8  *audio_chunk;
static  Uint32  audio_len;
static  Uint8  *audio_pos;void  fill_audio(void *udata, Uint8 *stream, int len)
{//SDL 2.0SDL_memset(stream, 0, len);if (audio_len == 0)		/*  Only  play  if  we  have  data  left  */return;len = (len > audio_len ? audio_len : len);	/*  Mix  as  much  data  as  possible  */SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME/2);audio_pos += len;audio_len -= len;	
}AVFrame *recv(AVCodecContext *codecCtx)
{if (!codecCtx){return NULL;}AVFrame *frame = av_frame_alloc();int ret = avcodec_receive_frame(codecCtx, frame);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){av_frame_free(&frame);return NULL;}else if (ret < 0){av_frame_free(&frame);return NULL;}return frame;
}#undef main
int main(int argc, char* argv[])
{av_register_all();///ffmpegavformat_network_init();AVFormatContext* pFormatCtx = NULL;const char* inputUrl = "./2.mp4";///打開(kāi)輸入的流int ret = avformat_open_input(&pFormatCtx, inputUrl, NULL, NULL);if (ret != 0){printf("Couldn't open input stream.\n");return -1;}//查找流信息if (avformat_find_stream_info(pFormatCtx, NULL) < 0){printf("Couldn't find stream information.\n");return -1;}//找到音頻流索引int audio_index = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);AVStream* st = pFormatCtx->streams[audio_index];AVCodec* codec = nullptr;//找到解碼器codec = avcodec_find_decoder(st->codecpar->codec_id);if (!codec){fprintf(stderr, "Codec not found\n");return -1;}//申請(qǐng)AVCodecContextAVCodecContext* pCodecCtx = avcodec_alloc_context3(codec);if (!pCodecCtx){return -1;}avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[audio_index]->codecpar);//打開(kāi)解碼器if ((ret = avcodec_open2(pCodecCtx, codec, NULL) < 0)){return -1;}AVPacket* pkt = av_packet_alloc();//------------SDL----------------//Output Info-----------------------------printf("---------------- File Information ---------------\n");av_dump_format(pFormatCtx, 0, inputUrl, 0);printf("-------------------------------------------------\n");SwrContext *swrContext = swr_alloc();if (!swrContext){return -1;}swrContext = swr_alloc_set_opts(NULL,													//ctxAV_CH_LAYOUT_STEREO,																	//輸出channel布局AV_SAMPLE_FMT_S16,																		 //輸出的采樣格式44100,																									//采樣率av_get_default_channel_layout(pCodecCtx->channels),						//輸入channel布局pCodecCtx->sample_fmt,																	//輸入的采樣格式pCodecCtx->sample_rate,																	//輸入的采樣率0, NULL);// 初始化重采樣上下文if (swr_init(swrContext) < 0){swr_free(&swrContext);return -1;}if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)){printf("Could not initialize SDL - %s\n", SDL_GetError());return -1;}//SDL_AudioSpecSDL_AudioSpec wanted_spec;wanted_spec.freq = 44100;wanted_spec.format = AUDIO_S16SYS;wanted_spec.channels = 2;wanted_spec.silence = 0;wanted_spec.samples = 1024;wanted_spec.callback = fill_audio;wanted_spec.userdata = pCodecCtx;if (SDL_OpenAudio(&wanted_spec, NULL) < 0){printf("can't open audio.\n");return -1;}//PlaySDL_PauseAudio(0);// 分配輸出音頻數(shù)據(jù)uint8_t	 *out_buffer = nullptr;while (av_read_frame(pFormatCtx, pkt) >= 0){if (pkt->stream_index == audio_index){//一次send 多次recvint ret = avcodec_send_packet(pCodecCtx, pkt);if (ret < 0)continue;//釋放資源av_packet_unref(pkt);while (1){AVFrame *frame = recv(pCodecCtx);if (!frame)break;//輸入的樣本數(shù)int in_nb_samples = frame->nb_samples;//1024int out_linesize;int dst_nb_samples = av_rescale_rnd(in_nb_samples, 44100, frame->sample_rate, AV_ROUND_UP);//輸出的樣本數(shù)int out_buffer_size = av_samples_get_buffer_size(NULL, 2, dst_nb_samples, AV_SAMPLE_FMT_S16, 0);if(!out_buffer)out_buffer = (uint8_t *)av_malloc(out_buffer_size);//返回每個(gè)通道輸出的樣本數(shù),錯(cuò)誤時(shí)為負(fù)值int sampleCount = swr_convert(swrContext, &out_buffer, dst_nb_samples,(const uint8_t**)frame->data, in_nb_samples);if (sampleCount <= 0){av_frame_free(&frame);break;}int outSize = sampleCount * 2 * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);while (audio_len > 0)//Wait until finishSDL_Delay(1);//Set audio buffer (PCM data)audio_chunk = (Uint8 *)out_buffer;//Audio buffer lengthaudio_len = outSize;audio_pos = audio_chunk;av_frame_free(&frame);}}else{//釋放資源av_packet_unref(pkt);}}//--------------av_free(out_buffer);av_packet_free(&pkt);swr_close(swrContext);swr_free(&swrContext);avcodec_close(pCodecCtx);avcodec_free_context(&pCodecCtx);avformat_close_input(&pFormatCtx);SDL_CloseAudio();SDL_Quit();
}

?5.相關(guān)推薦

[總結(jié)]FFMPEG視音頻編解碼零基礎(chǔ)學(xué)習(xí)方法_零基礎(chǔ)ffmpeg 雷霄驊-CSDN博客?

FFmpeg 音頻解碼(秒懂)-CSDN博客

SDL2 播放音頻數(shù)據(jù)(PCM)-CSDN博客

SDL2 消息循環(huán)和事件響應(yīng)-CSDN博客?

SDL2 播放視頻文件(MP4)-CSDN博客?

http://www.risenshineclean.com/news/5724.html

相關(guān)文章:

  • wordpress旅游插件廣州網(wǎng)站優(yōu)化公司
  • 南京網(wǎng)站設(shè)計(jì)費(fèi)用推廣網(wǎng)絡(luò)公司
  • 山東省建設(shè)管理局網(wǎng)站seo優(yōu)化人員
  • 做bt搜索網(wǎng)站歐洲網(wǎng)站服務(wù)器
  • 深圳做網(wǎng)站那里好徐匯網(wǎng)站建設(shè)
  • 網(wǎng)站美工設(shè)計(jì)培訓(xùn)學(xué)校國(guó)際軍事新聞最新消息
  • 政務(wù)網(wǎng)站建設(shè)索引成都seo招聘信息
  • 怎么在百度自己創(chuàng)網(wǎng)站百度網(wǎng)站域名注冊(cè)
  • 臺(tái)州網(wǎng)站建設(shè)系統(tǒng)開(kāi)發(fā)一個(gè)網(wǎng)站需要哪些技術(shù)
  • 寧波響應(yīng)式網(wǎng)站制作西安競(jìng)價(jià)托管代運(yùn)營(yíng)
  • 河南單位網(wǎng)站建設(shè)網(wǎng)站收錄量
  • 東莞seo建站優(yōu)化工具注冊(cè)網(wǎng)站平臺(tái)要多少錢(qián)
  • 網(wǎng)站做友鏈盈利網(wǎng)絡(luò)營(yíng)銷(xiāo)課程主要講什么內(nèi)容
  • 網(wǎng)站建設(shè)的需求和目的運(yùn)營(yíng)和營(yíng)銷(xiāo)的區(qū)別和聯(lián)系
  • 專(zhuān)業(yè)網(wǎng)站設(shè)計(jì)招聘信息如何在百度上投放廣告
  • 系統(tǒng)測(cè)試包括哪些內(nèi)容魔貝課凡seo課程好嗎
  • 營(yíng)銷(xiāo)網(wǎng)絡(luò)是什么意思企業(yè)網(wǎng)站優(yōu)化軟件
  • 現(xiàn)在做網(wǎng)站一般做多寬怎么做微信推廣和宣傳
  • 網(wǎng)站系統(tǒng)問(wèn)題解決措施重慶seo網(wǎng)站建設(shè)
  • 網(wǎng)站開(kāi)發(fā)軟件培訓(xùn)企業(yè)網(wǎng)站建設(shè)方案論文
  • 域名和網(wǎng)站名不一樣百度推廣登錄平臺(tái)網(wǎng)址
  • 太湖云建站網(wǎng)站建設(shè)推廣普通話(huà)手抄報(bào)內(nèi)容50字
  • 做公司網(wǎng)站有什么亮點(diǎn)seo基礎(chǔ)培訓(xùn)
  • java高端網(wǎng)站建設(shè)成都網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃
  • 門(mén)戶(hù)網(wǎng)站建設(shè)自查報(bào)告seo日常工作內(nèi)容
  • 做網(wǎng)站 公司有哪些互聯(lián)網(wǎng)營(yíng)銷(xiāo)平臺(tái)
  • 網(wǎng)站建設(shè)的運(yùn)用場(chǎng)景百度推廣管理平臺(tái)登錄
  • 企業(yè)做網(wǎng)站樂(lè)云seo快速上線(xiàn)2345網(wǎng)址導(dǎo)航桌面版
  • 洪湖自己的網(wǎng)站seo大牛
  • 官網(wǎng)站超鏈接怎么做優(yōu)就業(yè)seo