[libav-bugs] [Bug 911] Document better that avresample_open() requires a channel layout.

bugzilla at libav.org bugzilla at libav.org
Sat Nov 7 20:35:16 CET 2015


https://bugzilla.libav.org/show_bug.cgi?id=911

--- Comment #3 from kc <tjosko at yahoo.com> ---
(In reply to lu_zero at gentoo.org from comment #2)
> avplay seems to play it just fine and avconv can transcode it.
> 
> I guess we should document better what to do in those cases.
> 
> @kc can you share a code snippet of what you are doing?

it's roughly this (some non libav code removed):

// init
avformat_open_input(&container,input_filename,NULL,NULL)
avformat_find_stream_info(container, NULL)

int i; for(i=0;i<container->nb_streams;i++){
 if(container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){
ffmstream_id=i; break; } }
 if(ffmstream_id==-1){ ffm_die("EOF code: Could not find Audio Stream\n");
return; }

 metadata=container->metadata;
 metadataS=container->streams[i]->metadata;

 ctx=container->streams[ffmstream_id]->codec;
 codec=avcodec_find_decoder(ctx->codec_id);
 if(codec==NULL){ ffm_die("EOF code: cannot find codec\n"); return; }
 if(avcodec_open2(ctx,codec,NULL)<0){ ffm_die("EOF code: Codec cannot be
found\n"); return; }

 av_init_packet(&packet); ffmframe=avcodec_alloc_frame();

// playing loop
 while(ffmstate==3 && container && av_read_frame(container,&packet)>=0)
 {

  if(packet.stream_index==ffmstream_id){
   avcodec_decode_audio4(ctx,ffmframe,&frameFinished,&packet); // len=
   len=av_samples_get_buffer_size(&plane_size, ctx->channels,
    ffmframe->nb_samples, ctx->sample_fmt, 1);

   if(ctx->sample_rate!=old_rate || ctx->channel_layout!=old_chan ||
ctx->sample_fmt!=old_sfmt)
    { old_rate=ctx->sample_rate; old_chan=ctx->channel_layout;
old_sfmt=ctx->sample_fmt;
     avresample_close(ffmarc);

// following was a test if i can just force channel layout (as the test file
was just regular stereo)
if(0)if(ctx->channel_layout==0) {
 snprintf(lmsg, 127, "ffm_play: ctx->channel_layout==0, ctx->channels==%d",
ctx->channels);
 dlog(9, lmsg);
 if(ctx->channels==2) ctx->channel_layout=AV_CH_LAYOUT_STEREO;
 else if(ctx->channels==1)
 ctx->channel_layout=AV_CH_LAYOUT_MONO;
}

     // init resampler
     av_opt_set_int(ffmarc, "in_channel_layout",  ctx->channel_layout, 0);
     av_opt_set_int(ffmarc, "in_sample_fmt",      ctx->sample_fmt, 0);
     av_opt_set_int(ffmarc, "in_sample_rate",     ctx->sample_rate, 0);
     av_opt_set_int(ffmarc, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
     av_opt_set_int(ffmarc, "out_sample_fmt",     AV_SAMPLE_FMT_S16, 0);
     av_opt_set_int(ffmarc, "out_sample_rate",    44100, 0);
//     av_opt_set_int(ffmarc, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
     int ave=avresample_open(ffmarc);
     if(ave<0) {
      dlog(9,"ffm_play: avresample_open failed");
      do_resample=0;
      goto ERR;
     }
     if(old_rate!=44100 || old_chan!=AV_CH_LAYOUT_STEREO ||
old_sfmt!=AV_SAMPLE_FMT_S16) do_resample=-1; else do_resample=0;
    }
   if(do_resample) {
     int cb=0;
     cb=avresample_convert(ffmarc, (uint8_t **)buf, 0, ffmframe->nb_samples,
      ffmframe->extended_data, ffmframe->nb_samples*2*2, ffmframe->nb_samples);
     adev_out(buf, cb, sformat.channels, sfmt);
    } else adev_out((char *)ffmframe->extended_data, ffmframe->nb_samples,
ctx->channels, sfmt);
   }
  }
ERR:
  av_free_packet(&packet);
  ffmi++; ffm_check_input();
 }

 adev_close();
 ffm_die("EOF code: finished decoding\n");

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libav.org/pipermail/libav-bugs/attachments/20151107/b37904bb/attachment.html>


More information about the libav-bugs mailing list