OpenShot Library | libopenshot  0.1.9
FFmpegUtilities.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for FFmpegUtilities
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef OPENSHOT_FFMPEG_UTILITIES_H
29 #define OPENSHOT_FFMPEG_UTILITIES_H
30 
31  // Required for libavformat to build on Windows
32  #ifndef INT64_C
33  #define INT64_C(c) (c ## LL)
34  #define UINT64_C(c) (c ## ULL)
35  #endif
36 
37  // Include the FFmpeg headers
38  extern "C" {
39  #include <libavcodec/avcodec.h>
40  #include <libavformat/avformat.h>
41  #include <libswscale/swscale.h>
42  #include <libavresample/avresample.h>
43  #include <libavutil/mathematics.h>
44  #include <libavutil/pixfmt.h>
45  #include <libavutil/pixdesc.h>
46 
47  // libavutil changed folders at some point
48  #if LIBAVFORMAT_VERSION_MAJOR >= 53
49  #include <libavutil/opt.h>
50  #else
51  #include <libavcodec/opt.h>
52  #endif
53 
54  // channel header refactored
55  #if LIBAVFORMAT_VERSION_MAJOR >= 54
56  #include <libavutil/channel_layout.h>
57  #endif
58  }
59 
60  // This was removed from newer versions of FFmpeg (but still used in libopenshot)
61  #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
62  #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
63  #endif
64  #ifndef AV_ERROR_MAX_STRING_SIZE
65  #define AV_ERROR_MAX_STRING_SIZE 64
66  #endif
67  #ifndef AUDIO_PACKET_ENCODING_SIZE
68  #define AUDIO_PACKET_ENCODING_SIZE 768000 // 48khz * S16 (2 bytes) * max channels (8)
69  #endif
70 
71  // This wraps an unsafe C macro to be C++ compatible function
72  static const std::string av_make_error_string(int errnum)
73  {
74  char errbuf[AV_ERROR_MAX_STRING_SIZE];
75  av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
76  std::string errstring(errbuf);
77  return errstring;
78  }
79 
80  // Redefine the C macro to use our new C++ function
81  #undef av_err2str
82  #define av_err2str(errnum) av_make_error_string(errnum).c_str()
83 
84  // Define this for compatibility
85  #ifndef PixelFormat
86  #define PixelFormat AVPixelFormat
87  #endif
88  #ifndef PIX_FMT_RGBA
89  #define PIX_FMT_RGBA AV_PIX_FMT_RGBA
90  #endif
91  #ifndef PIX_FMT_NONE
92  #define PIX_FMT_NONE AV_PIX_FMT_NONE
93  #endif
94  #ifndef PIX_FMT_RGB24
95  #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
96  #endif
97  #ifndef PIX_FMT_YUV420P
98  #define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P
99  #endif
100 
101  #if LIBAVFORMAT_VERSION_MAJOR >= 55
102  #define AV_ALLOCATE_FRAME() av_frame_alloc()
103  #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame)
104  #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame)
105  #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet)
106  #else
107  #define AV_ALLOCATE_FRAME() avcodec_alloc_frame()
108  #define AV_RESET_FRAME(av_frame) avcodec_get_frame_defaults(av_frame)
109  #define AV_FREE_FRAME(av_frame) avcodec_free_frame(av_frame)
110  #define AV_FREE_PACKET(av_packet) av_free_packet(av_packet)
111  #endif
112 
113 
114 #endif
#define AV_ERROR_MAX_STRING_SIZE