最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

windows?使用ffmpeg?.a靜態(tài)庫(kù)讀取Wav音頻并保存PCM的方法

 更新時(shí)間:2024年02月28日 09:12:48   作者:qiufeng_xinqing  
這篇文章主要介紹了windows?使用ffmpeg?.a靜態(tài)庫(kù)讀取Wav音頻并保存PCM,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

ffmpeg讀取Wav音頻并保存PCM(源代碼保存成 c/c++ 文件需要與編譯命令一致):

// test_ffmpeg.cpp : 此文件包含 "main" 函數(shù)。程序執(zhí)行將在此處開始并結(jié)束。
//
//#include <iostream>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
//#pragma comment(lib, "libavdevice.a")
//#pragma comment(lib, "libavformat.a")
//#pragma comment(lib, "libavutil.a")
//#pragma comment(lib, "libavcodec.a")
//#pragma comment(lib, "libavfilter.a")
//#pragma comment(lib, "libswresample.a")
//#pragma comment(lib, "libswscale.a")
int main(int arvc, char*argv[]) {
    //av_register_all();
    printf("start...\n");
    AVFormatContext* formatCtx = NULL;
    const AVInputFormat* inputFmt = av_find_input_format(arvc > 1 ? argv[1] : "FLAC");
	int ret = 0;
	printf("format name: %s, long name; %s\n", inputFmt->name, inputFmt->long_name);
    // 打開輸入流
    if ((ret = avformat_open_input(&formatCtx, "D:\\project\\ffmpeg-6.1.1\\test_in.wav", inputFmt, NULL)) != 0) {
        printf("Unable to open input stream: %s\n", av_err2str(ret));
        return -1;
    }
    // 查找音頻流信息
    if (avformat_find_stream_info(formatCtx, NULL) < 0) {
        printf("Unable to find audio stream information: %s\n", av_err2str(ret));
        return -1;
    }
    // 尋找第一個(gè)音頻流索引
    int audioStreamIndex = av_find_best_stream(formatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
    if (audioStreamIndex < 0) {
        printf("Unable to find audio stream: %s\n", av_err2str(ret));
        return -1;
    }
    //const AVCodecContext* codecCtx = formatCtx->streams[audioStreamIndex]->codec;
    AVCodecContext* pCodecCtx = avcodec_alloc_context3(NULL);
    if (pCodecCtx == NULL)
    {
        printf("Could not allocate AVCodecContext: %s\n", av_err2str(ret));
        return -1;
    }
    avcodec_parameters_to_context(pCodecCtx, formatCtx->streams[audioStreamIndex]->codecpar);
    // 打開解碼器
    const AVCodec* codec = avcodec_find_decoder(pCodecCtx->codec_id);
    if (avcodec_open2(pCodecCtx, codec, NULL) < 0) {
        printf("Unable to open decoder: %s\n", av_err2str(ret));
        return -1;
    }
    // 創(chuàng)建輸出文件
    FILE* outputFile = fopen("output.pcm", "wb");
    AVPacket packet;
	printf("start read frame...\n");
    while ((ret = av_read_frame(formatCtx, &packet)) == 0) {
        // 如果數(shù)據(jù)包是音頻數(shù)據(jù)
        if (packet.stream_index == audioStreamIndex) {
            AVFrame* frame = av_frame_alloc();
            int gotFrame = 0;
			printf("read frame...index %d\n", audioStreamIndex);
            // 解碼音頻幀
            //avcodec_decode_audio4(pCodecCtx, frame, &gotFrame, &packet);
            if (avcodec_send_packet(pCodecCtx, &packet) < 0
                || (gotFrame = avcodec_receive_frame(pCodecCtx, frame)) < 0) {
                return -1;
            }
			printf("read frame...gotFrame = %d, frame size %d, frame pointer 0x%x\n", (ret), frame->linesize[0], frame->data[0]);
            if (gotFrame == 0) {
                // 處理解碼后的音頻數(shù)據(jù),例如寫入文件等
                fwrite(frame->data[0], 1, frame->linesize[0], outputFile);
            }
            av_frame_free(&frame);
        }
        //av_free_packet(&packet);
        av_packet_unref(&packet);
    }
	printf("read frame end. ret = %s\n", av_err2str(ret));
    fclose(outputFile);
    avformat_close_input(&formatCtx);
    return 0;
}
// 運(yùn)行程序: Ctrl + F5 或調(diào)試 >“開始執(zhí)行(不調(diào)試)”菜單
// 調(diào)試程序: F5 或調(diào)試 >“開始調(diào)試”菜單
// 入門使用技巧: 
//   1. 使用解決方案資源管理器窗口添加/管理文件
//   2. 使用團(tuán)隊(duì)資源管理器窗口連接到源代碼管理
//   3. 使用輸出窗口查看生成輸出和其他消息
//   4. 使用錯(cuò)誤列表窗口查看錯(cuò)誤
//   5. 轉(zhuǎn)到“項(xiàng)目”>“添加新項(xiàng)”以創(chuàng)建新的代碼文件,或轉(zhuǎn)到“項(xiàng)目”>“添加現(xiàn)有項(xiàng)”以將現(xiàn)有代碼文件添加到項(xiàng)目
//   6. 將來,若要再次打開此項(xiàng)目,請(qǐng)轉(zhuǎn)到“文件”>“打開”>“項(xiàng)目”并選擇 .sln 文件

編譯命令:

gcc -c test.c -o test.o -I./ffmpeg-bin/include 
gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -Wl,--nxcompat,--dynamicbase -Wl,--high-entropy-va -Wl,--as-needed -Wl,--warn-common -Wl,-rpath-link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil  -Wl,--image-base,0x140000000 -o test_g test.o -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil  -lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi -lgdi32 -lm -latomic -lvfw32 -lm -latomic -lm -latomic -lz -lsecur32 -lws2_32 -liconv -lm -latomic -lmfuuid -lole32 -lstrmiids -lole32 -luser32 -lz -lm -latomic -lm -latomic -lm -luser32 -lbcrypt -latomic  -lole32 -lpsapi -lshell32
strip -o test_1.exe test_g.exe
# 使用upx壓縮應(yīng)用(需要windows終端執(zhí)行)
upx.exe -9 -o test.exe test_1.exe
rm -rf test_g.exe test_1.exe
./test.exe

到此這篇關(guān)于windows 使用ffmpeg .a靜態(tài)庫(kù)讀取Wav音頻并保存PCM的方法的文章就介紹到這了,更多相關(guān)windows 使用ffmpeg .a靜態(tài)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • windows下vscode環(huán)境c++利用matplotlibcpp繪圖

    windows下vscode環(huán)境c++利用matplotlibcpp繪圖

    本文主要介紹了windows下vscode環(huán)境c++利用matplotlibcpp繪圖,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • 從匯編看c++中變量類型的深入分析

    從匯編看c++中變量類型的深入分析

    本篇文章是對(duì)c++中的變量類型進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下
    2013-05-05
  • 詳解C/C++性能優(yōu)化背后的方法論TMAM

    詳解C/C++性能優(yōu)化背后的方法論TMAM

    開發(fā)過程中我們多少都會(huì)關(guān)注服務(wù)的性能,然而性能優(yōu)化是相對(duì)比較困難,往往需要多輪優(yōu)化、測(cè)試,屬于費(fèi)時(shí)費(fèi)力,有時(shí)候還未必有好的效果。但是如果有較好的性能優(yōu)化方法指導(dǎo)、工具輔助分析可以幫助我們快速發(fā)現(xiàn)性能瓶頸所在,針對(duì)性地進(jìn)行優(yōu)化,可以事半功倍
    2021-06-06
  • wxWidgets自定義按鈕的方法

    wxWidgets自定義按鈕的方法

    這篇文章主要為大家詳細(xì)介紹了wxWidgets自定義按鈕的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C++ HLSL實(shí)現(xiàn)簡(jiǎn)單的圖像處理功能

    C++ HLSL實(shí)現(xiàn)簡(jiǎn)單的圖像處理功能

    本文主要介紹了HLSL實(shí)現(xiàn)簡(jiǎn)單的圖像處理功能的方法,具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • C++中的類型查詢之探索typeid和type_info(推薦)

    C++中的類型查詢之探索typeid和type_info(推薦)

    C++ 是一種靜態(tài)類型語言,這意味著每個(gè)變量的類型在編譯時(shí)就已經(jīng)確定,在這篇技術(shù)分享中,我們將探討 C++ 中的 typeid 和 type_info,以及如何使用它們來獲取類型信息,需要的朋友可以參考下
    2024-05-05
  • VScode配置C++運(yùn)行環(huán)境的完整步驟

    VScode配置C++運(yùn)行環(huán)境的完整步驟

    這篇文章主要給大家介紹了關(guān)于VScode配置C++運(yùn)行環(huán)境的完整步驟,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 詳解C++模板編程中typename用法

    詳解C++模板編程中typename用法

    typename在C++類模板或者函數(shù)模板中經(jīng)常使用的關(guān)鍵字,此時(shí)作用和class相同,只是定義模板參數(shù),下面通過例子給大家介紹c++模板typename的具體用法,一起看看吧
    2021-07-07
  • C++基礎(chǔ)入門教程(六):為什么創(chuàng)建類的時(shí)候要用new?

    C++基礎(chǔ)入門教程(六):為什么創(chuàng)建類的時(shí)候要用new?

    這篇文章主要介紹了C++基礎(chǔ)入門教程(六):為什么創(chuàng)建類的時(shí)候要用new?本文講解了使用new創(chuàng)建動(dòng)態(tài)結(jié)構(gòu)體、為什么要有new、自動(dòng)存儲(chǔ)(自動(dòng)變量、局部變量)、動(dòng)態(tài)存儲(chǔ)、vector和array等內(nèi)容,需要的朋友可以參考下
    2014-11-11
  • EasyC++?右值引用

    EasyC++?右值引用

    這篇文章主要介紹了C++?右值引用,右值引用指的是以引用傳遞(而非值傳遞)的方式使用?C++?右值,下面文章將對(duì)此詳細(xì)介紹,需要的朋友可以參考一下,希望對(duì)你有所幫助
    2021-12-12

最新評(píng)論

贡嘎县| 湘潭县| 民勤县| 水富县| 安阳市| 张家港市| 宣威市| 光山县| 玉林市| 晋州市| 云浮市| 两当县| 徐汇区| 格尔木市| 磐石市| 商丘市| 昌图县| 保康县| 汉寿县| 蓝山县| 上蔡县| 巴彦淖尔市| 西丰县| 资阳市| 瑞昌市| 琼中| 甘肃省| 弥渡县| 鹤岗市| 汾西县| 隆子县| 鸡泽县| 揭阳市| 文安县| 布尔津县| 通州市| 潼南县| 孟津县| 凤庆县| 清水河县| 平顶山市|