mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-29 06:59:27 +02:00
Make audacity build with ffmpeg HEAD
This still depends on internal API And is missing planar Audio support, so not all formats work also the fixed size audio buffer has to be removed Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Benjamin Drung <bdrung@debian.org>
This commit is contained in:
parent
54cca1deda
commit
f8be1f9668
@ -186,9 +186,9 @@ static int ufile_open(URLContext *h, const char *filename, int flags)
|
||||
//
|
||||
// Since Audacity doesn't use any other open flags (there aren't any others defined
|
||||
// anyway), making equality tests works for older and new FFmpeg headers.
|
||||
if (flags == URL_RDWR) {
|
||||
if (flags == (AVIO_FLAG_READ | AVIO_FLAG_WRITE)) {
|
||||
mode = wxFile::read_write;
|
||||
} else if (flags == URL_WRONLY) {
|
||||
} else if (flags == AVIO_FLAG_WRITE) {
|
||||
mode = wxFile::write;
|
||||
} else {
|
||||
mode = wxFile::read;
|
||||
@ -259,6 +259,7 @@ static int ufile_close(URLContext *h)
|
||||
URLProtocol ufile_protocol = {
|
||||
UFILE_PROTOCOL,
|
||||
ufile_open,
|
||||
NULL,
|
||||
ufile_read,
|
||||
ufile_write,
|
||||
ufile_seek,
|
||||
@ -276,15 +277,15 @@ int ufile_fopen(AVIOContext **s, const wxString & name, int flags)
|
||||
// filename. We convert the name to UTF8 here and it will be converted back
|
||||
// to original encoding in ufile_open(). This allows us to support Unicode
|
||||
// filenames even though FFmpeg does not.
|
||||
err = url_open(&h, (const char *) url.ToUTF8(), flags);
|
||||
err = ffurl_open(&h, (const char *) url.ToUTF8(), flags, NULL, NULL);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Associate the file with a context
|
||||
err = url_fdopen(s, h);
|
||||
err = ffio_fdopen(s, h);
|
||||
if (err < 0) {
|
||||
url_close(h);
|
||||
ffurl_close(h);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -325,7 +326,7 @@ int ufile_fopen_input(AVFormatContext **ic_ptr, wxString & name)
|
||||
}
|
||||
|
||||
// Open the file to prepare for probing
|
||||
if ((err = ufile_fopen(&pb, name, URL_RDONLY)) < 0) {
|
||||
if ((err = ufile_fopen(&pb, name, AVIO_FLAG_READ)) < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -389,8 +390,11 @@ int ufile_fopen_input(AVFormatContext **ic_ptr, wxString & name)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
*ic_ptr = avformat_alloc_context();
|
||||
(*ic_ptr)->pb = pb;
|
||||
|
||||
// And finally, attempt to associate an input stream with the file
|
||||
err = av_open_input_stream(ic_ptr, pb, filename, fmt, NULL);
|
||||
err = avformat_open_input(ic_ptr, filename, fmt, NULL);
|
||||
if (err) {
|
||||
goto fail;
|
||||
}
|
||||
@ -477,7 +481,7 @@ int import_ffmpeg_decode_frame(streamContext *sc, bool flushing)
|
||||
sc->m_samplefmt = sc->m_codecCtx->sample_fmt;
|
||||
sc->m_samplesize = av_get_bits_per_sample_format(sc->m_samplefmt) / 8;
|
||||
|
||||
unsigned int newsize = FFMAX(sc->m_pkt.size * sc->m_samplesize, AVCODEC_MAX_AUDIO_FRAME_SIZE);
|
||||
unsigned int newsize = FFMAX(sc->m_pkt.size * sc->m_samplesize, 192000); //FIXME
|
||||
// Reallocate the audio sample buffer if it's smaller than the frame size.
|
||||
if (newsize > sc->m_decodedAudioSamplesSiz )
|
||||
{
|
||||
@ -973,30 +977,28 @@ bool FFmpegLibs::InitLibs(wxString libpath_format, bool WXUNUSED(showerr))
|
||||
FFMPEG_INITDYN(avformat, av_read_frame);
|
||||
FFMPEG_INITDYN(avformat, av_seek_frame);
|
||||
FFMPEG_INITDYN(avformat, av_close_input_file);
|
||||
FFMPEG_INITDYN(avformat, av_write_header);
|
||||
FFMPEG_INITDYN(avformat, avformat_write_header);
|
||||
FFMPEG_INITDYN(avformat, av_interleaved_write_frame);
|
||||
FFMPEG_INITDYN(avformat, av_iformat_next);
|
||||
FFMPEG_INITDYN(avformat, av_oformat_next);
|
||||
FFMPEG_INITDYN(avformat, av_set_parameters);
|
||||
FFMPEG_INITDYN(avformat, url_open_protocol);
|
||||
FFMPEG_INITDYN(avformat, url_open);
|
||||
FFMPEG_INITDYN(avformat, url_fdopen);
|
||||
FFMPEG_INITDYN(avformat, url_close);
|
||||
FFMPEG_INITDYN(avformat, url_fseek);
|
||||
FFMPEG_INITDYN(avformat, url_fclose);
|
||||
FFMPEG_INITDYN(avformat, ffurl_open);
|
||||
FFMPEG_INITDYN(avformat, ffio_fdopen);
|
||||
FFMPEG_INITDYN(avformat, ffurl_close);
|
||||
FFMPEG_INITDYN(avformat, av_new_stream);
|
||||
FFMPEG_INITDYN(avformat, avformat_alloc_context);
|
||||
FFMPEG_INITDYN(avformat, av_write_trailer);
|
||||
FFMPEG_INITDYN(avformat, av_codec_get_tag);
|
||||
FFMPEG_INITDYN(avformat, avformat_version);
|
||||
FFMPEG_INITDYN(avformat, av_open_input_stream);
|
||||
FFMPEG_INITDYN(avformat, av_metadata_get);
|
||||
FFMPEG_INITDYN(avformat, avformat_open_input);
|
||||
FFMPEG_INITDYN(avformat, av_dict_get);
|
||||
FFMPEG_INITDYN(avformat, av_dict_set);
|
||||
FFMPEG_INITDYN(avformat, avio_size);
|
||||
|
||||
FFMPEG_INITDYN(avformat, ffurl_register_protocol);
|
||||
|
||||
FFMPEG_INITALT(avformat, av_register_protocol2, av_register_protocol);
|
||||
FFMPEG_INITALT(avformat, avio_read, get_buffer);
|
||||
FFMPEG_INITALT(avformat, avio_seek, url_fseek);
|
||||
FFMPEG_INITALT(avformat, avio_close, url_fclose);
|
||||
FFMPEG_INITALT(avformat, av_metadata_set2, av_metadata_set);
|
||||
FFMPEG_INITALT(avformat, av_guess_format, guess_format);
|
||||
FFMPEG_INITALT(avformat, av_match_ext, match_ext);
|
||||
|
||||
@ -1009,12 +1011,10 @@ bool FFmpegLibs::InitLibs(wxString libpath_format, bool WXUNUSED(showerr))
|
||||
#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(52, 31, 0)
|
||||
FFMPEG_INITDYN(avcodec, av_free_packet);
|
||||
#endif
|
||||
FFMPEG_INITDYN(avcodec, avcodec_init);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_find_encoder);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_find_encoder_by_name);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_find_decoder);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_get_context_defaults);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_open);
|
||||
FFMPEG_INITDYN(avcodec, avcodec_open2);
|
||||
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(52, 25, 0)
|
||||
FFMPEG_INITDYN(avcodec, avcodec_decode_audio3);
|
||||
#else
|
||||
@ -1026,6 +1026,7 @@ bool FFmpegLibs::InitLibs(wxString libpath_format, bool WXUNUSED(showerr))
|
||||
FFMPEG_INITDYN(avcodec, avcodec_version);
|
||||
FFMPEG_INITDYN(avcodec, av_fast_realloc);
|
||||
FFMPEG_INITDYN(avcodec, av_codec_next);
|
||||
FFMPEG_INITDYN(avcodec, av_codec_is_encoder);
|
||||
|
||||
FFMPEG_INITALT(avcodec, av_get_bits_per_sample_format, av_get_bits_per_sample_fmt);
|
||||
|
||||
@ -1051,7 +1052,6 @@ bool FFmpegLibs::InitLibs(wxString libpath_format, bool WXUNUSED(showerr))
|
||||
#endif
|
||||
|
||||
//FFmpeg initialization
|
||||
avcodec_init();
|
||||
avcodec_register_all();
|
||||
av_register_all();
|
||||
|
||||
@ -1089,11 +1089,7 @@ bool FFmpegLibs::InitLibs(wxString libpath_format, bool WXUNUSED(showerr))
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(DISABLE_DYNAMIC_LOADING_FFMPEG) && (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 69, 0))
|
||||
av_register_protocol(&ufile_protocol);
|
||||
#else
|
||||
av_register_protocol2(&ufile_protocol, sizeof(ufile_protocol));
|
||||
#endif
|
||||
ffurl_register_protocol(&ufile_protocol);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
123
src/FFmpeg.h
123
src/FFmpeg.h
@ -41,6 +41,9 @@ extern "C" {
|
||||
#include <libavutil/fifo.h>
|
||||
#include <libavutil/mathematics.h>
|
||||
|
||||
//XXX HACK FIXME
|
||||
#include "libavformat/url.h"
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52, 102, 0)
|
||||
#define AVIOContext ByteIOContext
|
||||
#endif
|
||||
@ -353,7 +356,7 @@ typedef struct _streamContext
|
||||
int m_initialchannels; // number of channels allocated when we begin the importing. Assumes that number of channels doesn't change on the fly.
|
||||
|
||||
int m_samplesize; // input sample size in bytes
|
||||
SampleFormat m_samplefmt; // input sample format
|
||||
AVSampleFormat m_samplefmt; // input sample format
|
||||
|
||||
int m_osamplesize; // output sample size in bytes
|
||||
sampleFormat m_osamplefmt; // output sample format
|
||||
@ -510,15 +513,10 @@ extern "C" {
|
||||
(void),
|
||||
()
|
||||
);
|
||||
FFMPEG_FUNCTION_NO_RETURN(
|
||||
avcodec_init,
|
||||
(void),
|
||||
()
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVCodec*,
|
||||
avcodec_find_encoder,
|
||||
(enum CodecID id),
|
||||
(enum AVCodecID id),
|
||||
(id)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
@ -530,25 +528,20 @@ extern "C" {
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVCodec*,
|
||||
avcodec_find_decoder,
|
||||
(enum CodecID id),
|
||||
(enum AVCodecID id),
|
||||
(id)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
unsigned int,
|
||||
av_codec_get_tag,
|
||||
(const struct AVCodecTag * const *tags, enum CodecID id),
|
||||
(const struct AVCodecTag * const *tags, enum AVCodecID id),
|
||||
(tags, id)
|
||||
);
|
||||
FFMPEG_FUNCTION_NO_RETURN(
|
||||
avcodec_get_context_defaults,
|
||||
(AVCodecContext *s),
|
||||
(s)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
avcodec_open,
|
||||
(AVCodecContext *avctx, AVCodec *codec),
|
||||
(avctx, codec);
|
||||
avcodec_open2,
|
||||
(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options),
|
||||
(avctx, codec, options);
|
||||
);
|
||||
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(52, 25, 0)
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
@ -585,7 +578,7 @@ extern "C" {
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_get_bits_per_sample_format,
|
||||
(enum SampleFormat sample_fmt),
|
||||
(enum AVSampleFormat sample_fmt),
|
||||
(sample_fmt)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
@ -621,9 +614,9 @@ extern "C" {
|
||||
#endif
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_open_input_stream,
|
||||
(AVFormatContext **ic_ptr, AVIOContext *pb, const char *filename, AVInputFormat *fmt, AVFormatParameters *ap),
|
||||
(ic_ptr, pb, filename, fmt, ap)
|
||||
avformat_open_input,
|
||||
(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, AVDictionary **options),
|
||||
(ic_ptr, filename, fmt, options)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
@ -667,9 +660,9 @@ extern "C" {
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_write_header,
|
||||
(AVFormatContext *s),
|
||||
(s)
|
||||
avformat_write_header,
|
||||
(AVFormatContext *s, AVDictionary **options),
|
||||
(s, options)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVInputFormat*,
|
||||
@ -686,63 +679,27 @@ extern "C" {
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVCodec*,
|
||||
av_codec_next,
|
||||
(AVCodec *c),
|
||||
(const AVCodec *c),
|
||||
(c)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_set_parameters,
|
||||
(AVFormatContext *s, AVFormatParameters *ap),
|
||||
(s, ap)
|
||||
ffurl_open,
|
||||
(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options),
|
||||
(puc, filename, flags, int_cb, options)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_open_protocol,
|
||||
(URLContext **puc, struct URLProtocol *up, const char *filename, int flags),
|
||||
(puc, up, filename, flags)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_open,
|
||||
(URLContext **puc, const char *filename, int flags),
|
||||
(puc, filename, flags)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_fdopen,
|
||||
ffio_fdopen,
|
||||
(AVIOContext **s, URLContext *h),
|
||||
(s, h)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_close,
|
||||
ffurl_close,
|
||||
(URLContext *h),
|
||||
(h)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_fopen,
|
||||
(AVIOContext **s, const char *filename, int flags),
|
||||
(s, filename, flags)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int64_t,
|
||||
url_fseek,
|
||||
(AVIOContext *s, int64_t offset, int whence),
|
||||
(s, offset, whence)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
url_fclose,
|
||||
(AVIOContext *s),
|
||||
(s)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int64_t,
|
||||
url_fsize,
|
||||
(AVIOContext *s),
|
||||
(s)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVStream*,
|
||||
av_new_stream,
|
||||
@ -870,21 +827,15 @@ extern "C" {
|
||||
(f, size)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
AVMetadataTag *,
|
||||
av_metadata_get,
|
||||
(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags),
|
||||
AVDictionaryEntry *,
|
||||
av_dict_get,
|
||||
(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags),
|
||||
(m, key, prev, flags)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_metadata_set,
|
||||
(AVMetadata **pm, const char *key, const char *value),
|
||||
(pm, key, value)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_metadata_set2,
|
||||
(AVMetadata **pm, const char *key, const char *value, int flags),
|
||||
av_dict_set,
|
||||
(AVDictionary **pm, const char *key, const char *value, int flags),
|
||||
(pm, key, value, flags)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
@ -899,6 +850,12 @@ extern "C" {
|
||||
(AVIOContext *s, int64_t offset, int whence),
|
||||
(s, offset, whence)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int64_t,
|
||||
avio_size,
|
||||
(AVIOContext *s),
|
||||
(s)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
avio_close,
|
||||
@ -907,9 +864,15 @@ extern "C" {
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_register_protocol2,
|
||||
(URLProtocol *protocol, int size),
|
||||
(protocol, size)
|
||||
ffurl_register_protocol,
|
||||
(URLProtocol *protocol),
|
||||
(protocol)
|
||||
);
|
||||
FFMPEG_FUNCTION_WITH_RETURN(
|
||||
int,
|
||||
av_codec_is_encoder,
|
||||
(const AVCodec *codec),
|
||||
(codec)
|
||||
);
|
||||
};
|
||||
#endif
|
||||
|
@ -265,8 +265,6 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
|
||||
|
||||
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.
|
||||
@ -295,30 +293,17 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
|
||||
}
|
||||
|
||||
mEncAudioStream->id = 0;
|
||||
mEncFormatCtx->timestamp = 0;
|
||||
|
||||
// Open the output file.
|
||||
if (!(mEncFormatDesc->flags & AVFMT_NOFILE))
|
||||
{
|
||||
if ((err = ufile_fopen(&mEncFormatCtx->pb, mName, URL_WRONLY)) < 0)
|
||||
if ((err = ufile_fopen(&mEncFormatCtx->pb, mName, AVIO_FLAG_WRITE)) < 0)
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : ERROR - Can't open output file \"%s\" to write. Error code is %d."), mName.c_str(),err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set default parameters on the format context.
|
||||
memset(&fpOutFile, 0, sizeof(AVFormatParameters));
|
||||
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;
|
||||
}
|
||||
|
||||
// I have no idea what is this
|
||||
mEncFormatCtx->preload = (int)(0.5 * AV_TIME_BASE);
|
||||
mEncFormatCtx->max_delay = (int)(0.7 * AV_TIME_BASE);
|
||||
|
||||
// Open the audio stream's codec and initialise any stream related data.
|
||||
if (!InitCodecs(project))
|
||||
return false;
|
||||
@ -334,7 +319,7 @@ bool ExportFFmpeg::Init(const char *shortname, AudacityProject *project, Tags *m
|
||||
}
|
||||
|
||||
// Write headers to the output file.
|
||||
if ((err = av_write_header(mEncFormatCtx)) < 0)
|
||||
if ((err = avformat_write_header(mEncFormatCtx, NULL)) < 0)
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : ERROR - Can't write headers to output file \"%s\". Error code is %d."), mName.c_str(),err);
|
||||
|
||||
@ -355,11 +340,11 @@ bool ExportFFmpeg::CheckSampleRate(int rate, int lowrate, int highrate, const in
|
||||
bool ExportFFmpeg::InitCodecs(AudacityProject *project)
|
||||
{
|
||||
AVCodec * codec = NULL;
|
||||
AVDictionary *options = NULL;
|
||||
|
||||
// Configure the audio stream's codec context.
|
||||
mEncAudioCodecCtx = mEncAudioStream->codec;
|
||||
|
||||
avcodec_get_context_defaults(mEncAudioCodecCtx);
|
||||
mEncAudioCodecCtx->codec_id = ExportFFmpegOptions::fmts[mSubFormat].codecid;
|
||||
mEncAudioCodecCtx->codec_type = CODEC_TYPE_AUDIO;
|
||||
mEncAudioCodecCtx->codec_tag = av_codec_get_tag((const AVCodecTag **)mEncFormatCtx->oformat->codec_tag,mEncAudioCodecCtx->codec_id);
|
||||
@ -399,10 +384,9 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
|
||||
mEncAudioCodecCtx->bit_rate = gPrefs->Read(wxT("/FileFormats/WMABitRate"), 198000);
|
||||
if (!CheckSampleRate(mSampleRate,ExportFFmpegWMAOptions::iWMASampleRates[0], ExportFFmpegWMAOptions::iWMASampleRates[4], &ExportFFmpegWMAOptions::iWMASampleRates[0]))
|
||||
mSampleRate = AskResample(mEncAudioCodecCtx->bit_rate,mSampleRate, ExportFFmpegWMAOptions::iWMASampleRates[0], ExportFFmpegWMAOptions::iWMASampleRates[4], &ExportFFmpegWMAOptions::iWMASampleRates[0]);
|
||||
mEncAudioCodecCtx->flags2 |= CODEC_FLAG2_BIT_RESERVOIR | 0x0004;
|
||||
break;
|
||||
case FMT_OTHER:
|
||||
av_metadata_set2(&mEncAudioStream->metadata, "language", gPrefs->Read(wxT("/FileFormats/FFmpegLanguage"),wxT("")).ToUTF8(), 0);
|
||||
av_dict_set(&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);
|
||||
@ -410,22 +394,25 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
|
||||
mEncAudioCodecCtx->global_quality = gPrefs->Read(wxT("/FileFormats/FFmpegQuality"),(long)-99999);
|
||||
mEncAudioCodecCtx->cutoff = gPrefs->Read(wxT("/FileFormats/FFmpegCutOff"),(long)0);
|
||||
mEncAudioCodecCtx->flags2 = 0;
|
||||
if (gPrefs->Read(wxT("/FileFormats/FFmpegBitReservoir"),true)) mEncAudioCodecCtx->flags2 |= CODEC_FLAG2_BIT_RESERVOIR;
|
||||
if (gPrefs->Read(wxT("/FileFormats/FFmpegBitReservoir"),true))
|
||||
av_dict_set(&options, "reservoir", "1", 0);
|
||||
if (gPrefs->Read(wxT("/FileFormats/FFmpegVariableBlockLen"),true)) mEncAudioCodecCtx->flags2 |= 0x0004; //WMA only?
|
||||
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 0, 0)
|
||||
mEncAudioCodecCtx->use_lpc = gPrefs->Read(wxT("/FileFormats/FFmpegUseLPC"),true);
|
||||
#endif
|
||||
mEncAudioCodecCtx->compression_level = gPrefs->Read(wxT("/FileFormats/FFmpegCompLevel"),-1);
|
||||
mEncAudioCodecCtx->frame_size = gPrefs->Read(wxT("/FileFormats/FFmpegFrameSize"),(long)0);
|
||||
mEncAudioCodecCtx->lpc_coeff_precision = gPrefs->Read(wxT("/FileFormats/FFmpegLPCCoefPrec"),(long)0);
|
||||
mEncAudioCodecCtx->min_prediction_order = gPrefs->Read(wxT("/FileFormats/FFmpegMinPredOrder"),(long)-1);
|
||||
mEncAudioCodecCtx->max_prediction_order = gPrefs->Read(wxT("/FileFormats/FFmpegMaxPredOrder"),(long)-1);
|
||||
mEncAudioCodecCtx->min_partition_order = gPrefs->Read(wxT("/FileFormats/FFmpegMinPartOrder"),(long)-1);
|
||||
mEncAudioCodecCtx->max_partition_order = gPrefs->Read(wxT("/FileFormats/FFmpegMaxPartOrder"),(long)-1);
|
||||
mEncAudioCodecCtx->prediction_order_method = gPrefs->Read(wxT("/FileFormats/FFmpegPredOrderMethod"),(long)0);
|
||||
mEncFormatCtx->mux_rate = gPrefs->Read(wxT("/FileFormats/FFmpegMuxRate"),(long)0);
|
||||
|
||||
//These all should use AVDictionary & AVOptions that way audacity could display the correct list of available options for the choosen encoder
|
||||
// mEncAudioCodecCtx->lpc_coeff_precision = gPrefs->Read(wxT("/FileFormats/FFmpegLPCCoefPrec"),(long)0);
|
||||
// mEncAudioCodecCtx->min_prediction_order = gPrefs->Read(wxT("/FileFormats/FFmpegMinPredOrder"),(long)-1);
|
||||
// mEncAudioCodecCtx->max_prediction_order = gPrefs->Read(wxT("/FileFormats/FFmpegMaxPredOrder"),(long)-1);
|
||||
// mEncAudioCodecCtx->min_partition_order = gPrefs->Read(wxT("/FileFormats/FFmpegMinPartOrder"),(long)-1);
|
||||
// mEncAudioCodecCtx->max_partition_order = gPrefs->Read(wxT("/FileFormats/FFmpegMaxPartOrder"),(long)-1);
|
||||
// mEncAudioCodecCtx->prediction_order_method = gPrefs->Read(wxT("/FileFormats/FFmpegPredOrderMethod"),(long)0);
|
||||
// mEncFormatCtx->mux_rate = gPrefs->Read(wxT("/FileFormats/FFmpegMuxRate"),(long)0);
|
||||
mEncFormatCtx->packet_size = gPrefs->Read(wxT("/FileFormats/FFmpegPacketSize"),(long)0);
|
||||
mEncAudioCodecCtx->codec_id = (CodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"), mEncFormatDesc->audio_codec);
|
||||
mEncAudioCodecCtx->codec_id = (AVCodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"), mEncFormatDesc->audio_codec);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -439,12 +426,12 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
|
||||
mEncAudioCodecCtx->flags |= CODEC_FLAG_QSCALE;
|
||||
}
|
||||
else mEncAudioCodecCtx->global_quality = -99999;
|
||||
this->mEncAudioStream->quality = mEncAudioCodecCtx->global_quality = mEncAudioCodecCtx->global_quality * FF_QP2LAMBDA;
|
||||
mEncAudioCodecCtx->global_quality = mEncAudioCodecCtx->global_quality * FF_QP2LAMBDA;
|
||||
mEncAudioCodecCtx->sample_rate = mSampleRate;
|
||||
mEncAudioCodecCtx->channels = mChannels;
|
||||
mEncAudioCodecCtx->time_base.num = 1;
|
||||
mEncAudioCodecCtx->time_base.den = mEncAudioCodecCtx->sample_rate;
|
||||
mEncAudioCodecCtx->sample_fmt = SAMPLE_FMT_S16;
|
||||
mEncAudioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
|
||||
//mEncAudioCodecCtx->strict_std_compliance = FF_COMPLIANCE_STRICT;
|
||||
|
||||
if (mEncAudioCodecCtx->codec_id == CODEC_ID_AC3)
|
||||
@ -476,7 +463,7 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project)
|
||||
}
|
||||
|
||||
// Open the codec.
|
||||
if (avcodec_open(mEncAudioCodecCtx, codec) < 0 || mEncAudioCodecCtx->frame_size == 0)
|
||||
if (avcodec_open2(mEncAudioCodecCtx, codec, &options) < 0 || mEncAudioCodecCtx->frame_size == 0)
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : ERROR - Can't open audio codec 0x%x."),mEncAudioCodecCtx->codec_id);
|
||||
return false;
|
||||
@ -536,7 +523,7 @@ bool ExportFFmpeg::Finalize()
|
||||
// Fill audio buffer with zeroes. If codec tries to read the whole buffer,
|
||||
// it will just read silence. If not - who cares?
|
||||
memset(mEncAudioFifoOutBuf,0,nAudioFrameSizeOut);
|
||||
AVCodec *codec = mEncAudioCodecCtx->codec;
|
||||
const AVCodec *codec = mEncAudioCodecCtx->codec;
|
||||
|
||||
// We have an incomplete buffer of samples left. Is it OK to encode it?
|
||||
// If codec supports CODEC_CAP_SMALL_LAST_FRAME, we can feed it with smaller frame
|
||||
@ -805,7 +792,7 @@ void ExportFFmpeg::SetMetadata(Tags *tags, const char *name, const wxChar *tag)
|
||||
{
|
||||
wxString value = tags->GetTag(tag);
|
||||
|
||||
av_metadata_set2(&mEncFormatCtx->metadata, name, mSupportsUTF8 ? value.ToUTF8() : value.mb_str(), 0);
|
||||
av_dict_set(&mEncFormatCtx->metadata, name, mSupportsUTF8 ? value.ToUTF8() : value.mb_str(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1251,7 +1251,7 @@ ExportFFmpegOptions::ExportFFmpegOptions(wxWindow *parent)
|
||||
DoOnFormatList();
|
||||
|
||||
//Select the codec that was selected last time this dialog was closed
|
||||
AVCodec *codec = avcodec_find_encoder((CodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"),(long)CODEC_ID_NONE));
|
||||
AVCodec *codec = avcodec_find_encoder((AVCodecID)gPrefs->Read(wxT("/FileFormats/FFmpegCodec"),(long)CODEC_ID_NONE));
|
||||
if (codec != NULL) mCodecList->Select(mCodecList->FindString(wxString::FromUTF8(codec->name)));
|
||||
DoOnCodecList();
|
||||
}
|
||||
@ -1288,7 +1288,7 @@ void ExportFFmpegOptions::FetchCodecList()
|
||||
while ((codec = av_codec_next(codec)))
|
||||
{
|
||||
// We're only interested in audio and only in encoders
|
||||
if (codec->type == CODEC_TYPE_AUDIO && codec->encode)
|
||||
if (codec->type == CODEC_TYPE_AUDIO && av_codec_is_encoder(codec))
|
||||
{
|
||||
mCodecNames.Add(wxString::FromUTF8(codec->name));
|
||||
mCodecLongNames.Add(wxString::Format(wxT("%s - %s"),mCodecNames.Last().c_str(),wxString::FromUTF8(codec->long_name).c_str()));
|
||||
@ -1506,7 +1506,7 @@ void ExportFFmpegOptions::FindSelectedCodec(wxString **name, wxString **longname
|
||||
|
||||
///
|
||||
///
|
||||
int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
|
||||
int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, AVCodecID id)
|
||||
{
|
||||
// By default assume that id is not in the list
|
||||
int index = -1;
|
||||
@ -1533,7 +1533,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
|
||||
// Find the codec, that is claimed to be compatible
|
||||
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)
|
||||
if (codec != NULL && (codec->type == CODEC_TYPE_AUDIO) && av_codec_is_encoder(codec))
|
||||
{
|
||||
// If it was selected - remember it's new index
|
||||
if ((id >= 0) && codec->id == id) index = mShownCodecNames.GetCount();
|
||||
@ -1548,7 +1548,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
|
||||
AVCodec *codec = NULL;
|
||||
while ((codec = av_codec_next(codec)))
|
||||
{
|
||||
if (codec->type == CODEC_TYPE_AUDIO && codec->encode)
|
||||
if (codec->type == CODEC_TYPE_AUDIO && av_codec_is_encoder(codec))
|
||||
{
|
||||
if (mShownCodecNames.Index(wxString::FromUTF8(codec->name)) < 0)
|
||||
{
|
||||
@ -1568,7 +1568,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
|
||||
if (format != NULL)
|
||||
{
|
||||
AVCodec *codec = avcodec_find_encoder(format->audio_codec);
|
||||
if (codec != NULL && (codec->type == CODEC_TYPE_AUDIO) && codec->encode)
|
||||
if (codec != NULL && (codec->type == CODEC_TYPE_AUDIO) && av_codec_is_encoder(codec))
|
||||
{
|
||||
if ((id >= 0) && codec->id == id) index = mShownCodecNames.GetCount();
|
||||
mShownCodecNames.Add(wxString::FromUTF8(codec->name));
|
||||
@ -1584,7 +1584,7 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, CodecID id)
|
||||
|
||||
///
|
||||
///
|
||||
int ExportFFmpegOptions::FetchCompatibleFormatList(CodecID id, wxString *selfmt)
|
||||
int ExportFFmpegOptions::FetchCompatibleFormatList(AVCodecID id, wxString *selfmt)
|
||||
{
|
||||
int index = -1;
|
||||
mShownFormatNames.Clear();
|
||||
@ -1824,7 +1824,7 @@ void ExportFFmpegOptions::DoOnFormatList()
|
||||
selcdcid = cdc->id;
|
||||
}
|
||||
}
|
||||
int newselcdc = FetchCompatibleCodecList(selfmt->c_str(), (CodecID)selcdcid);
|
||||
int newselcdc = FetchCompatibleCodecList(selfmt->c_str(), (AVCodecID)selcdcid);
|
||||
if (newselcdc >= 0) mCodecList->Select(newselcdc);
|
||||
|
||||
AVCodec *cdc = NULL;
|
||||
|
@ -43,7 +43,7 @@ struct ExposedFormat
|
||||
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)
|
||||
AVCodecID codecid; //!< codec ID (see libavcodec/avcodec.h)
|
||||
bool compiledIn; //!< support for this codec/format is compiled in (checked at runtime)
|
||||
};
|
||||
|
||||
@ -52,7 +52,7 @@ struct ExposedFormat
|
||||
struct CompatibilityEntry
|
||||
{
|
||||
const wxChar *fmt; //!< format, recognizeable by guess_format()
|
||||
CodecID codec; //!< codec ID
|
||||
AVCodecID codec; //!< codec ID
|
||||
};
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ struct ApplicableFor
|
||||
{
|
||||
bool enable; //!< true if this control should be enabled, false otherwise
|
||||
int control; //!< control ID
|
||||
CodecID codec; //!< Codec ID
|
||||
AVCodecID codec; //!< Codec ID
|
||||
const char *format; //!< Format short name
|
||||
};
|
||||
|
||||
@ -258,7 +258,7 @@ private:
|
||||
///\param id Codec ID
|
||||
///\param selfmt format selected at the moment
|
||||
///\return index of the selfmt in new format list or -1 if it is not in the list
|
||||
int FetchCompatibleFormatList(CodecID id, wxString *selfmt);
|
||||
int FetchCompatibleFormatList(AVCodecID id, wxString *selfmt);
|
||||
|
||||
/// Retreives codec list from libavcodec
|
||||
void FetchCodecList();
|
||||
@ -267,7 +267,7 @@ private:
|
||||
///\param fmt Format short name
|
||||
///\param id id of the codec selected at the moment
|
||||
///\return index of the id in new codec list or -1 if it is not in the list
|
||||
int FetchCompatibleCodecList(const wxChar *fmt, CodecID id);
|
||||
int FetchCompatibleCodecList(const wxChar *fmt, AVCodecID id);
|
||||
|
||||
/// Retreives list of presets from configuration file
|
||||
void FetchPresetList();
|
||||
|
@ -413,7 +413,7 @@ bool FFmpegImportFileHandle::InitCodecs()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (avcodec_open(sc->m_codecCtx, codec) < 0)
|
||||
if (avcodec_open2(sc->m_codecCtx, codec, NULL) < 0)
|
||||
{
|
||||
wxLogError(wxT("FFmpeg : avcodec_open() failed. Index[%02d], Codec[%02x - %s]"),i,sc->m_codecCtx->codec_id,sc->m_codecCtx->codec_name);
|
||||
//Can't open decoder - skip this stream
|
||||
@ -434,7 +434,7 @@ bool FFmpegImportFileHandle::InitCodecs()
|
||||
else
|
||||
bitrate.Printf(wxT("?"));
|
||||
|
||||
AVMetadataTag *tag = av_metadata_get(sc->m_stream->metadata, "language", NULL, 0);
|
||||
AVDictionaryEntry *tag = av_dict_get(sc->m_stream->metadata, "language", NULL, 0);
|
||||
wxString lang;
|
||||
if (tag)
|
||||
{
|
||||
@ -491,8 +491,8 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
|
||||
{
|
||||
switch (mScs[s]->m_stream->codec->sample_fmt)
|
||||
{
|
||||
case SAMPLE_FMT_U8:
|
||||
case SAMPLE_FMT_S16:
|
||||
case AV_SAMPLE_FMT_U8:
|
||||
case AV_SAMPLE_FMT_S16:
|
||||
mScs[s]->m_osamplesize = sizeof(int16_t);
|
||||
mScs[s]->m_osamplefmt = int16Sample;
|
||||
break;
|
||||
@ -749,23 +749,23 @@ int FFmpegImportFileHandle::WriteData(streamContext *sc)
|
||||
{
|
||||
switch (sc->m_samplefmt)
|
||||
{
|
||||
case SAMPLE_FMT_U8:
|
||||
case AV_SAMPLE_FMT_U8:
|
||||
((int16_t *)tmp[chn])[index] = (int16_t) (*(uint8_t *)in - 0x80) << 8;
|
||||
break;
|
||||
|
||||
case SAMPLE_FMT_S16:
|
||||
case AV_SAMPLE_FMT_S16:
|
||||
((int16_t *)tmp[chn])[index] = (int16_t) *(int16_t *)in;
|
||||
break;
|
||||
|
||||
case SAMPLE_FMT_S32:
|
||||
case AV_SAMPLE_FMT_S32:
|
||||
((float *)tmp[chn])[index] = (float) *(int32_t *)in * (1.0 / (1 << 31));
|
||||
break;
|
||||
|
||||
case SAMPLE_FMT_FLT:
|
||||
case AV_SAMPLE_FMT_FLT:
|
||||
((float *)tmp[chn])[index] = (float) *(float *)in;
|
||||
break;
|
||||
|
||||
case SAMPLE_FMT_DBL:
|
||||
case AV_SAMPLE_FMT_DBL:
|
||||
((float *)tmp[chn])[index] = (float) *(double *)in;
|
||||
break;
|
||||
|
||||
@ -792,6 +792,7 @@ int FFmpegImportFileHandle::WriteData(streamContext *sc)
|
||||
|
||||
// Try to update the progress indicator (and see if user wants to cancel)
|
||||
int updateResult = eProgressSuccess;
|
||||
int64_t filesize = avio_size(mFormatContext->pb);
|
||||
// PTS (presentation time) is the proper way of getting current position
|
||||
if (sc->m_pkt.pts != int64_t(AV_NOPTS_VALUE) && mFormatContext->duration != int64_t(AV_NOPTS_VALUE))
|
||||
{
|
||||
@ -805,10 +806,10 @@ int FFmpegImportFileHandle::WriteData(streamContext *sc)
|
||||
mProgressLen = sc->m_stream->nb_frames;
|
||||
}
|
||||
// When number of frames is unknown, use position in file
|
||||
else if (mFormatContext->file_size > 0 && sc->m_pkt.pos > 0 && sc->m_pkt.pos <= mFormatContext->file_size)
|
||||
else if (filesize > 0 && sc->m_pkt.pos > 0 && sc->m_pkt.pos <= filesize)
|
||||
{
|
||||
mProgressPos = sc->m_pkt.pos;
|
||||
mProgressLen = mFormatContext->file_size;
|
||||
mProgressLen = filesize;
|
||||
}
|
||||
updateResult = mProgress->Update(mProgressPos, mProgressLen != 0 ? mProgressLen : 1);
|
||||
|
||||
@ -831,9 +832,9 @@ void FFmpegImportFileHandle::WriteMetadata(Tags *tags)
|
||||
|
||||
void FFmpegImportFileHandle::GetMetadata(Tags *tags, const wxChar *tag, const char *name)
|
||||
{
|
||||
AVMetadataTag *meta;
|
||||
AVDictionaryEntry *meta;
|
||||
|
||||
meta = av_metadata_get(mFormatContext->metadata, name, NULL, AV_METADATA_IGNORE_SUFFIX);
|
||||
meta = av_dict_get(mFormatContext->metadata, name, NULL, AV_DICT_IGNORE_SUFFIX);
|
||||
if (meta)
|
||||
{
|
||||
tags->SetTag(tag, wxString::FromUTF8(meta->value));
|
||||
|
Loading…
x
Reference in New Issue
Block a user