首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sox和FFMPEG解码

Sox和FFMPEG解码
EN

Stack Overflow用户
提问于 2011-06-23 16:20:41
回答 1查看 1.9K关注 0票数 0

你好,请帮帮我索克斯。我的想法是通过ffmpeg解码音频部分,然后通过sox进行处理。Ie解码只使用FFMPEG。下面是我剩下的内容:

代码语言:javascript
复制
   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++;
                             }




      }


  }

function in = sox_open_mem_read (pAudioBuffer,data_size,NULL,NULL,NULL);返回错误:

格式:无法确定文件的类型‘’

我该怎么办?如何解决这个问题?请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2011-07-19 00:51:40

正如您所看到的,sox_open_mem_read是这样定义的:

代码语言:javascript
复制
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混淆。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6451180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档