Audacity 3.2.0
Classes | Macros | Functions | Variables
FFmpeg.cpp File Reference
#include "FFmpeg.h"
#include "FileNames.h"
#include "SelectFile.h"
#include "widgets/HelpSystem.h"
#include "widgets/AudacityMessageBox.h"
#include <wx/checkbox.h>
#include <wx/dynlib.h>
#include <wx/file.h>
#include <wx/log.h>
#include <wx/textctrl.h>
Include dependency graph for FFmpeg.cpp:

Go to the source code of this file.

Classes

class  FindFFmpegDialog
 Allows user to locate libav* libraries. More...
 

Macros

#define DEFINE_FFMPEG_POINTERS
 
#define ID_FFMPEG_BROWSE   5000
 
#define ID_FFMPEG_DLOAD   5001
 

Functions

bool LoadFFmpeg (bool showerror)
 
void FFmpegStartup ()
 
TranslatableString GetFFmpegVersion ()
 
bool FindFFmpegLibs (wxWindow *parent)
 

Variables

static BoolSetting FFmpegEnabled { L"/FFmpeg/Enabled", false }
 
BoolSetting FFmpegNotFoundDontShow { L"/FFmpeg/NotFoundDontShow", false }
 

Macro Definition Documentation

◆ DEFINE_FFMPEG_POINTERS

#define DEFINE_FFMPEG_POINTERS

Definition at line 18 of file FFmpeg.cpp.

◆ ID_FFMPEG_BROWSE

#define ID_FFMPEG_BROWSE   5000

Definition at line 108 of file FFmpeg.cpp.

◆ ID_FFMPEG_DLOAD

#define ID_FFMPEG_DLOAD   5001

Definition at line 109 of file FFmpeg.cpp.

Function Documentation

◆ FFmpegStartup()

void FFmpegStartup ( )

Called during Audacity start-up to try and load the ffmpeg libraries

Definition at line 65 of file FFmpeg.cpp.

66{
67 bool enabled = FFmpegEnabled.Read();
68 // 'false' means that no errors should be shown whatsoever
69 if (!LoadFFmpeg(false))
70 {
71 if (enabled)
72 {
74"FFmpeg was configured in Preferences and successfully loaded before, \
75\nbut this time Audacity failed to load it at startup. \
76\n\nYou may want to go back to Preferences > Libraries and re-configure it."),
77 XO("FFmpeg startup failed"));
78 }
79 }
80}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static BoolSetting FFmpegEnabled
Definition: FFmpeg.cpp:44
bool LoadFFmpeg(bool showerror)
Definition: FFmpeg.cpp:46
#define XO(s)
Definition: Internat.h:31
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200

References AudacityMessageBox(), FFmpegEnabled, LoadFFmpeg(), Setting< T >::Read(), and XO.

Referenced by AudacityApp::InitPart2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindFFmpegLibs()

bool FindFFmpegLibs ( wxWindow *  parent)

Definition at line 310 of file FFmpeg.cpp.

311{
312 wxString path;
313
314#if defined(__WXMSW__)
315 const wxString name = wxT("avformat.dll");
316#elif defined(__WXMAC__)
317 const wxString name = wxT("ffmpeg.64bit.dylib");
318#else
319 const wxString name = wxT("libavformat.so");
320#endif
321
322 wxLogMessage(wxT("Looking for FFmpeg libraries..."));
323
324 auto searchPaths = FFmpegFunctions::GetSearchPaths(false);
325
326 if (!searchPaths.empty())
327 path = searchPaths.front();
328
329 FindFFmpegDialog fd(parent, path, name);
330
331 if (fd.ShowModal() == wxID_CANCEL) {
332 wxLogMessage(wxT("User canceled the dialog. Failed to find FFmpeg libraries."));
333 return false;
334 }
335
336 path = fd.GetLibPath();
337
338 const wxFileName fileName(path);
339
340 if (fileName.FileExists())
341 path = fileName.GetPath();
342
343 wxLogMessage(wxT("User-specified path = '%s'"), path);
344
345 SettingTransaction transaction;
346 AVFormatPath.Write(path);
347
348 // Try to load FFmpeg from the user provided path
349 if (!FFmpegFunctions::Load(true))
350 {
351 wxLogError(wxT("User-specified path does not contain FFmpeg libraries."));
352 return false;
353 }
354
355 transaction.Commit();
356
357 wxLogMessage(wxT("User-specified FFmpeg file exists. Success."));
358
359 return true;
360}
const TranslatableString name
Definition: Distortion.cpp:82
StringSetting AVFormatPath
Allows user to locate libav* libraries.
Definition: FFmpeg.cpp:113
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:252
Extend SettingScope with Commit() which flushes updates in a batch.
Definition: Prefs.h:144
static std::vector< wxString > GetSearchPaths(bool fromUserPathOnly)
static std::shared_ptr< FFmpegFunctions > Load(bool fromUserPathOnly=false)

References AVFormatPath, SettingTransaction::Commit(), FindFFmpegDialog::GetLibPath(), FFmpegFunctions::GetSearchPaths(), FFmpegFunctions::Load(), name, and Setting< T >::Write().

Referenced by ExportFFmpeg::CheckFileName(), LibraryPrefs::OnFFmpegFindButton(), and ExportFFmpegCustomOptions::OnOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFFmpegVersion()

TranslatableString GetFFmpegVersion ( )

Definition at line 82 of file FFmpeg.cpp.

83{
84 auto ffmpeg = FFmpegFunctions::Load();
85
86 if (ffmpeg)
87 {
88 return Verbatim(
89 wxString::Format(
90 wxT("F(%d.%d.%d),C(%d.%d.%d),U(%d.%d.%d)"),
91 ffmpeg->AVFormatVersion.Major, ffmpeg->AVFormatVersion.Minor, ffmpeg->AVFormatVersion.Micro,
92 ffmpeg->AVCodecVersion.Major, ffmpeg->AVCodecVersion.Minor, ffmpeg->AVCodecVersion.Micro,
93 ffmpeg->AVUtilVersion.Major, ffmpeg->AVUtilVersion.Minor, ffmpeg->AVUtilVersion.Micro
94 ));
95 }
96
97 return XO("FFmpeg library not found");
98}
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.

References FFmpegFunctions::Load(), Verbatim(), and XO.

Referenced by LibraryPrefs::SetFFmpegVersionText().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadFFmpeg()

bool LoadFFmpeg ( bool  showerror)

Definition at line 46 of file FFmpeg.cpp.

47{
48 auto ffmpeg = FFmpegFunctions::Load();
49
50 if (!ffmpeg)
51 {
52 FFmpegEnabled.Write(false);
53 gPrefs->Flush();
54 return false;
55 }
56 else
57 {
58 FFmpegEnabled.Write(true);
59 gPrefs->Flush();
60 return true;
61 }
62}
FileConfig * gPrefs
Definition: Prefs.cpp:71
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143

References FFmpegEnabled, FileConfig::Flush(), gPrefs, FFmpegFunctions::Load(), and Setting< T >::Write().

Referenced by ExportFFmpeg::CheckFileName(), FFmpegStartup(), LibraryPrefs::OnFFmpegFindButton(), and ExportFFmpegCustomOptions::OnOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ FFmpegEnabled

BoolSetting FFmpegEnabled { L"/FFmpeg/Enabled", false }
static

Definition at line 44 of file FFmpeg.cpp.

Referenced by FFmpegStartup(), and LoadFFmpeg().

◆ FFmpegNotFoundDontShow

BoolSetting FFmpegNotFoundDontShow { L"/FFmpeg/NotFoundDontShow", false }