huihui 6 years ago
parent
commit
6d762464e4
3 changed files with 20 additions and 12 deletions
  1. BIN
      bin32/VideoRecorder.exe
  2. 19 10
      src/video/getvideothread.cpp
  3. 1 2
      src/video/getvideothread.h

BIN
bin32/VideoRecorder.exe


+ 19 - 10
src/video/getvideothread.cpp

@@ -209,11 +209,6 @@ ErroCode GetVideoThread::init(QString videoDevName, bool useVideo, QString audio
         //输入的声道布局
         int in_ch_layout;
 
-        //输出的声道布局
-        int out_ch_layout = av_get_default_channel_layout(audio_tgt_channels); ///AV_CH_LAYOUT_STEREO
-
-        out_ch_layout &= ~AV_CH_LAYOUT_STEREO;
-
         /// 新版ffmpeg编码aac只支持输入AV_SAMPLE_FMT_FLTP的数据
         /// 强制将音频重采样成44100 双声道  AV_SAMPLE_FMT_FLTP
         //重采样设置选项----------------
@@ -230,10 +225,13 @@ ErroCode GetVideoThread::init(QString videoDevName, bool useVideo, QString audio
         out_sample_rate = 44100;
         //输出的声道布局
 
+        //输出的声道布局
         out_ch_layout = AV_CH_LAYOUT_STEREO;
-
         audio_tgt_channels = av_get_channel_layout_nb_channels(out_ch_layout);
-        out_ch_layout = av_get_default_channel_layout(audio_tgt_channels); ///AV_CH_LAYOUT_STEREO
+
+//        //输出的声道布局
+//        out_ch_layout = av_get_default_channel_layout(audio_tgt_channels); ///AV_CH_LAYOUT_STEREO
+//        out_ch_layout &= ~AV_CH_LAYOUT_STEREO;
 
         if (in_ch_layout <= 0)
         {
@@ -467,10 +465,21 @@ void GetVideoThread::run()
                 {
                     aFrame_ReSample = av_frame_alloc();
 
-                    aFrame_ReSample->nb_samples = av_rescale_rnd(swr_get_delay(swrCtx, out_sample_rate) + aFrame->nb_samples,
-                                out_sample_rate, in_sample_rate, AV_ROUND_UP);
+                    int nb_samples = av_rescale_rnd(swr_get_delay(swrCtx, out_sample_rate) + aFrame->nb_samples, out_sample_rate, in_sample_rate, AV_ROUND_UP);
+
+//                    av_samples_fill_arrays(aFrame_ReSample->data, aFrame_ReSample->linesize, audio_buf_resample, audio_tgt_channels, aFrame_ReSample->nb_samples, out_sample_fmt, 0);
+
+                    aFrame_ReSample->format = out_sample_fmt;
+                    aFrame_ReSample->channel_layout = out_ch_layout;
+                    aFrame_ReSample->sample_rate = out_sample_rate;
+                    aFrame_ReSample->nb_samples = nb_samples;
 
-                    av_samples_fill_arrays(aFrame_ReSample->data, aFrame_ReSample->linesize, audio_buf_resample, audio_tgt_channels, aFrame_ReSample->nb_samples, out_sample_fmt, 0);
+                    ret = av_frame_get_buffer(aFrame_ReSample, 0);
+                    if (ret < 0)
+                    {
+                        fprintf(stderr, "Error allocating an audio buffer\n");
+                        exit(1);
+                    }
 
                 }
 

+ 1 - 2
src/video/getvideothread.h

@@ -79,8 +79,7 @@ private:
     int in_sample_rate;//输入的采样率
     int out_sample_rate;//输出的采样率
     int audio_tgt_channels; ///av_get_channel_layout_nb_channels(out_ch_layout);
-    DECLARE_ALIGNED(16, uint8_t, audio_buf_resample) [AVCODEC_MAX_AUDIO_FRAME_SIZE * 4];
-
+    int out_ch_layout;
 
     int pic_x;
     int pic_y;