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 661 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::@148 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 bool ret = true;
1622
1623 if (adjustedFormatIndex >= FMT_LAST) {
1624 // TODO: more precise message
1625 throw ExportErrorException("FFmpeg:996");
1626 }
1627
1628 wxString shortname(ExportFFmpegOptions::fmts[adjustedFormatIndex].shortname);
1629 if (adjustedFormatIndex == FMT_OTHER)
1630 shortname = ExportPluginHelpers::GetParameterValue<std::string>(parameters, FEFormatID, "matroska");
1631
1632 context.exporter = std::make_unique<FFmpegExporter>(mFFmpeg, fName, channels, adjustedFormatIndex);
1633
1634 ret = context.exporter->Init(shortname.mb_str(), &project, static_cast<int>(sampleRate), metadata, parameters);
1635
1636 if (!ret) {
1637 // TODO: more precise message
1638 throw ExportErrorException("FFmpeg:1008");
1639 }
1640
1641 context.mixer =
1642 context.exporter->CreateMixer(project, selectionOnly, t0, t1, mixerSpec);
1643
1644 context.status = selectionOnly
1645 ? XO("Exporting selected audio as %s")
1646 .Format( ExportFFmpegOptions::fmts[adjustedFormatIndex].description )
1647 : XO("Exporting the audio as %s")
1648 .Format( ExportFFmpegOptions::fmts[adjustedFormatIndex].description );
1649
1650 return true;
1651}
static int AdjustFormatIndex(int format)
@ FMT_OTHER
@ FMT_LAST
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
const auto project
static ExposedFormat fmts[]
List of export types.
Abstract base class used in importing a file.
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)

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

Here is the call graph for this function:

◆ Process()

ExportResult FFmpegExportProcessor::Process ( ExportProcessorDelegate delegate)
overridevirtual

Implements ExportProcessor.

Definition at line 1653 of file ExportFFmpeg.cpp.

1654{
1655 delegate.SetStatusString(context.status);
1656 auto exportResult = ExportResult::Success;
1657 {
1658 while (exportResult == ExportResult::Success) {
1659 auto pcmNumSamples = context.mixer->Process();
1660 if (pcmNumSamples == 0)
1661 break;
1662
1663 short *pcmBuffer = (short *)context.mixer->GetBuffer();
1664
1665 if (!context.exporter->EncodeAudioFrame(pcmBuffer, pcmNumSamples))
1666 // All errors should already have been reported.
1667 return ExportResult::Error;
1668
1669 if(exportResult == ExportResult::Success)
1671 delegate, *context.mixer, context.t0, context.t1);
1672 }
1673 }
1674
1675 if ( exportResult != ExportResult::Cancelled )
1676 if ( !context.exporter->Finalize() ) // Finalize makes its own messages
1677 return ExportResult::Error;
1678 return exportResult;
1679}
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 672 of file ExportFFmpeg.cpp.

◆ mFFmpeg

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

Definition at line 663 of file ExportFFmpeg.cpp.

Referenced by Initialize().

◆ mixer

std::unique_ptr<Mixer> FFmpegExportProcessor::mixer

Definition at line 671 of file ExportFFmpeg.cpp.

◆ status

TranslatableString FFmpegExportProcessor::status

Definition at line 668 of file ExportFFmpeg.cpp.

◆ subformat

int FFmpegExportProcessor::subformat

Definition at line 667 of file ExportFFmpeg.cpp.

Referenced by FFmpegExportProcessor().

◆ t0

double FFmpegExportProcessor::t0

Definition at line 669 of file ExportFFmpeg.cpp.

Referenced by Initialize().

◆ t1

double FFmpegExportProcessor::t1

Definition at line 670 of file ExportFFmpeg.cpp.

Referenced by Initialize().


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