Panda3D
config_ffmpeg.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file config_ffmpeg.cxx
10  * @author rdb
11  * @date 2013-08-23
12  */
13 
14 #include "config_ffmpeg.h"
15 #include "dconfig.h"
16 #include "ffmpegVideo.h"
17 #include "ffmpegVideoCursor.h"
18 #include "ffmpegAudio.h"
19 #include "ffmpegAudioCursor.h"
20 
21 #include "movieTypeRegistry.h"
22 
23 extern "C" {
24  #include <libavcodec/avcodec.h>
25  #include <libavformat/avformat.h>
26  #include <libavutil/avutil.h>
27 }
28 
29 #if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_FFMPEG)
30  #error Buildsystem error: BUILDING_FFMPEG not defined
31 #endif
32 
33 // Minimum supported versions:
34 // FFmpeg: 1.1
35 // libav: 9.20 (for Ubuntu 14.04)
36 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 35, 1)
37  #error Minimum supported version of libavcodec is 54.35.1.
38 #endif
39 
40 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(54, 20, 4)
41  #error Minimum supported version of libavformat is 54.20.4.
42 #endif
43 
44 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(52, 3, 0)
45  #error Minimum supported version of libavutil is 52.3.0.
46 #endif
47 
48 ConfigureDef(config_ffmpeg);
49 NotifyCategoryDef(ffmpeg, "");
50 
51 ConfigureFn(config_ffmpeg) {
53 }
54 
55 ConfigVariableInt ffmpeg_max_readahead_frames
56 ("ffmpeg-max-readahead-frames", 2,
57  PRC_DESC("The maximum number of frames ahead which an ffmpeg decoder thread "
58  "should read in advance of actual playback. Set this to 0 to "
59  "decode ffmpeg videos in the main thread."));
60 
61 ConfigVariableBool ffmpeg_show_seek_frames
62 ("ffmpeg-show-seek-frames", true,
63  PRC_DESC("Set this true to allow showing the intermediate results of seeking "
64  "through the ffmpeg stream to a target frame, or false to hold the "
65  "current frame until the target frame is achieved. This has the "
66  "biggest effect on videos that are too expensive to decode in real "
67  "time: when this is true, the video can be seen to animate at least "
68  "a little bit; when it is false, you may get long periods of one "
69  "held frame."));
70 
71 ConfigVariableBool ffmpeg_support_seek
72 ("ffmpeg-support-seek", true,
73  PRC_DESC("True to use the av_seek_frame() function to seek within ffmpeg "
74  "video files. If this is false, Panda will only seek within a "
75  "file by reading it from the beginning until the desired point, "
76  "which can be much slower. Set this false only if you suspect "
77  "a problem with av_seek_frame()."));
78 
79 ConfigVariableBool ffmpeg_global_lock
80 ("ffmpeg-global-lock", false,
81  PRC_DESC("Set this true to enable a single global mutex across *all* ffmpeg "
82  "operations. Leave this false to use the mutex only for "
83  "the ffmpeg operations that are generally known to be "
84  "not thread-safe. This will negatively affect ffmpeg performance, "
85  "especially when decoding multiple videos at once (including the "
86  "left and right channels of a stereo video). Set this true only "
87  "if you suspect a problem with ffmpeg's own thread-safe nature."));
88 
89 ConfigVariableEnum<ThreadPriority> ffmpeg_thread_priority
90 ("ffmpeg-thread-priority", TP_normal,
91  PRC_DESC("The default thread priority at which to start ffmpeg decoder "
92  "threads."));
93 
94 ConfigVariableInt ffmpeg_read_buffer_size
95 ("ffmpeg-read-buffer-size", 4096,
96  PRC_DESC("The size in bytes of the buffer used when reading input files. "
97  "This is important for performance. A typical size is that of a "
98  "cache page, e.g. 4kb."));
99 
100 ConfigVariableBool ffmpeg_prefer_libvpx
101 ("ffmpeg-prefer-libvpx", false,
102  PRC_DESC("If this is true, Panda will overrule ffmpeg's best judgment on "
103  "which decoder to use for decoding VP8 and VP9 files, and try to "
104  "choose libvpx. This is useful when you want to play WebM videos "
105  "with an alpha channel, which aren't supported by ffmpeg's own "
106  "VP8/VP9 decoders."));
107 
108 /**
109  * Initializes the library. This must be called at least once before any of
110  * the functions or classes in this library can be used. Normally it will be
111  * called by the static initializers and need not be called explicitly, but
112  * special cases exist.
113  */
114 void
116  static bool initialized = false;
117  if (initialized) {
118  return;
119  }
120  initialized = true;
121 
123 
124  FfmpegVideo::init_type();
125  FfmpegVideoCursor::init_type();
126  FfmpegAudio::init_type();
127  FfmpegAudioCursor::init_type();
128 
131 
132  // Register ffmpeg as catch-all audiovideo type.
134  reg->register_audio_type(&FfmpegAudio::make, "*");
135  reg->register_video_type(&FfmpegVideo::make, "*");
136 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void init_libffmpeg()
Initializes the library.
This is a convenience class to specialize ConfigVariable as a boolean type.
This class records the different types of MovieAudio and MovieVideo that are available for loading.
static void register_with_read_factory()
Tells the BamReader how to create objects of type FfmpegVideo.
static void register_protocol()
Should be called at startup to attach the appropriate hooks between Panda and FFMpeg.
static void register_with_read_factory()
Tells the BamReader how to create objects of type FfmpegVideo.
Definition: ffmpegVideo.cxx:79
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class specializes ConfigVariable as an enumerated type.
static MovieTypeRegistry * get_global_ptr()
Returns a pointer to the global MovieTypeRegistry instance.
This is a convenience class to specialize ConfigVariable as an integer type.
void register_video_type(MakeVideoFunc func, const std::string &extensions)
Registers a MovieVideo type, so that files with any of the given extensions will be loaded as this ty...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_audio_type(MakeAudioFunc func, const std::string &extensions)
Registers a MovieAudio type, so that files with any of the given extensions will be loaded as this ty...