Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
FFmpegExportProcessor Class Referencefinal
Inheritance diagram for FFmpegExportProcessor:
[legend]
Collaboration diagram for FFmpegExportProcessor:
[legend]

Public Member Functions

 FFmpegExportProcessor (std::shared_ptr< FFmpegFunctions > ffmpeg, int format)
 
bool Initialize (AudacityProject &project, const Parameters &parameters, const wxFileNameWrapper &filename, double t0, double t1, bool selectedOnly, double sampleRate, unsigned channels, MixerOptions::Downmix *mixerSpec, const Tags *tags) override
 Called before start processing. More...
 
ExportResult Process (ExportProcessorDelegate &delegate) override
 
- Public Member Functions inherited from ExportProcessor
 ExportProcessor (const ExportProcessor &)=delete
 
ExportProcessoroperator= (const ExportProcessor &)=delete
 
 ExportProcessor ()=default
 
virtual ~ExportProcessor ()
 
virtual bool Initialize (AudacityProject &project, const Parameters &parameters, const wxFileNameWrapper &filename, double t0, double t1, bool selectedOnly, double rate, unsigned channels, MixerOptions::Downmix *mixerSpec=nullptr, const Tags *tags=nullptr)=0
 Called before start processing. More...
 
virtual ExportResult Process (ExportProcessorDelegate &delegate)=0
 

Private Attributes

std::shared_ptr< FFmpegFunctionsmFFmpeg
 
struct {
   int   subformat
 
   TranslatableString   status
 
   double   t0
 
   double   t1
 
   std::unique_ptr< Mixer >   mixer
 
   std::unique_ptr< FFmpegExporter >   exporter
 
context
 

Additional Inherited Members

- Public Types inherited from ExportProcessor
using Parameters = std::vector< std::tuple< ExportOptionID, ExportValue > >
 

Detailed Description

Definition at line 662 of file ExportFFmpeg.cpp.

Constructor & Destructor Documentation

◆ FFmpegExportProcessor()

FFmpegExportProcessor::FFmpegExportProcessor ( std::shared_ptr< FFmpegFunctions ffmpeg,
int  format 
)

Definition at line 1589 of file ExportFFmpeg.cpp.

1590 : mFFmpeg(std::move(ffmpeg))
1591{
1592 context.subformat = subformat;
1593}
std::shared_ptr< FFmpegFunctions > mFFmpeg
struct FFmpegExportProcessor::@149 context

References context, and subformat.

Member Function Documentation

◆ Initialize()

bool FFmpegExportProcessor::Initialize ( AudacityProject project,
const Parameters parameters,
const wxFileNameWrapper filename,
double  t0,
double  t1,
bool  selectedOnly,
double  rate,
unsigned  channels,
MixerOptions::Downmix mixerSpec,
const Tags tags 
)
overridevirtual

Called before start processing.

Parameters
projectProcessor may access project data, take care to exclude any data race
parametersA format-dependent set of parameters used in exporting
selectedOnlySet to true if all tracks should be mixed, to false if only the selected tracks should be mixed and exported.
tagsA Tags object that will over-ride the one in *project and be used to tag the file that is exported. @retern Implementations may simply return false without any error reporting. This is to temporarily preserve old behavior, which is to be removed in the nearest future.

Implements ExportProcessor.

Definition at line 1595 of file ExportFFmpeg.cpp.

1602{
1603 context.t0 = t0;
1604 context.t1 = t1;
1605
1606 if (!FFmpegFunctions::Load())
1607 {
1608 throw ExportException(_("Properly configured FFmpeg is required to proceed.\nYou can configure it at Preferences > Libraries."));
1609 }
1610 // subformat index may not correspond directly to fmts[] index, convert it
1611 const auto adjustedFormatIndex = AdjustFormatIndex(context.subformat);
1612 if (channels > ExportFFmpegOptions::fmts[adjustedFormatIndex].maxchannels)
1613 {
1614 throw ExportException(XO("Attempted to export %d channels, but maximum number of channels for selected output format is %d")
1615 .Format(
1616 channels,
1617 ExportFFmpegOptions::fmts[adjustedFormatIndex].maxchannels )
1618 .Translation());
1619 }
1620
1621 const auto &tracks = TrackList::Get( project );
1622 bool ret = true;
1623
1624 if (adjustedFormatIndex >= FMT_LAST) {
1625 // TODO: more precise message
1626 throw ExportErrorException("FFmpeg:996");
1627 }
1628
1629 wxString shortname(ExportFFmpegOptions::fmts[adjustedFormatIndex].shortname);
1630 if (adjustedFormatIndex == FMT_OTHER)
1631 shortname = ExportPluginHelpers::GetParameterValue<std::string>(parameters, FEFormatID, "matroska");
1632
1633 context.exporter = std::make_unique<FFmpegExporter>(mFFmpeg, fName, channels, adjustedFormatIndex);
1634
1635 ret = context.exporter->Init(shortname.mb_str(), &project, static_cast<int>(sampleRate), metadata, parameters);
1636
1637 if (!ret) {
1638 // TODO: more precise message
1639 throw ExportErrorException("FFmpeg:1008");
1640 }
1641
1642 context.mixer = context.exporter->CreateMixer(tracks, selectionOnly,
1643 t0, t1,
1644 mixerSpec);
1645
1646 context.status = selectionOnly
1647 ? XO("Exporting selected audio as %s")
1648 .Format( ExportFFmpegOptions::fmts[adjustedFormatIndex].description )
1649 : XO("Exporting the audio as %s")
1650 .Format( ExportFFmpegOptions::fmts[adjustedFormatIndex].description );
1651
1652 return true;
1653}
static int AdjustFormatIndex(int format)
@ FMT_OTHER
@ FMT_LAST
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
const auto tracks
const auto project
static ExposedFormat fmts[]
List of export types.
Abstract base class used in importing a file.
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)

References _, AdjustFormatIndex(), context, FMT_LAST, FMT_OTHER, ExportFFmpegOptions::fmts, TrackList::Get(), FFmpegFunctions::Load(), mFFmpeg, project, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, t0, t1, tracks, and XO().

Here is the call graph for this function:

◆ Process()

ExportResult FFmpegExportProcessor::Process ( ExportProcessorDelegate delegate)
overridevirtual

Implements ExportProcessor.

Definition at line 1655 of file ExportFFmpeg.cpp.

1656{
1657 delegate.SetStatusString(context.status);
1658 auto exportResult = ExportResult::Success;
1659 {
1660 while (exportResult == ExportResult::Success) {
1661 auto pcmNumSamples = context.mixer->Process();
1662 if (pcmNumSamples == 0)
1663 break;
1664
1665 short *pcmBuffer = (short *)context.mixer->GetBuffer();
1666
1667 if (!context.exporter->EncodeAudioFrame(pcmBuffer, pcmNumSamples))
1668 // All errors should already have been reported.
1669 return ExportResult::Error;
1670
1671 if(exportResult == ExportResult::Success)
1673 delegate, *context.mixer, context.t0, context.t1);
1674 }
1675 }
1676
1677 if ( exportResult != ExportResult::Cancelled )
1678 if ( !context.exporter->Finalize() ) // Finalize makes its own messages
1679 return ExportResult::Error;
1680 return exportResult;
1681}
static ExportResult UpdateProgress(ExportProcessorDelegate &delegate, Mixer &mixer, double t0, double t1)
Sends progress update to delegate and retrieves state update from it. Typically used inside each expo...
virtual void SetStatusString(const TranslatableString &str)=0

References Cancelled, context, Error, ExportProcessorDelegate::SetStatusString(), Success, and ExportPluginHelpers::UpdateProgress().

Here is the call graph for this function:

Member Data Documentation

◆ 

struct { ... } FFmpegExportProcessor::context

◆ exporter

std::unique_ptr<FFmpegExporter> FFmpegExportProcessor::exporter

Definition at line 673 of file ExportFFmpeg.cpp.

◆ mFFmpeg

std::shared_ptr<FFmpegFunctions> FFmpegExportProcessor::mFFmpeg
private

Definition at line 664 of file ExportFFmpeg.cpp.

Referenced by Initialize().

◆ mixer

std::unique_ptr<Mixer> FFmpegExportProcessor::mixer

Definition at line 672 of file ExportFFmpeg.cpp.

◆ status

TranslatableString FFmpegExportProcessor::status

Definition at line 669 of file ExportFFmpeg.cpp.

◆ subformat

int FFmpegExportProcessor::subformat

Definition at line 668 of file ExportFFmpeg.cpp.

Referenced by FFmpegExportProcessor().

◆ t0

double FFmpegExportProcessor::t0

Definition at line 670 of file ExportFFmpeg.cpp.

Referenced by Initialize().

◆ t1

double FFmpegExportProcessor::t1

Definition at line 671 of file ExportFFmpeg.cpp.

Referenced by Initialize().


The documentation for this class was generated from the following file: