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

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

網(wǎng)站郵件發(fā)送功能怎么做查網(wǎng)站流量的網(wǎng)址

網(wǎng)站郵件發(fā)送功能怎么做,查網(wǎng)站流量的網(wǎng)址,番禺建設(shè)網(wǎng)站策劃,免費(fèi)素材網(wǎng)圖片文章目錄 概要整體架構(gòu)流程技術(shù)細(xì)節(jié) 概要 本文介紹使用 FFmpeg,將MP3或WAV文件解碼成PCM文件的方法。 整體架構(gòu)流程 首先,使用的 FFmpeg 庫要支持 MP3/WAV 解碼功能,即編譯的時(shí)候要加上(編譯 FFmpeg 庫可以參考:Win…

文章目錄

    • 概要
    • 整體架構(gòu)流程
    • 技術(shù)細(xì)節(jié)

概要

本文介紹使用 FFmpeg,將MP3或WAV文件解碼成PCM文件的方法。

整體架構(gòu)流程

首先,使用的 FFmpeg 庫要支持 MP3/WAV 解碼功能,即編譯的時(shí)候要加上(編譯 FFmpeg 庫可以參考:Windows編譯和使用ffmpeg):

--enable-decoder=mp3float --enable-decoder=pcm_s16le --enable-demuxer=mp3 --enable-demuxer=wav

下面的函數(shù)就是利用 FFmpeg 接口,實(shí)現(xiàn)將 MP3 或 WAV 文件解碼成PCM文件:

#ifdef __cplusplus
extern "C" {
#endif
#include "libavutil/imgutils.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
#ifndef __linux__
#include "libswscale/swscale.h"
#endif
#include "libavutil/opt.h"
#ifdef __cplusplus
}
#endif#pragma comment(lib, "libavcodec.a")
#pragma comment(lib, "libavformat.a")
#pragma comment(lib, "libavutil.a")
#pragma comment(lib, "libswresample.a")int DecodedAudioFile(const char *pFileName) {FILE *pFile = fopen("tmp.pcm", "wb");  // 輸出文件AVFormatContext *pFormatCtx;AVCodecContext *pCodecCtx;AVCodec *pCodec;AVPacket *packet;AVFrame *pFrame;struct SwrContext *au_convert_ctx = NULL;av_register_all();avformat_network_init();pFormatCtx = avformat_alloc_context();if (avformat_open_input(&pFormatCtx, pFileName, NULL, NULL) != 0) {OutputDebugStringA("Couldn't open input stream.\n");return -1;}if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {OutputDebugStringA("Couldn't find stream information.\n");return -1;}av_dump_format(pFormatCtx, 0, pFileName, false);// Find the first audio streamint audioStream = -1;for (int i = 0; i < pFormatCtx->nb_streams; i++) {if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {audioStream = i;break;}}if (audioStream == -1) {OutputDebugStringA("Didn't find a audio stream.\n");return -1;}// Get a pointer to the codec context for the audio streampCodecCtx = pFormatCtx->streams[audioStream]->codec;// Find the decoder for the audio streampCodec = avcodec_find_decoder(pCodecCtx->codec_id);if (pCodec == NULL) {OutputDebugStringA("Codec not found.\n");return -1;}// Open codecif (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {OutputDebugStringA("Could not open codec.\n");return -1;}int64_t in_channel_layout = av_get_default_channel_layout(pCodecCtx->channels);packet = (AVPacket*)av_malloc(sizeof(AVPacket));av_init_packet(packet);// Out Audio Paramuint64_t out_channel_layout = in_channel_layout;int out_nb_samples = pCodecCtx->frame_size;AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16;int out_sample_rate = pCodecCtx->sample_rate;int out_channels = pCodecCtx->channels;// Out Buffer Sizeint out_buffer_size = av_samples_get_buffer_size(NULL, out_channels, out_nb_samples, out_sample_fmt, 1);uint8_t *out_buffer = (uint8_t*)av_malloc(MAX_AUDIO_FRAME_SIZE * 2);pFrame = av_frame_alloc();// 如果輸入文件格式不是AV_SAMPLE_FMT_S16才需要if (pCodecCtx->sample_fmt != AV_SAMPLE_FMT_S16) {au_convert_ctx = swr_alloc();au_convert_ctx = swr_alloc_set_opts(au_convert_ctx, out_channel_layout, out_sample_fmt, out_sample_rate,in_channel_layout, pCodecCtx->sample_fmt, pCodecCtx->sample_rate, 0, NULL);swr_init(au_convert_ctx);}while (av_read_frame(pFormatCtx, packet) >= 0) {if (packet->stream_index == audioStream) {int got_picture;int ret = avcodec_decode_audio4(pCodecCtx, pFrame, &got_picture, packet);if (ret < 0) {OutputDebugStringA("Error in decoding audio frame.\n");return -1;}if (got_picture > 0) {if (au_convert_ctx) {  // MP3文件格式通常是AV_SAMPLE_FMT_FLTP,要重采樣、格式轉(zhuǎn)換等swr_convert(au_convert_ctx, &out_buffer, MAX_AUDIO_FRAME_SIZE, (const uint8_t**)pFrame->data, pFrame->nb_samples);// Write PCMfwrite(out_buffer, 1, out_buffer_size, pFile);} else {  // WAV文件格式通常是AV_SAMPLE_FMT_S16,與輸出文件一致,直接保存fwrite(pFrame->data[0], 1, pFrame->nb_samples * pCodecCtx->channels * 2, pFile);}}}av_free_packet(packet);}swr_free(&au_convert_ctx);fclose(pFile);av_free(out_buffer);avcodec_close(pCodecCtx);avformat_close_input(&pFormatCtx);return 0;
}int main() {DecodedAudioFile("test.mp3");DecodedAudioFile("test.wav");return 0;
}

技術(shù)細(xì)節(jié)

WAV 文件通常是未壓縮的 PCM 音頻,解碼的步驟與壓縮格式(如 MP3)有所不同。在解碼 WAV 文件時(shí),解碼器可能會直接輸出 PCM 數(shù)據(jù),而不是像 MP3 那樣的壓縮數(shù)據(jù)。對于 WAV 文件,如果格式是 AV_SAMPLE_FMT_S16,則不需要使用 swr_convert,因?yàn)橐纛l數(shù)據(jù)已經(jīng)是 PCM 格式,可以直接寫入文件。例如上述代碼中,對文件格式的檢查:

// ...
// 如果輸入文件格式不是AV_SAMPLE_FMT_S16才需要
if (pCodecCtx->sample_fmt != AV_SAMPLE_FMT_S16) {au_convert_ctx = swr_alloc();au_convert_ctx = swr_alloc_set_opts(au_convert_ctx, out_channel_layout, out_sample_fmt, out_sample_rate,in_channel_layout, pCodecCtx->sample_fmt, pCodecCtx->sample_rate, 0, NULL);swr_init(au_convert_ctx);
}
// ...
if (au_convert_ctx) {  // MP3文件格式通常是AV_SAMPLE_FMT_FLTP,要重采樣、格式轉(zhuǎn)換等swr_convert(au_convert_ctx, &out_buffer, MAX_AUDIO_FRAME_SIZE, (const uint8_t**)pFrame->data, pFrame->nb_samples);// Write PCMfwrite(out_buffer, 1, out_buffer_size, pFile);
} else {  // WAV文件格式通常是AV_SAMPLE_FMT_S16,與輸出文件一致,直接保存fwrite(pFrame->data[0], 1, pFrame->nb_samples * pCodecCtx->channels * 2, pFile);
}
// ...
http://www.risenshineclean.com/news/35229.html

相關(guān)文章:

  • 秒火食品代理網(wǎng)seo扣費(fèi)系統(tǒng)
  • 動態(tài)網(wǎng)站開發(fā)從入門到實(shí)踐今日要聞新聞
  • 怎么樣通過做網(wǎng)站賺錢嗎百度搜索推廣是什么
  • 專業(yè)邯鄲網(wǎng)站建設(shè)百度識圖軟件
  • 網(wǎng)站模版怎么做網(wǎng)絡(luò)營銷軟文范例500
  • 網(wǎng)絡(luò)推廣加盟項(xiàng)目怎么給網(wǎng)站做優(yōu)化
  • 手機(jī)怎么做三個(gè)視頻網(wǎng)站淘寶代運(yùn)營公司十大排名
  • 購物商城論文關(guān)鍵詞優(yōu)化的策略
  • 在深圳做網(wǎng)站多少錢谷歌seo軟件
  • 廣州天河區(qū)小學(xué)排名上海seo網(wǎng)站策劃
  • 網(wǎng)絡(luò)營銷網(wǎng)站建設(shè)實(shí)訓(xùn)百度大全下載
  • 對網(wǎng)站建設(shè)過程seo關(guān)鍵詞排名技巧
  • 貴陽網(wǎng)站建設(shè)專家it培訓(xùn)學(xué)校
  • 黑馬程序員培訓(xùn)靠譜嗎seo搜索引擎的優(yōu)化
  • 南寧網(wǎng)站設(shè)計(jì)企業(yè)qq一年多少費(fèi)用
  • 山西省住房建設(shè)廳網(wǎng)站首頁太原seo網(wǎng)站優(yōu)化
  • 設(shè)計(jì)工作室網(wǎng)站首頁線下營銷推廣方式有哪些
  • 中間商網(wǎng)站怎么做市場調(diào)研報(bào)告包括哪些內(nèi)容
  • 西安旅游攻略2天自由行攻略seo每日一貼
  • 那些網(wǎng)站可做代購博為峰軟件測試培訓(xùn)學(xué)費(fèi)
  • 淘寶聯(lián)盟建網(wǎng)站網(wǎng)站推廣優(yōu)化公司
  • 網(wǎng)站建設(shè)維護(hù)多少錢企業(yè)建站公司
  • wordpress彈出廣告seo搜索引擎優(yōu)化工程師招聘
  • 怎么做阿里媽媽推廣網(wǎng)站怎么做信息流廣告代理商
  • 網(wǎng)站建設(shè) 010東莞網(wǎng)絡(luò)營銷優(yōu)化
  • 株洲網(wǎng)紅網(wǎng)站優(yōu)化怎么操作
  • 濟(jì)南做網(wǎng)站最好的公司鎮(zhèn)江網(wǎng)站制作公司
  • 昆明學(xué)校網(wǎng)站建設(shè)室內(nèi)設(shè)計(jì)培訓(xùn)
  • 中山網(wǎng)站建設(shè)技術(shù)如何做seo優(yōu)化
  • 網(wǎng)站 設(shè)計(jì) 分辨率萬網(wǎng)域名注冊信息查詢