From 49993e6f9c77bf4c610b53e3abc4ce5651c7700b Mon Sep 17 00:00:00 2001 From: Comment Date: Thu, 21 Mar 2013 22:05:38 +0000 Subject: wrestling with libavcodec --- rotord/rotor.cpp | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'rotord/rotor.cpp') diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 07ea2b7..81b0716 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -307,10 +307,12 @@ bool Render_context::load_audio(const string &filename,vectornb_streams; ++i) { if (avFormat->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - // we've found a video stream! + // we've found a stream! stream = avFormat->streams[i]; break; } @@ -332,37 +334,37 @@ bool Render_context::load_audio(const string &filename,vector audioCodec(avcodec_alloc_context3(codec), [](AVCodecContext* c) { avcodec_close(c); av_free(c); }); - /* extradata??? + // extradata??? // we need to make a copy of videoStream->codec->extradata and give it to the context // make sure that this vector exists as long as the avVideoCodec exists - std::vector codecContextExtraData(stream->codec->extradata, stream->codec->extradata + stream->codec->extradata_size); - audioCodec->extradata = reinterpret_cast(codecContextExtraData.data()); + std::vector codecContextExtraData; + codecContextExtraData.assign(stream->codec->extradata, stream->codec->extradata + stream->codec->extradata_size); + + audioCodec->extradata = reinterpret_cast(codecContextExtraData.data()); audioCodec->extradata_size = codecContextExtraData.size(); // initializing the structure by opening the codec - if (avcodec_open2(avVideoCodec.get(), codec, nullptr) < 0) { + if (avcodec_open2(audioCodec.get(), codec, nullptr) < 0) { cerr <<"Rotor: Could not open codec"<< endl; return false; } - */ - //avcodec.h line 1026 + //avcodec.h line 1026 - Packet packet(avFormat.get()); - if (packet.packet.data == nullptr) { - //done - return true; - } - - cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<channels<<", sample format: "<sample_fmt<sample_rate <<", channels: "<channels<<", sample format: "<sample_fmt<index) - continue; // the packet is not about the video stream we want, let's jump again the start of the loop + continue; // the packet is not about the stream we want, let's jump again the start of the loop } while(0); + */ // allocating an AVFrame std::shared_ptr avFrame(avcodec_alloc_frame(), &av_free); @@ -401,8 +403,15 @@ bool Render_context::load_audio(const string &filename,vectorsample_fmt) * CHAR_BIT; // 16 or 32 + unsigned int numberOfChannels = stream.codecContext->channels; // 1 for mono, 2 for stereo, or more + unsigned int numberOfSamplesContainedInTheFrame = stream.frame->nb_samples * stream.codecContext->channels; + unsigned int numberOfSamplesToPlayPerSecond = stream.codecContext->sample_rate; // usually 44100 or 48000 + const void* data = stream.frame->data[0]; + */ if (processedLength < 0) { //av_free_packet(&packet); shouldn't have to because of type safe wrapper @@ -410,7 +419,7 @@ bool Render_context::load_audio(const string &filename,vector