1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-21 16:11:11 +01:00

Bug #176 - Support newer versions of FFmpeg.

Also includes Benjamin's ffmpeg-configure-v2.patch.
This commit is contained in:
lllucius
2011-04-02 02:10:50 +00:00
parent b55fb15b89
commit f50be91900
25 changed files with 1956 additions and 860 deletions

View File

@@ -103,6 +103,9 @@ public:
/// Writes metadata
bool AddTags(Tags *metadata);
/// Sets individual metadata values
void SetMetadata(Tags *tags, const char *name, const wxChar *tag);
/// Encodes audio
bool EncodeAudioFrame(int16_t *pFrame, int frameSize);
@@ -147,12 +150,8 @@ private:
AVStream * mEncAudioStream; // the output audio stream (may remain NULL)
AVCodecContext * mEncAudioCodecCtx; // the encoder for the output audio stream
uint8_t * mEncAudioEncodedBuf; // buffer to hold frames encoded by the encoder
int mEncAudioEncodedBufSiz;
#if FFMPEG_STABLE
AVFifoBuffer mEncAudioFifo; // FIFO to write incoming audio samples into
#else
AVFifoBuffer * mEncAudioFifo; // FIFO to write incoming audio samples into
#endif
int mEncAudioEncodedBufSiz;
AVFifoBuffer * mEncAudioFifo; // FIFO to write incoming audio samples into
uint8_t * mEncAudioFifoOutBuf; // buffer to read _out_ of the FIFO into
wxString mName;
@@ -179,6 +178,7 @@ ExportFFmpeg::ExportFFmpeg()
mSupportsUTF8 = true;
PickFFmpegLibs(); // DropFFmpegLibs() call is in ExportFFmpeg::Destroy()
int avfver = FFmpegLibsInst->ValidLibsLoaded() ? avformat_version() : 0;
int newfmt;
// Adds export types from the export type list
for (newfmt = 0; newfmt < FMT_LAST; newfmt++)
@@ -188,8 +188,8 @@ ExportFFmpeg::ExportFFmpeg()
if (newfmt < FMT_OTHER && FFmpegLibsInst->ValidLibsLoaded())
{
// Format/Codec support is compiled in?
AVOutputFormat *avoformat = FFmpegLibsInst->guess_format(shortname.mb_str(), NULL, NULL);
AVCodec *avcodec = FFmpegLibsInst->avcodec_find_encoder(ExportFFmpegOptions::fmts[newfmt].codecid);
AVOutputFormat *avoformat = av_guess_format(shortname.mb_str(), NULL, NULL);
AVCodec *avcodec = avcodec_find_encoder(ExportFFmpegOptions::fmts[newfmt].codecid);
if (avoformat == NULL || avcodec == NULL)
{
ExportFFmpegOptions::fmts[newfmt].compiledIn = false;
@@ -215,9 +215,18 @@ ExportFFmpeg::ExportFFmpeg()
break;
}
SetMaxChannels(ExportFFmpegOptions::fmts[newfmt].maxchannels,fmtindex);
SetCanMetaData(ExportFFmpegOptions::fmts[newfmt].canmetadata,fmtindex);
SetDescription(ExportFFmpegOptions::fmts[newfmt].description,fmtindex);
SetMaxChannels(ExportFFmpegOptions::fmts[newfmt].maxchannels,fmtindex);
SetDescription(ExportFFmpegOptions::fmts[newfmt].description,fmtindex);
int canmeta = ExportFFmpegOptions::fmts[newfmt].canmetadata;
if (canmeta && (canmeta == AV_VERSION_INT(-1,-1,-1) || canmeta <= avfver))
{
SetCanMetaData(true,fmtindex);
}
else
{
SetCanMetaData(false,fmtindex);
}
}
}
@@ -230,15 +239,6 @@ void ExportFFmpeg::Destroy()
bool ExportFFmpeg::CheckFileName(wxFileName &filename, int format)
{
bool result = true;
#if FFMPEG_STABLE
int subFormat = AdjustFormatIndex(format);
if (subFormat == FMT_AMRNB || subFormat == FMT_AMRWB)
{
wxMessageBox(_("Properly configured FFmpeg is required to proceed.\nYou can configure it at Preferences > Libraries.\n\nNote that AMR support is not available with our FFmpeg\ninstaller, but requires you compile FFmpeg yourself."), _("AMR support is not distributable"));
result = false;
}
else
#endif
if (!CheckFFmpegPresence())
{
result = false;
@@ -253,21 +253,21 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
if (!FFmpegLibsInst->ValidLibsLoaded()) return false;
FFmpegLibsInst->av_log_set_callback(av_log_wx_callback);
av_log_set_callback(av_log_wx_callback);
AVFormatParameters fpOutFile;
// See if libavformat has modules that can write our output format. If so, mEncFormatDesc
// will describe the functions used to write the format (used internally by libavformat)
// and the default video/audio codecs that the format uses.
if ((mEncFormatDesc = FFmpegLibsInst->guess_format(shortname, OSINPUT(mName), NULL)) == NULL)
if ((mEncFormatDesc = av_guess_format(shortname, OSINPUT(mName), NULL)) == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't determine format description for file \"%s\"."), mName.c_str());
return false;
}
// mEncFormatCtx is used by libavformat to carry around context data re our output file.
if ((mEncFormatCtx = FFmpegLibsInst->av_alloc_format_context()) == NULL)
if ((mEncFormatCtx = avformat_alloc_context()) == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't allocate output format context."));
return false;
@@ -278,7 +278,7 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
memcpy(mEncFormatCtx->filename, OSINPUT(mName), strlen(OSINPUT(mName))+1);
// At the moment Audacity can export only one audio stream
if ((mEncAudioStream = FFmpegLibsInst->av_new_stream(mEncFormatCtx, 1)) == NULL)
if ((mEncAudioStream = av_new_stream(mEncFormatCtx, 1)) == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't add audio stream to output file \"%s\"."), mName.c_str());
return false;
@@ -299,7 +299,7 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
// Set default parameters on the format context.
memset(&fpOutFile, 0, sizeof(AVFormatParameters));
if ((err = FFmpegLibsInst->av_set_parameters(mEncFormatCtx, &fpOutFile)) < 0)
if ((err = av_set_parameters(mEncFormatCtx, &fpOutFile)) < 0)
{
wxLogError(wxT("FFmpeg : ERROR - Can't set output parameters for output file \"%s\". Error code is %d."), mName.c_str(),err);
return false;
@@ -317,14 +317,14 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
// Add metadata BEFORE writing the header.
// At the moment that works with ffmpeg-git and ffmpeg-0.5 for MP4.
if (ExportFFmpegOptions::fmts[mSubFormat].canmetadata)
if (GetCanMetaData(mSubFormat))
{
mSupportsUTF8 = ExportFFmpegOptions::fmts[mSubFormat].canutf8;
AddTags(metadata);
}
// Write headers to the output file.
if ((err = FFmpegLibsInst->av_write_header(mEncFormatCtx)) < 0)
if ((err = av_write_header(mEncFormatCtx)) < 0)
{
wxLogError(wxT("FFmpeg : ERROR - Can't write headers to output file \"%s\". Error code is %d."), mName.c_str(),err);
@@ -349,11 +349,11 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
// Configure the audio stream's codec context.
mEncAudioCodecCtx = mEncAudioStream->codec;
FFmpegLibsInst->avcodec_get_context_defaults(mEncAudioCodecCtx);
avcodec_get_context_defaults(mEncAudioCodecCtx);
mEncAudioCodecCtx->codec_id = ExportFFmpegOptions::fmts[mSubFormat].codecid;
mEncAudioCodecCtx->codec_type = CODEC_TYPE_AUDIO;
mEncAudioCodecCtx->codec_tag = FFmpegLibsInst->av_codec_get_tag((const AVCodecTag **)mEncFormatCtx->oformat->codec_tag,mEncAudioCodecCtx->codec_id);
mEncAudioCodecCtx->codec_tag = av_codec_get_tag((const AVCodecTag **)mEncFormatCtx->oformat->codec_tag,mEncAudioCodecCtx->codec_id);
mSampleRate = (int)project->GetRate();
mEncAudioCodecCtx->global_quality = -99999; //quality mode is off by default;
@@ -386,12 +386,6 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mSampleRate = 8000;
mEncAudioCodecCtx->bit_rate = gPrefs->Read(wxT("/FileFormats/AMRNBBitRate"), 12200);
break;
#if FFMPEG_STABLE
case FMT_AMRWB:
mSampleRate = 16000;
mEncAudioCodecCtx->bit_rate = gPrefs->Read(wxT("/FileFormats/AMRWBBitRate"), 23850);
break;
#endif
case FMT_WMA2:
mEncAudioCodecCtx->bit_rate = gPrefs->Read(wxT("/FileFormats/WMABitRate"), 198000);
if (!CheckSampleRate(mSampleRate,ExportFFmpegWMAOptions::iWMASampleRates[0], ExportFFmpegWMAOptions::iWMASampleRates[4], &ExportFFmpegWMAOptions::iWMASampleRates[0]))
@@ -399,7 +393,7 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mEncAudioCodecCtx->flags2 |= CODEC_FLAG2_BIT_RESERVOIR | 0x0004;
break;
case FMT_OTHER:
strncpy(mEncAudioStream->language,gPrefs->Read(wxT("/FileFormats/FFmpegLanguage"),wxT("")).mb_str(wxConvUTF8),4);
av_metadata_set2(&mEncAudioStream->metadata, "language", gPrefs->Read(wxT("/FileFormats/FFmpegLanguage"),wxT("")).ToUTF8(), 0);
mEncAudioCodecCtx->sample_rate = gPrefs->Read(wxT("/FileFormats/FFmpegSampleRate"),(long)0);
if (mEncAudioCodecCtx->sample_rate != 0) mSampleRate = mEncAudioCodecCtx->sample_rate;
mEncAudioCodecCtx->bit_rate = gPrefs->Read(wxT("/FileFormats/FFmpegBitRate"), (long)0);
@@ -431,11 +425,6 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
if (mEncAudioCodecCtx->global_quality >= 0)
{
/* I'm not sure this is required, regardless of FFmpeg version
#if FFMPEG_STABLE
mEncAudioCodecCtx->bit_rate = 0;
#endif
*/
mEncAudioCodecCtx->flags |= CODEC_FLAG_QSCALE;
}
else mEncAudioCodecCtx->global_quality = -99999;
@@ -447,8 +436,22 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mEncAudioCodecCtx->sample_fmt = SAMPLE_FMT_S16;
//mEncAudioCodecCtx->strict_std_compliance = FF_COMPLIANCE_STRICT;
if (mEncAudioCodecCtx->codec_id == CODEC_ID_AC3)
{
// As of Jan 4, 2011, the default AC3 encoder only accept SAMPLE_FMT_FLT samples.
// But, currently, Audacity only supports SAMPLE_FMT_S16. So, for now, look for the
// "older" AC3 codec. this is not a proper solution, but will suffice until other
// encoders no longer support SAMPLE_FMT_S16.
codec = avcodec_find_encoder_by_name("ac3_fixed");
}
if (!codec)
{
codec = avcodec_find_encoder(mEncAudioCodecCtx->codec_id);
}
// Is the required audio codec compiled into libavcodec?
if ((codec = FFmpegLibsInst->avcodec_find_encoder(mEncAudioCodecCtx->codec_id)) == NULL)
if (codec == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't find audio codec 0x%x."),mEncAudioCodecCtx->codec_id);
wxMessageBox(wxString::Format(_("FFmpeg cannot find audio codec 0x%x.\nSupport for this codec is probably not compiled in."),mEncAudioCodecCtx->codec_id));
@@ -462,7 +465,7 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
}
// Open the codec.
if (FFmpegLibsInst->avcodec_open(mEncAudioCodecCtx, codec) < 0 || mEncAudioCodecCtx->frame_size == 0)
if (avcodec_open(mEncAudioCodecCtx, codec) < 0 || mEncAudioCodecCtx->frame_size == 0)
{
wxLogError(wxT("FFmpeg : ERROR - Can't open audio codec 0x%x."),mEncAudioCodecCtx->codec_id);
return false;
@@ -475,7 +478,7 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
mEncAudioEncodedBufSiz = FF_MIN_BUFFER_SIZE;
}
// Allocate a buffer for the encoder to store encoded audio frames into.
if ((mEncAudioEncodedBuf = (uint8_t*)FFmpegLibsInst->av_malloc(mEncAudioEncodedBufSiz)) == NULL)
if ((mEncAudioEncodedBuf = (uint8_t*)av_malloc(mEncAudioEncodedBufSiz)) == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't allocate buffer to hold encoded audio."));
return false;
@@ -484,14 +487,10 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
// The encoder may require a minimum number of raw audio samples for each encoding but we can't
// guarantee we'll get this minimum each time an audio frame is decoded from the input file so
// we use a FIFO to store up incoming raw samples until we have enough for one call to the codec.
#if FFMPEG_STABLE
FFmpegLibsInst->av_fifo_init(&mEncAudioFifo, 1024);
#else
mEncAudioFifo = FFmpegLibsInst->av_fifo_alloc(1024);
#endif
mEncAudioFifo = av_fifo_alloc(1024);
// Allocate a buffer to read OUT of the FIFO into. The FIFO maintains its own buffer internally.
if ((mEncAudioFifoOutBuf = (uint8_t*)FFmpegLibsInst->av_malloc(2*MAX_AUDIO_PACKET_SIZE)) == NULL)
if ((mEncAudioFifoOutBuf = (uint8_t*)av_malloc(2*MAX_AUDIO_PACKET_SIZE)) == NULL)
{
wxLogError(wxT("FFmpeg : ERROR - Can't allocate buffer to read into from audio FIFO."));
return false;
@@ -508,11 +507,7 @@ bool ExportFFmpeg::Finalize()
for (;;)
{
AVPacket pkt;
#if FFMPEG_STABLE
int nFifoBytes = FFmpegLibsInst->av_fifo_size(&mEncAudioFifo); // any bytes left in audio FIFO?
#else
int nFifoBytes = FFmpegLibsInst->av_fifo_size(mEncAudioFifo); // any bytes left in audio FIFO?
#endif
int nFifoBytes = av_fifo_size(mEncAudioFifo); // any bytes left in audio FIFO?
nEncodedBytes = 0;
int nAudioFrameSizeOut = mEncAudioCodecCtx->frame_size * mEncAudioCodecCtx->channels * sizeof(int16_t);
@@ -549,16 +544,12 @@ bool ExportFFmpeg::Finalize()
nFifoBytes, mEncAudioCodecCtx->frame_size);
// Pull the bytes out from the FIFO and feed them to the encoder.
#if FFMPEG_STABLE
if (FFmpegLibsInst->av_fifo_read(&mEncAudioFifo, mEncAudioFifoOutBuf, nFifoBytes) == 0)
#else
if (FFmpegLibsInst->av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nFifoBytes, NULL) == 0)
#endif
if (av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nFifoBytes, NULL) == 0)
{
if (mEncAudioCodecCtx->frame_size != 1)
nEncodedBytes = FFmpegLibsInst->avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, (int16_t*)mEncAudioFifoOutBuf);
nEncodedBytes = avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, (int16_t*)mEncAudioFifoOutBuf);
else
nEncodedBytes = FFmpegLibsInst->avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, nFifoBytes, (int16_t*)mEncAudioFifoOutBuf);
nEncodedBytes = avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, nFifoBytes, (int16_t*)mEncAudioFifoOutBuf);
}
mEncAudioCodecCtx->frame_size = nFrameSizeTmp; // restore the native frame size
@@ -567,13 +558,13 @@ bool ExportFFmpeg::Finalize()
// Now flush the encoder.
if (nEncodedBytes <= 0)
nEncodedBytes = FFmpegLibsInst->avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, NULL);
nEncodedBytes = avcodec_encode_audio(mEncAudioCodecCtx, mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, NULL);
if (nEncodedBytes <= 0)
break;
// Okay, we got a final encoded frame we can write to the output file.
FFmpegLibsInst->av_init_packet(&pkt);
av_init_packet(&pkt);
pkt.stream_index = mEncAudioStream->index;
pkt.data = mEncAudioEncodedBuf;
@@ -582,47 +573,44 @@ bool ExportFFmpeg::Finalize()
// Set presentation time of frame (currently in the codec's timebase) in the stream timebase.
if(mEncAudioCodecCtx->coded_frame && mEncAudioCodecCtx->coded_frame->pts != int64_t(AV_NOPTS_VALUE))
pkt.pts = FFmpegLibsInst->av_rescale_q(mEncAudioCodecCtx->coded_frame->pts, mEncAudioCodecCtx->time_base, mEncAudioStream->time_base);
pkt.pts = av_rescale_q(mEncAudioCodecCtx->coded_frame->pts, mEncAudioCodecCtx->time_base, mEncAudioStream->time_base);
if (FFmpegLibsInst->av_interleaved_write_frame(mEncFormatCtx, &pkt) != 0)
if (av_interleaved_write_frame(mEncFormatCtx, &pkt) != 0)
{
wxLogError(wxT("FFmpeg : ERROR - Couldn't write last audio frame to output file."));
break;
}
}
// Write any file trailers.
av_write_trailer(mEncFormatCtx);
// Close the codecs.
if (mEncAudioStream != NULL)
FFmpegLibsInst->avcodec_close(mEncAudioStream->codec);
// Write any file trailers.
FFmpegLibsInst->av_write_trailer(mEncFormatCtx);
avcodec_close(mEncAudioStream->codec);
for (i = 0; i < (int)mEncFormatCtx->nb_streams; i++)
{
FFmpegLibsInst->av_freep(&mEncFormatCtx->streams[i]->codec);
FFmpegLibsInst->av_freep(&mEncFormatCtx->streams[i]);
av_freep(&mEncFormatCtx->streams[i]->codec);
av_freep(&mEncFormatCtx->streams[i]);
}
// Close the output file if we created it.
if (!(mEncFormatDesc->flags & AVFMT_NOFILE))
FFmpegLibsInst->url_fclose(mEncFormatCtx->pb);
avio_close(mEncFormatCtx->pb);
// Free any buffers or structures we allocated.
FFmpegLibsInst->av_free(mEncFormatCtx);
av_free(mEncFormatCtx);
if (mEncAudioEncodedBuf != NULL)
FFmpegLibsInst->av_free(mEncAudioEncodedBuf);
av_free(mEncAudioEncodedBuf);
if (mEncAudioFifoOutBuf != NULL)
FFmpegLibsInst->av_free(mEncAudioFifoOutBuf);
av_free(mEncAudioFifoOutBuf);
#if FFMPEG_STABLE
FFmpegLibsInst->av_fifo_free(&mEncAudioFifo);
#else
FFmpegLibsInst->av_fifo_free(mEncAudioFifo);
av_fifo_free(mEncAudioFifo);
mEncAudioFifo = NULL;
#endif
return true;
}
@@ -637,32 +625,21 @@ bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, int frameSize)
nBytesToWrite = frameSize;
pRawSamples = (uint8_t*)pFrame;
#if FFMPEG_STABLE
FFmpegLibsInst->av_fifo_realloc(&mEncAudioFifo, FFmpegLibsInst->av_fifo_size(&mEncAudioFifo) + frameSize);
#else
FFmpegLibsInst->av_fifo_realloc2(mEncAudioFifo, FFmpegLibsInst->av_fifo_size(mEncAudioFifo) + frameSize);
#endif
av_fifo_realloc2(mEncAudioFifo, av_fifo_size(mEncAudioFifo) + frameSize);
// Put the raw audio samples into the FIFO.
#if FFMPEG_STABLE
ret = FFmpegLibsInst->av_fifo_generic_write(&mEncAudioFifo, pRawSamples, nBytesToWrite,NULL);
#else
ret = FFmpegLibsInst->av_fifo_generic_write(mEncAudioFifo, pRawSamples, nBytesToWrite,NULL);
#endif
ret = av_fifo_generic_write(mEncAudioFifo, pRawSamples, nBytesToWrite,NULL);
wxASSERT(ret == nBytesToWrite);
// Read raw audio samples out of the FIFO in nAudioFrameSizeOut byte-sized groups to encode.
#if FFMPEG_STABLE
while ((ret = FFmpegLibsInst->av_fifo_size(&mEncAudioFifo)) >= nAudioFrameSizeOut)
while ((ret = av_fifo_size(mEncAudioFifo)) >= nAudioFrameSizeOut)
{
ret = FFmpegLibsInst->av_fifo_read(&mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut);
#else
while ((ret = FFmpegLibsInst->av_fifo_size(mEncAudioFifo)) >= nAudioFrameSizeOut)
{
ret = FFmpegLibsInst->av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut, NULL);
#endif
FFmpegLibsInst->av_init_packet(&pkt);
ret = av_fifo_generic_read(mEncAudioFifo, mEncAudioFifoOutBuf, nAudioFrameSizeOut, NULL);
pkt.size = FFmpegLibsInst->avcodec_encode_audio(mEncAudioCodecCtx,
av_init_packet(&pkt);
pkt.size = avcodec_encode_audio(mEncAudioCodecCtx,
mEncAudioEncodedBuf, mEncAudioEncodedBufSiz, // out
(int16_t*)mEncAudioFifoOutBuf); // in
if (mEncAudioCodecCtx->frame_size == 1) { wxASSERT(pkt.size == mEncAudioEncodedBufSiz); }
@@ -674,7 +651,7 @@ bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, int frameSize)
// Rescale from the codec time_base to the AVStream time_base.
if (mEncAudioCodecCtx->coded_frame && mEncAudioCodecCtx->coded_frame->pts != int64_t(AV_NOPTS_VALUE))
pkt.pts = FFmpegLibsInst->av_rescale_q(mEncAudioCodecCtx->coded_frame->pts, mEncAudioCodecCtx->time_base, mEncAudioStream->time_base);
pkt.pts = av_rescale_q(mEncAudioCodecCtx->coded_frame->pts, mEncAudioCodecCtx->time_base, mEncAudioStream->time_base);
//wxLogDebug(wxT("FFmpeg : (%d) Writing audio frame with PTS: %lld."), mEncAudioCodecCtx->frame_number, pkt.pts);
pkt.stream_index = mEncAudioStream->index;
@@ -682,7 +659,7 @@ bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, int frameSize)
pkt.flags |= PKT_FLAG_KEY;
// Write the encoded audio frame to the output file.
if ((ret = FFmpegLibsInst->av_interleaved_write_frame(mEncFormatCtx, &pkt)) != 0)
if ((ret = av_interleaved_write_frame(mEncFormatCtx, &pkt)) != 0)
{
wxLogError(wxT("FFmpeg : ERROR - Failed to write audio frame to file."));
return false;
@@ -779,23 +756,33 @@ void AddStringTagANSI(char field[], int size, wxString value)
bool ExportFFmpeg::AddTags(Tags *tags)
{
if (tags == NULL) return false;
void (*AddStringTag)(char [], int, wxString);
if (mSupportsUTF8)
AddStringTag = AddStringTagUTF8;
else
AddStringTag = AddStringTagANSI;
AddStringTag(mEncFormatCtx->author, sizeof(mEncFormatCtx->author), tags->GetTag(TAG_ARTIST));
AddStringTag(mEncFormatCtx->album, sizeof(mEncFormatCtx->album), tags->GetTag(TAG_ALBUM));
AddStringTag(mEncFormatCtx->comment, sizeof(mEncFormatCtx->comment), tags->GetTag(TAG_COMMENTS));
AddStringTag(mEncFormatCtx->genre, sizeof(mEncFormatCtx->genre), tags->GetTag(TAG_GENRE));
AddStringTag(mEncFormatCtx->title, sizeof(mEncFormatCtx->title), tags->GetTag(TAG_TITLE));
tags->GetTag(TAG_YEAR).ToLong((long*)&mEncFormatCtx->year);
tags->GetTag(TAG_TRACK).ToLong((long*)&mEncFormatCtx->track);
if (tags == NULL)
{
return false;
}
SetMetadata(tags, "author", TAG_ARTIST);
SetMetadata(tags, "album", TAG_ALBUM);
SetMetadata(tags, "comment", TAG_COMMENTS);
SetMetadata(tags, "genre", TAG_GENRE);
SetMetadata(tags, "title", TAG_TITLE);
SetMetadata(tags, "year", TAG_YEAR);
SetMetadata(tags, "track", TAG_TRACK);
return true;
}
void ExportFFmpeg::SetMetadata(Tags *tags, const char *name, const wxChar *tag)
{
if (tags->HasTag(tag))
{
wxString value = tags->GetTag(tag);
av_metadata_set2(&mEncFormatCtx->metadata, name, mSupportsUTF8 ? value.ToUTF8() : value.mb_str(), 0);
}
}
//----------------------------------------------------------------------------
// AskResample dialog
//----------------------------------------------------------------------------
@@ -898,14 +885,6 @@ bool ExportFFmpeg::DisplayOptions(wxWindow *parent, int format)
od.ShowModal();
return true;
}
#if FFMPEG_STABLE
else if (mSubFormat == FMT_AMRWB)
{
ExportFFmpegAMRWBOptions od(parent);
od.ShowModal();
return true;
}
#endif
else if (mSubFormat == FMT_WMA2)
{
ExportFFmpegWMAOptions od(parent);

View File

@@ -26,11 +26,6 @@
*//***************************************************************//**
\class ExportFFmpegAMRWBOptions
\brief Options dialog for FFmpeg exporting of AMRWB format.
*//***************************************************************//**
\class ExportFFmpegWMAOptions
\brief Options dialog for FFmpeg exporting of WMA format.
@@ -161,7 +156,7 @@ ExportFFmpegAC3Options::ExportFFmpegAC3Options(wxWindow *parent)
for (unsigned int i=0; i < (sizeof(iAC3BitRates)/sizeof(int)); i++)
{
mBitRateNames.Add(wxString::Format(wxT("%i"),iAC3BitRates[i]/1000));
mBitRateNames.Add(wxString::Format(_("%i kbps"),iAC3BitRates[i]/1000));
mBitRateLabels.Add(iAC3BitRates[i]);
}
@@ -284,7 +279,7 @@ ExportFFmpegAMRNBOptions::ExportFFmpegAMRNBOptions(wxWindow *parent)
for (unsigned int i=0; i < (sizeof(iAMRNBBitRate)/sizeof(int)); i++)
{
mBitRateNames.Add(wxString::Format(wxT("%i"),iAMRNBBitRate[i]/1000));
mBitRateNames.Add(wxString::Format(_("%.2f kbps"),(float)iAMRNBBitRate[i]/1000));
mBitRateLabels.Add(iAMRNBBitRate[i]);
}
@@ -332,75 +327,6 @@ void ExportFFmpegAMRNBOptions::OnOK(wxCommandEvent& event)
return;
}
//----------------------------------------------------------------------------
// ExportFFmpegAMRWBOptions Class
//----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ExportFFmpegAMRWBOptions, wxDialog)
EVT_BUTTON(wxID_OK,ExportFFmpegAMRWBOptions::OnOK)
END_EVENT_TABLE()
/// Bit Rates supported by libAMR-WB encoder
/// Sample Rate is always 16 kHz
int ExportFFmpegAMRWBOptions::iAMRWBBitRate[] =
{ 6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850 };
ExportFFmpegAMRWBOptions::ExportFFmpegAMRWBOptions(wxWindow *parent)
: wxDialog(parent, wxID_ANY,
wxString(_("Specify AMR-WB Options")))
{
ShuttleGui S(this, eIsCreatingFromPrefs);
for (unsigned int i=0; i < (sizeof(iAMRWBBitRate)/sizeof(int)); i++)
{
mBitRateNames.Add(wxString::Format(wxT("%i"),iAMRWBBitRate[i]/1000));
mBitRateLabels.Add(iAMRWBBitRate[i]);
}
PopulateOrExchange(S);
}
///
///
void ExportFFmpegAMRWBOptions::PopulateOrExchange(ShuttleGui & S)
{
S.StartHorizontalLay(wxEXPAND, 0);
{
S.StartStatic(_("AMR-WB Export Setup"), 0);
{
S.StartTwoColumn();
{
S.TieChoice(_("Bit Rate:"), wxT("/FileFormats/AMRWBBitRate"),
23850, mBitRateNames, mBitRateLabels);
}
S.EndTwoColumn();
}
S.EndStatic();
}
S.EndHorizontalLay();
S.AddStandardButtons();
Layout();
Fit();
SetMinSize(GetSize());
Center();
return;
}
///
///
void ExportFFmpegAMRWBOptions::OnOK(wxCommandEvent& event)
{
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);
EndModal(wxID_OK);
return;
}
//----------------------------------------------------------------------------
// ExportFFmpegWMAOptions Class
//----------------------------------------------------------------------------
@@ -414,8 +340,7 @@ const int ExportFFmpegWMAOptions::iWMASampleRates[] =
/// Bit Rates supported by WMA encoder. Setting bit rate to other values will not result in different file size.
const int ExportFFmpegWMAOptions::iWMABitRate[] =
{ 24634, 26012, 27734, 29457, 31524, 33764, 36348, 39448, 42894, 47028, 52024,
58225, 65805, 75624, 88716, 106976, 134539, 180189, 271835, 546598 };
{ 24000, 32000, 40000, 48000, 64000, 80000, 96000, 128000, 160000, 192000, 256000, 320000 };
ExportFFmpegWMAOptions::ExportFFmpegWMAOptions(wxWindow *parent)
@@ -426,7 +351,7 @@ ExportFFmpegWMAOptions::ExportFFmpegWMAOptions(wxWindow *parent)
for (unsigned int i=0; i < (sizeof(iWMABitRate)/sizeof(int)); i++)
{
mBitRateNames.Add(wxString::Format(wxT("%i"),iWMABitRate[i]/1000));
mBitRateNames.Add(wxString::Format(wxT("%i kbps"),iWMABitRate[i]/1000));
mBitRateLabels.Add(iWMABitRate[i]);
}
@@ -444,7 +369,7 @@ void ExportFFmpegWMAOptions::PopulateOrExchange(ShuttleGui & S)
S.StartTwoColumn();
{
S.TieChoice(_("Bit Rate:"), wxT("/FileFormats/WMABitRate"),
180189, mBitRateNames, mBitRateLabels);
96000, mBitRateNames, mBitRateLabels);
}
S.EndTwoColumn();
}
@@ -1185,14 +1110,11 @@ const wxChar *ExportFFmpegOptions::iAACProfileNames[] = {
/// List of export types
ExposedFormat ExportFFmpegOptions::fmts[] =
{
{FMT_M4A, wxT("M4A"), wxT("m4a"), wxT("ipod"), 48, true ,true ,_("M4A (AAC) Files (FFmpeg)"), CODEC_ID_AAC, true},
{FMT_AC3, wxT("AC3"), wxT("ac3"), wxT("ac3"), 7, false,false,_("AC3 Files (FFmpeg)"), CODEC_ID_AC3, true},
{FMT_AMRNB, wxT("AMRNB"), wxT("amr"), wxT("amr"), 1, false,false,_("AMR (narrow band) Files (FFmpeg)"), CODEC_ID_AMR_NB, true},
#if FFMPEG_STABLE
{FMT_AMRWB, wxT("AMRWB"), wxT("amr"), wxT("amr"), 1, false,false,_("AMR (wide band) Files (FFmpeg)"), CODEC_ID_AMR_WB, true},
#endif
{FMT_WMA2, wxT("WMA"), wxT("wma"), wxT("asf"), 2, false,false,_("WMA (version 2) Files (FFmpeg)"), CODEC_ID_WMAV2, true},
{FMT_OTHER, wxT("FFMPEG"), wxT(""), wxT(""), 255, true ,true ,_("Custom FFmpeg Export"), CODEC_ID_NONE, true}
{FMT_M4A, wxT("M4A"), wxT("m4a"), wxT("ipod"), 48, AV_VERSION_INT(-1,-1,-1), true, _("M4A (AAC) Files (FFmpeg)"), CODEC_ID_AAC, true},
{FMT_AC3, wxT("AC3"), wxT("ac3"), wxT("ac3"), 7, AV_VERSION_INT(0,0,0), false, _("AC3 Files (FFmpeg)"), CODEC_ID_AC3, true},
{FMT_AMRNB, wxT("AMRNB"), wxT("amr"), wxT("amr"), 1, AV_VERSION_INT(0,0,0), false, _("AMR (narrow band) Files (FFmpeg)"), CODEC_ID_AMR_NB, true},
{FMT_WMA2, wxT("WMA"), wxT("wma"), wxT("asf"), 2, AV_VERSION_INT(52,53,0), false, _("WMA (version 2) Files (FFmpeg)"), CODEC_ID_WMAV2, true},
{FMT_OTHER, wxT("FFMPEG"), wxT(""), wxT(""), 255, AV_VERSION_INT(-1,-1,-1), true, _("Custom FFmpeg Export"), CODEC_ID_NONE, true}
};
/// Sample rates supported by AAC encoder (must end with zero-element)
@@ -1329,7 +1251,7 @@ ExportFFmpegOptions::ExportFFmpegOptions(wxWindow *parent)
DoOnFormatList();
//Select the codec that was selected last time this dialog was closed
AVCodec *codec = FFmpegLibsInst->avcodec_find_encoder((CodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"),(long)CODEC_ID_NONE));
AVCodec *codec = avcodec_find_encoder((CodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"),(long)CODEC_ID_NONE));
if (codec != NULL) mCodecList->Select(mCodecList->FindString(wxString::FromUTF8(codec->name)));
DoOnCodecList();
}
@@ -1342,7 +1264,7 @@ void ExportFFmpegOptions::FetchFormatList()
{
// Enumerate all output formats
AVOutputFormat *ofmt = NULL;
while ((ofmt = FFmpegLibsInst->av_oformat_next(ofmt)))
while ((ofmt = av_oformat_next(ofmt)))
{
// Any audio-capable format has default audio codec.
// If it doesn't, then it doesn't supports any audio codecs
@@ -1363,7 +1285,7 @@ void ExportFFmpegOptions::FetchCodecList()
{
// Enumerate all codecs
AVCodec *codec = NULL;
while ((codec = FFmpegLibsInst->av_codec_next(codec)))
while ((codec = av_codec_next(codec)))
{
// We're only interested in audio and only in encoders
if (codec->type == CODEC_TYPE_AUDIO && codec->encode)
@@ -1604,7 +1526,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
break;
}
// Find the codec, that is claimed to be compatible
AVCodec *codec = FFmpegLibsInst->avcodec_find_encoder(CompatibilityList[i].codec);
AVCodec *codec = avcodec_find_encoder(CompatibilityList[i].codec);
// If it exists, is audio and has encoder
if (codec != NULL && (codec->type == CODEC_TYPE_AUDIO) && codec->encode)
{
@@ -1619,7 +1541,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
if (found == 2)
{
AVCodec *codec = NULL;
while ((codec = FFmpegLibsInst->av_codec_next(codec)))
while ((codec = av_codec_next(codec)))
{
if (codec->type == CODEC_TYPE_AUDIO && codec->encode)
{
@@ -1637,10 +1559,10 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
else if (found == 0)
{
wxCharBuffer buf = str.ToUTF8();
AVOutputFormat *format = FFmpegLibsInst->guess_format(buf,NULL,NULL);
AVOutputFormat *format = av_guess_format(buf,NULL,NULL);
if (format != NULL)
{
AVCodec *codec = FFmpegLibsInst->avcodec_find_encoder(format->audio_codec);
AVCodec *codec = avcodec_find_encoder(format->audio_codec);
if (codec != NULL && (codec->type == CODEC_TYPE_AUDIO) && codec->encode)
{
if ((id >= 0) && codec->id == id) index = mShownCodecNames.GetCount();
@@ -1674,7 +1596,7 @@ int ExportFFmpegOptions::FetchCompatibleFormatList(CodecID id, wxString *selfmt)
if ((selfmt != NULL) && (selfmt->Cmp(CompatibilityList[i].fmt) == 0)) index = mShownFormatNames.GetCount();
FromList.Add(CompatibilityList[i].fmt);
mShownFormatNames.Add(CompatibilityList[i].fmt);
AVOutputFormat *tofmt = FFmpegLibsInst->guess_format(wxString(CompatibilityList[i].fmt).ToUTF8(),NULL,NULL);
AVOutputFormat *tofmt = av_guess_format(wxString(CompatibilityList[i].fmt).ToUTF8(),NULL,NULL);
if (tofmt != NULL) mShownFormatLongNames.Add(wxString::Format(wxT("%s - %s"),CompatibilityList[i].fmt,wxString::FromUTF8(tofmt->long_name).c_str()));
}
}
@@ -1694,7 +1616,7 @@ int ExportFFmpegOptions::FetchCompatibleFormatList(CodecID id, wxString *selfmt)
if (found)
{
// Find all formats which have this codec as default and which are not in the list yet and add them too
while ((ofmt = FFmpegLibsInst->av_oformat_next(ofmt)))
while ((ofmt = av_oformat_next(ofmt)))
{
if (ofmt->audio_codec == id)
{
@@ -1879,7 +1801,7 @@ void ExportFFmpegOptions::DoOnFormatList()
wxString *selcdclong = NULL;
FindSelectedCodec(&selcdc, &selcdclong);
AVOutputFormat *fmt = FFmpegLibsInst->guess_format(selfmt->ToUTF8(),NULL,NULL);
AVOutputFormat *fmt = av_guess_format(selfmt->ToUTF8(),NULL,NULL);
if (fmt == NULL)
{
//This shouldn't really happen
@@ -1891,7 +1813,7 @@ void ExportFFmpegOptions::DoOnFormatList()
if (selcdc != NULL)
{
AVCodec *cdc = FFmpegLibsInst->avcodec_find_encoder_by_name(selcdc->ToUTF8());
AVCodec *cdc = avcodec_find_encoder_by_name(selcdc->ToUTF8());
if (cdc != NULL)
{
selcdcid = cdc->id;
@@ -1902,7 +1824,7 @@ void ExportFFmpegOptions::DoOnFormatList()
AVCodec *cdc = NULL;
if (selcdc != NULL)
cdc = FFmpegLibsInst->avcodec_find_encoder_by_name(selcdc->ToUTF8());
cdc = avcodec_find_encoder_by_name(selcdc->ToUTF8());
EnableDisableControls(cdc, selfmt);
Layout();
Fit();
@@ -1923,7 +1845,7 @@ void ExportFFmpegOptions::DoOnCodecList()
wxString *selfmtlong = NULL;
FindSelectedFormat(&selfmt, &selfmtlong);
AVCodec *cdc = FFmpegLibsInst->avcodec_find_encoder_by_name(selcdc->ToUTF8());
AVCodec *cdc = avcodec_find_encoder_by_name(selcdc->ToUTF8());
if (cdc == NULL)
{
//This shouldn't really happen
@@ -1934,7 +1856,7 @@ void ExportFFmpegOptions::DoOnCodecList()
if (selfmt != NULL)
{
AVOutputFormat *fmt = FFmpegLibsInst->guess_format(selfmt->ToUTF8(),NULL,NULL);
AVOutputFormat *fmt = av_guess_format(selfmt->ToUTF8(),NULL,NULL);
if (fmt == NULL)
{
selfmt = NULL;
@@ -1971,7 +1893,7 @@ void ExportFFmpegOptions::OnOK(wxCommandEvent& event)
{
int selcdc = mCodecList->GetSelection();
int selfmt = mFormatList->GetSelection();
if (selcdc > -1) gPrefs->Write(wxT("/FileFormats/FFmpegCodec"),(long)FFmpegLibsInst->avcodec_find_encoder_by_name(mCodecList->GetString(selcdc).ToUTF8())->id);
if (selcdc > -1) gPrefs->Write(wxT("/FileFormats/FFmpegCodec"),(long)avcodec_find_encoder_by_name(mCodecList->GetString(selcdc).ToUTF8())->id);
if (selfmt > -1) gPrefs->Write(wxT("/FileFormats/FFmpegFormat"),mFormatList->GetString(selfmt));
ShuttleGui S(this, eIsSavingToPrefs);
PopulateOrExchange(S);

View File

@@ -27,9 +27,6 @@ enum FFmpegExposedFormat
FMT_M4A,
FMT_AC3,
FMT_AMRNB,
#if FFMPEG_STABLE
FMT_AMRWB,
#endif
FMT_WMA2,
FMT_OTHER,
FMT_LAST
@@ -43,7 +40,7 @@ struct ExposedFormat
const wxChar *extension; //!< default extension for this format. More extensions may be added later via AddExtension.
const wxChar *shortname; //!< used to guess the format
int maxchannels; //!< how much channels this format could handle
bool canmetadata; //!< true if format supports metadata, false otherwise
int canmetadata; //!< !=0 if format supports metadata, -1 any avformat version, otherwise version support added
bool canutf8; //!< true if format supports metadata in UTF-8, false otherwise
const wxChar *description; //!< format description (will be shown in export dialog)
CodecID codecid; //!< codec ID (see libavcodec/avcodec.h)
@@ -123,28 +120,6 @@ private:
DECLARE_EVENT_TABLE()
};
class ExportFFmpegAMRWBOptions : public wxDialog
{
public:
ExportFFmpegAMRWBOptions(wxWindow *parent);
void PopulateOrExchange(ShuttleGui & S);
void OnOK(wxCommandEvent& event);
static int iAMRWBBitRate[];
private:
wxArrayString mBitRateNames;
wxArrayInt mBitRateLabels;
wxChoice *mBitRateChoice;
wxButton *mOk;
int mBitRateFromChoice;
DECLARE_EVENT_TABLE()
};
class ExportFFmpegWMAOptions : public wxDialog
{
public: