29#define DESC XO("FFmpeg-compatible files")
174 std::unique_ptr<ImportFileHandle>
Open(
212 std::optional<LibFileFormats::AcidizerTags>& outAcidTags)
override;
218 void Stop()
override;
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(),
454 std::optional<LibFileFormats::AcidizerTags>&)
477 int64_t stream_delay = 0;
487 wxT(
"Stream %d start_time = %lld, that would be %f milliseconds."),
490 if (stream_delay > 0)
492 for (
auto track : *
tracks)
504 for (std::unique_ptr<AVPacketWrapper> packet;
509 auto streamContextIt = std::find_if(
512 { return ctx.StreamIndex == index;
518 WriteData(&(*streamContextIt), packet.get());
527 auto emptyPacket =
mFFmpeg->CreateAVPacketWrapper();
573 auto streamIt = std::find_if(
592 auto data = sc->
CodecContext->DecodeAudioPacketInt16(packet);
593 const auto channelsCount = sc->
CodecContext->GetChannels();
594 const auto samplesPerChannel = data.size() / channelsCount;
602 channel.AppendBuffer(
603 reinterpret_cast<samplePtr>(data.data() + chn),
614 auto data = sc->
CodecContext->DecodeAudioPacketFloat(packet);
615 const auto channelsCount = sc->
CodecContext->GetChannels();
616 const auto samplesPerChannel = data.size() / channelsCount;
618 auto channelIndex = 0;
621 if(channelIndex >= nChannels)
624 channel.AppendBuffer(
625 reinterpret_cast<samplePtr>(data.data() + channelIndex),
662 filesize > 0 && packet->
GetPos() > 0 && packet->
GetPos() <= filesize)
679 if (wxString(
mAVFormatContext->GetInputFormat()->GetName()).Contains(
"m4a"))
684 else if (wxString(
mAVFormatContext->GetInputFormat()->GetName()).Contains(
"asf"))
#define DICT_IGNORE_SUFFIX
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< Track > > 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)
TranslatableStrings mStreamInfo
Array of stream descriptions. After Init() and before Import(), same size as mStreamContexts.
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
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 sampleFormat ChooseFormat(sampleFormat effectiveFormat)
Choose appropriate format, which will not be narrower than the specified one.
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< std::shared_ptr< WaveTrack > > &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...
TrackListHolder CreateMany(size_t nChannels)
Creates tracks with project's default rate and format and the given number of channels.
virtual bool Flush() noexcept=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
ProjectFileIOExtensionRegistry::Extension extension
static double streamStartTime
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)
std::unique_ptr< AVCodecContextWrapper > CodecContext
sampleFormat SampleFormat