簡體   English   中英

Sox和FFMPEG解碼

[英]Sox and FFMPEG decode

您好,請幫助襪子。 我的想法是通過ffmpeg解碼音頻部分,然后通過sox處理它。 即僅使用FFMPEG進行解碼。 這是我剩下的:


   av_register_all();

   char *str = "/home/user/spoon_-_got_nuffin.mp3";
printf("hdhd2");

   if(av_open_input_file(&pFormatCtx, str, NULL, 0, NULL)!=0)
     return -150; // Couldn't open file
printf("hdhd3");
   // Retrieve stream information
   if(av_find_stream_info(pFormatCtx)nb_streams; i++) {

     if(audioStream streams[audioStream]->codec;

   ReSampleContext* rsc = av_audio_resample_init(
   1, aCodecCtx->channels,
   8000, aCodecCtx->sample_rate,
      av_get_sample_fmt("u8"), aCodecCtx->sample_fmt,
      1, 1, 1, 1);


   aCodec = avcodec_find_decoder(aCodecCtx->codec_id);


   if(!aCodec) {
     fprintf(stderr, "Unsupported codec!\n");
     return -45;
   }

   avcodec_open(aCodecCtx, aCodec);
   c=avcodec_alloc_context();

   int source_sample_size = av_get_bits_per_sample_format(av_get_sample_fmt("u8"));
     int number = 0;

    int decoded = 0;

     while (av_read_frame(pFormatCtx, &packet)>= 0) {
      if (aCodecCtx->codec_type == AVMEDIA_TYPE_AUDIO) {

                     int data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE * 2;
                     int size=packet.size;


                     while(size > 0) {

                             int len = avcodec_decode_audio3(aCodecCtx, (int32_t)pAudioBuffer, &data_size, &packet);

                          int argc;
                          char * args[3];
                          sox_effects_chain_t * chain;
                          sox_effect_t * e;



                          size_t number_read;

                          /* All libSoX applications must start by initialising the SoX library */
                          sox_init();

                          /* Open the input file (with default parameters) */
                          in = sox_open_mem_read(pAudioBuffer, data_size, NULL, NULL, NULL);


                             decoded +=data_size;
                             size -= data_size;
                             number++;
                             }




      }


  }

in = sox_open_mem_read(pAudioBuffer,data_size,NULL,NULL,NULL)中的函數; 給出一個錯誤:

格式:無法確定文件類型''

我該怎么辦? 如何解決問題? 請幫忙!!!

如您所見, sox_open_mem_read的定義如下:

SOX_API sox_open_mem_read(
    LSX_PARAM_IN_BYTECOUNT(buffer_size) void  * buffer,     /* Pointer to audio data buffer (required). */
    size_t                                      buffer_size,/* Number of bytes to read from audio data buffer. */
    LSX_PARAM_IN_OPT sox_signalinfo_t   const * signal,     /* Information already known about audio stream, or NULL if none. */
    LSX_PARAM_IN_OPT sox_encodinginfo_t const * encoding,   /* Information already known about sample encoding, or NULL if none. */
    LSX_PARAM_IN_OPT_Z char             const * filetype);  /* Previously-determined file type, or NULL to auto-detect. */

您可能需要指定filetype ,以指示要libsox使用的編解碼器。 視情況而定,某些編解碼器是無頭的,而libsox無法預測它將是哪種格式。

否則,您可能無法正確解碼數據(如果您希望某些數據帶有標頭),導致libsox混亂。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM