Audacity  3.0.3
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 }

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 306 of file FFmpeg.cpp.

307 {
308  wxString path;
309 
310 #if defined(__WXMSW__)
311  const wxString name = wxT("avformat-*.dll");
312 #elif defined(__WXMAC__)
313  const wxString name = wxT("ffmpeg.*.64bit.dylib");
314 #else
315  const wxString name = wxT("libavformat.so.*");
316 #endif
317 
318  wxLogMessage(wxT("Looking for FFmpeg libraries..."));
319 
320  auto searchPaths = FFmpegFunctions::GetSearchPaths();
321 
322  if (!searchPaths.empty())
323  path = searchPaths.front();
324 
325  FindFFmpegDialog fd(parent, path, name);
326 
327  if (fd.ShowModal() == wxID_CANCEL) {
328  wxLogMessage(wxT("User canceled the dialog. Failed to find FFmpeg libraries."));
329  return false;
330  }
331 
332  path = fd.GetLibPath();
333 
334  wxLogMessage(wxT("User-specified path = '%s'"), path);
335 
336  if (!::wxFileExists(path)) {
337  wxLogError(wxT("User-specified file does not exist. Failed to find FFmpeg libraries."));
338  return false;
339  }
340 
341  wxLogMessage(wxT("User-specified FFmpeg file exists. Success."));
342 
343  AVFormatPath.Write(path);
344  gPrefs->Flush();
345 
346  return true;
347 }

References AVFormatPath, FileConfig::Flush(), FindFFmpegDialog::GetLibPath(), FFmpegFunctions::GetSearchPaths(), gPrefs, 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 }

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 }

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 }
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Setting::Write
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:172
XO
#define XO(s)
Definition: Internat.h:31
Setting::Read
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:128
LoadFFmpeg
bool LoadFFmpeg(bool showerror)
Definition: FFmpeg.cpp:46
FFmpegEnabled
static BoolSetting FFmpegEnabled
Definition: FFmpeg.cpp:44
name
const TranslatableString name
Definition: Distortion.cpp:98
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
AVFormatPath
StringSetting AVFormatPath
Definition: FFmpegFunctions.cpp:272
FFmpegFunctions::Load
static std::shared_ptr< FFmpegFunctions > Load()
Definition: FFmpegFunctions.cpp:240
FFmpegFunctions::GetSearchPaths
static std::vector< wxString > GetSearchPaths()
Definition: FFmpegFunctions.cpp:274
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
FindFFmpegDialog
Allows user to locate libav* libraries.
Definition: FFmpeg.cpp:113