29#define DESC XO("FFmpeg-compatible files")
174 std::unique_ptr<ImportFileHandle>
Open(
212 Tags *tags)
override;
218 void Stop()
override;
291 wxString extension = filename.AfterLast(
wxT(
'.'));
303 if (dontShowDlg == 0 && newsession)
319 auto handle = std::make_unique<FFmpegImportFileHandle>(filename);
322 bool success = handle->Init();
332 std::make_unique< FFmpegImportPlugin >()
352 wxLogError(
wxT(
"FFmpeg : AVFormatContextWrapper::OpenInputContext() failed for file %s"),
mName);
372 auto codec =
mFFmpeg->CreateDecoder(
id);
378 wxT(
"FFmpeg : CreateDecoder() failed. Index[%02d], Codec[%02x - %s]"),
386 if ( codecContextPtr->Open( codecContextPtr->GetCodec() ) < 0 )
388 wxLogError(
wxT(
"FFmpeg : Open() failed. Index[%02d], Codec[%02x - %s]"),i,
id,
name);
393 const int channels = codecContextPtr->GetChannels();
395 codecContextPtr->GetPreferredAudacitySampleFormat();
397 auto codecContext = codecContextPtr.get();
401 channels, preferredFormat,
true });
411 if (codecContext->GetBitRate() > 0)
412 bitrate.Printf(
wxT(
"%d"),(
int)codecContext->GetBitRate());
414 bitrate.Printf(
wxT(
"?"));
418 auto lang = std::string(streamMetadata.
Get(
"language", {}));
422"Index[%02x] Codec[%s], Language[%s], Bitrate[%s], Channels[%d], Duration[%d]")
428 (
int)codecContext->GetChannels(),
480 int64_t stream_delay = 0;
490 wxT(
"Stream %d start_time = %lld, that would be %f milliseconds."),
494 if (stream_delay > 0) {
495 for (
auto track : *stream)
499 mStreams.push_back(std::move(stream));
505 for (std::unique_ptr<AVPacketWrapper> packet;
510 auto streamContextIt = std::find_if(
513 { return ctx.StreamIndex == index;
519 WriteData(&(*streamContextIt), packet.get());
528 auto emptyPacket =
mFFmpeg->CreateAVPacketWrapper();
570 auto streamIt = std::find_if(
589 auto data = sc->
CodecContext->DecodeAudioPacketInt16(packet);
590 const auto channelsCount = sc->
CodecContext->GetChannels();
591 const auto samplesPerChannel = data.size() / channelsCount;
599 channel.AppendBuffer(
600 reinterpret_cast<samplePtr>(data.data() + chn),
611 auto data = sc->
CodecContext->DecodeAudioPacketFloat(packet);
612 const auto channelsCount = sc->
CodecContext->GetChannels();
613 const auto samplesPerChannel = data.size() / channelsCount;
615 auto channelIndex = 0;
618 if(channelIndex >= nChannels)
621 channel.AppendBuffer(
622 reinterpret_cast<samplePtr>(data.data() + channelIndex),
659 filesize > 0 && packet->
GetPos() > 0 && packet->
GetPos() <= filesize)
676 if (wxString(
mAVFormatContext->GetInputFormat()->GetName()).Contains(
"m4a"))
681 else if (wxString(
mAVFormatContext->GetInputFormat()->GetName()).Contains(
"asf"))
#define DICT_IGNORE_SUFFIX
const TranslatableString name
BoolSetting FFmpegNotFoundDontShow
#define AUDACITY_AV_TIME_BASE
#define AUDACITY_AV_NOPTS_VALUE
BoolSetting NewImportingSession
static Importer::RegisteredImportPlugin registered
The interface that all file import "plugins" (if you want to call them that) must implement....
std::vector< std::shared_ptr< TrackList > > TrackHolders
audacity::BasicSettings * gPrefs
std::vector< TranslatableString > TranslatableStrings
std::string_view Get(const std::string_view &key, const std::string_view &defaultValue, int flags=0) const
virtual int64_t GetPos() const noexcept=0
virtual int64_t GetPresentationTimestamp() const noexcept=0
virtual int64_t GetDuration() const noexcept=0
virtual int GetIndex() const noexcept=0
virtual bool IsAudio() const noexcept=0
virtual AVDictionaryWrapper GetMetadata() const noexcept=0
virtual AudacityAVRational GetTimeBase() const noexcept=0
virtual int64_t GetFramesCount() const noexcept=0
virtual std::unique_ptr< AVCodecContextWrapper > GetAVCodecContext() const noexcept=0
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
! Does actual import, returned by FFmpegImportPlugin::Open
void WriteData(StreamContext *sc, const AVPacketWrapper *packet)
wxInt64 mProgressPos
Current timestamp, file position or whatever is used as first argument for Update()
std::unique_ptr< AVFormatContextWrapper > mAVFormatContext
FFmpegImportFileHandle(const FilePath &name)
void GetMetadata(Tags &tags, const wxChar *tag, const char *name)
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) override
TranslatableStrings mStreamInfo
Array of stream descriptions. After Init() and before Import(), same size as mStreamContexts.
std::vector< TrackListHolder > mStreams
void SetStreamUsage(wxInt32 StreamID, bool Use) override
FilePath GetFilename() const override
const TranslatableStrings & GetStreamInfo() override
~FFmpegImportFileHandle()
const std::shared_ptr< FFmpegFunctions > mFFmpeg
TranslatableString GetFileDescription() override
void WriteMetadata(Tags *tags)
bool mStopped
True if importing was stopped by user.
ByteCount GetFileUncompressedBytes() override
bool mCancelled
True if importing was canceled by user.
wxInt32 GetStreamCount() override
std::vector< StreamContext > mStreamContexts
wxInt64 mProgressLen
Duration, total length or whatever is used as second argument for Update()
An ImportPlugin for FFmpeg data.
TranslatableString FailureHint() const override
User visible message suggesting what to do when a file type isn't recognized; default empty string.
wxString GetPluginStringID() override
std::unique_ptr< ImportFileHandle > Open(const FilePath &Filename, AudacityProject *) override
! Probes the file and opens it if appropriate
TranslatableString GetPluginFormatDescription() override
Base class for FlacImportFileHandle, LOFImportFileHandle, MP3ImportFileHandle, OggImportFileHandle an...
unsigned long long ByteCount
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
bool SupportsExtension(const FileExtension &extension)
Interface used to report on import state and progress.
virtual void OnImportResult(ImportResult result)=0
Used to report on import result for file handle passed as argument to OnImportFileOpened.
virtual void OnImportProgress(double progress)=0
static TrackListHolder NewWaveTrack(WaveTrackFactory &trackFactory, unsigned nChannels, sampleFormat effectiveFormat, double rate)
static void ForEachChannel(TrackList &trackList, const std::function< void(WaveChannel &)> &op)
Iterates over channels in each wave track from the list.
static void FinalizeImport(TrackHolders &outTracks, const std::vector< TrackListHolder > &importedStreams)
Flushes the given channels and moves them to outTracks.
bool Write(const T &value)
Write value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
Holds a msgid for the translation catalog; may also bind format arguments.
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
virtual bool Flush() noexcept=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
static double streamStartTime
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)
std::unique_ptr< AVCodecContextWrapper > CodecContext
sampleFormat SampleFormat