2008-07-16 16:35:59 +08:00
|
|
|
/*
|
2008-07-25 17:08:15 +08:00
|
|
|
* ZoneMinder FFMPEG Interface, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
* Copyright (C) 2001-2008 Philip Coombes
|
2008-07-16 16:35:59 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZM_FFMPEG_H
|
|
|
|
#define ZM_FFMPEG_H
|
2013-09-27 19:08:11 +08:00
|
|
|
#include <stdint.h>
|
2013-11-26 22:34:26 +08:00
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_image.h"
|
2008-07-25 00:57:39 +08:00
|
|
|
|
2008-07-25 17:00:23 +08:00
|
|
|
#ifdef __cplusplus
|
2008-07-16 16:35:59 +08:00
|
|
|
extern "C" {
|
2008-07-25 17:00:23 +08:00
|
|
|
#endif
|
2013-10-10 12:16:11 +08:00
|
|
|
|
|
|
|
// AVUTIL
|
2008-07-25 00:57:39 +08:00
|
|
|
#if HAVE_LIBAVUTIL_AVUTIL_H
|
|
|
|
#include <libavutil/avutil.h>
|
2013-09-27 19:08:11 +08:00
|
|
|
#include <libavutil/base64.h>
|
2013-10-10 12:16:11 +08:00
|
|
|
#include <libavutil/mathematics.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
|
|
|
|
/* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg
|
2015-05-29 23:45:35 +08:00
|
|
|
* The original source is vlc (in modules/codec/avcodec/avcommon_compat.h)
|
2015-05-29 23:38:02 +08:00
|
|
|
* a is the major version
|
|
|
|
* b and c the minor and micro versions of libav
|
|
|
|
* d and e the minor and micro versions of FFmpeg */
|
|
|
|
#define LIBAVUTIL_VERSION_CHECK(a, b, c, d, e) \
|
|
|
|
( (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
|
|
|
|
(LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
|
|
|
|
|
|
|
|
#if LIBAVUTIL_VERSION_CHECK(50, 29, 0, 29, 0)
|
2014-10-16 01:23:29 +08:00
|
|
|
#include <libavutil/opt.h>
|
|
|
|
#else
|
|
|
|
#include <libavcodec/opt.h>
|
|
|
|
#endif
|
2013-09-27 19:08:11 +08:00
|
|
|
#elif HAVE_FFMPEG_AVUTIL_H
|
|
|
|
#include <ffmpeg/avutil.h>
|
|
|
|
#include <ffmpeg/base64.h>
|
2013-10-10 12:16:11 +08:00
|
|
|
#include <ffmpeg/mathematics.h>
|
2014-10-16 01:23:29 +08:00
|
|
|
#include <ffmpeg/opt.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBAVUTIL_AVUTIL_H */
|
2013-10-10 12:16:11 +08:00
|
|
|
|
|
|
|
// AVCODEC
|
2008-07-24 19:30:18 +08:00
|
|
|
#if HAVE_LIBAVCODEC_AVCODEC_H
|
|
|
|
#include <libavcodec/avcodec.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
|
2015-05-29 23:45:35 +08:00
|
|
|
/*
|
|
|
|
* LIBAVCODEC_VERSION_CHECK checks for the right version of libav and FFmpeg
|
|
|
|
* The original source is vlc (in modules/codec/avcodec/avcommon_compat.h)
|
2015-05-29 23:38:02 +08:00
|
|
|
* a is the major version
|
|
|
|
* b and c the minor and micro versions of libav
|
|
|
|
* d and e the minor and micro versions of FFmpeg */
|
|
|
|
#define LIBAVCODEC_VERSION_CHECK(a, b, c, d, e) \
|
|
|
|
( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
|
|
|
|
(LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
|
|
|
|
|
2013-09-27 19:08:11 +08:00
|
|
|
#elif HAVE_FFMPEG_AVCODEC_H
|
|
|
|
#include <ffmpeg/avcodec.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBAVCODEC_AVCODEC_H */
|
|
|
|
|
2014-10-12 06:14:09 +08:00
|
|
|
#if defined(HAVE_LIBAVCODEC_AVCODEC_H)
|
2015-05-29 23:38:02 +08:00
|
|
|
#if LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100)
|
2014-04-26 04:12:58 +08:00
|
|
|
#define _AVCODECID AVCodecID
|
|
|
|
#else
|
|
|
|
#define _AVCODECID CodecID
|
|
|
|
#endif
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBAVCODEC_AVCODEC_H */
|
2013-10-10 12:16:11 +08:00
|
|
|
|
|
|
|
// AVFORMAT
|
2008-07-24 19:30:18 +08:00
|
|
|
#if HAVE_LIBAVFORMAT_AVFORMAT_H
|
|
|
|
#include <libavformat/avformat.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
|
|
|
|
/* LIBAVFORMAT_VERSION_CHECK checks for the right version of libav and FFmpeg
|
2015-05-29 23:45:35 +08:00
|
|
|
* The original source is vlc (in modules/codec/avcodec/avcommon_compat.h)
|
2015-05-29 23:38:02 +08:00
|
|
|
* a is the major version
|
|
|
|
* b and c the minor and micro versions of libav
|
|
|
|
* d and e the minor and micro versions of FFmpeg */
|
|
|
|
#define LIBAVFORMAT_VERSION_CHECK(a, b, c, d, e) \
|
|
|
|
( (LIBAVFORMAT_VERSION_MICRO < 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
|
|
|
|
(LIBAVFORMAT_VERSION_MICRO >= 100 && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
|
|
|
|
|
2013-09-27 19:08:11 +08:00
|
|
|
#elif HAVE_FFMPEG_AVFORMAT_H
|
|
|
|
#include <ffmpeg/avformat.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBAVFORMAT_AVFORMAT_H */
|
2013-10-10 12:16:11 +08:00
|
|
|
|
|
|
|
// AVDEVICE
|
|
|
|
#if HAVE_LIBAVDEVICE_AVDEVICE_H
|
|
|
|
#include <libavdevice/avdevice.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
|
|
|
|
/* LIBAVDEVICE_VERSION_CHECK checks for the right version of libav and FFmpeg
|
|
|
|
* a is the major version
|
|
|
|
* b and c the minor and micro versions of libav
|
|
|
|
* d and e the minor and micro versions of FFmpeg */
|
|
|
|
#define LIBAVDEVICE_VERSION_CHECK(a, b, c, d, e) \
|
|
|
|
( (LIBAVDEVICE_VERSION_MICRO < 100 && LIBAVDEVICE_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
|
|
|
|
(LIBAVDEVICE_VERSION_MICRO >= 100 && LIBAVDEVICE_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
|
|
|
|
|
2013-10-10 12:16:11 +08:00
|
|
|
#elif HAVE_FFMPEG_AVDEVICE_H
|
|
|
|
#include <ffmpeg/avdevice.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBAVDEVICE_AVDEVICE_H */
|
2013-10-10 12:16:11 +08:00
|
|
|
|
|
|
|
// SWSCALE
|
2008-07-24 19:30:18 +08:00
|
|
|
#if HAVE_LIBSWSCALE_SWSCALE_H
|
|
|
|
#include <libswscale/swscale.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
|
|
|
|
/* LIBSWSCALE_VERSION_CHECK checks for the right version of libav and FFmpeg
|
|
|
|
* a is the major version
|
|
|
|
* b and c the minor and micro versions of libav
|
|
|
|
* d and e the minor and micro versions of FFmpeg */
|
|
|
|
#define LIBSWSCALE_VERSION_CHECK(a, b, c, d, e) \
|
|
|
|
( (LIBSWSCALE_VERSION_MICRO < 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
|
|
|
|
(LIBSWSCALE_VERSION_MICRO >= 100 && LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
|
|
|
|
|
2013-09-27 19:08:11 +08:00
|
|
|
#elif HAVE_FFMPEG_SWSCALE_H
|
|
|
|
#include <ffmpeg/swscale.h>
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif /* HAVE_LIBSWSCALE_SWSCALE_H */
|
2013-10-10 12:16:11 +08:00
|
|
|
|
2008-07-25 17:00:23 +08:00
|
|
|
#ifdef __cplusplus
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2008-07-25 17:00:23 +08:00
|
|
|
#endif
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2013-10-10 12:16:11 +08:00
|
|
|
#if ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H )
|
|
|
|
|
2015-05-29 23:38:02 +08:00
|
|
|
#if !LIBAVFORMAT_VERSION_CHECK(52, 107, 0, 107, 0)
|
2013-03-17 07:45:21 +08:00
|
|
|
#if defined(AVIO_WRONLY)
|
|
|
|
#define AVIO_FLAG_WRITE AVIO_WRONLY
|
|
|
|
#else
|
|
|
|
#define AVIO_FLAG_WRITE URL_WRONLY
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-11-26 22:34:26 +08:00
|
|
|
#if HAVE_LIBAVUTIL
|
2015-11-03 08:58:23 +08:00
|
|
|
enum AVPixelFormat GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder);
|
2013-11-26 22:34:26 +08:00
|
|
|
#endif // HAVE_LIBAVUTIL
|
|
|
|
|
|
|
|
|
|
|
|
/* SWScale wrapper class to make our life easier and reduce code reuse */
|
|
|
|
#if HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
|
|
|
|
class SWScale {
|
|
|
|
public:
|
|
|
|
SWScale();
|
|
|
|
~SWScale();
|
2015-11-03 08:58:23 +08:00
|
|
|
int SetDefaults(enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height);
|
2013-11-26 22:34:26 +08:00
|
|
|
int ConvertDefaults(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size);
|
|
|
|
int ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size);
|
2015-11-03 08:58:23 +08:00
|
|
|
int Convert(const Image* img, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height);
|
|
|
|
int Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint8_t* out_buffer, const size_t out_buffer_size, enum AVPixelFormat in_pf, enum AVPixelFormat out_pf, unsigned int width, unsigned int height);
|
2013-11-26 22:34:26 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool gotdefaults;
|
|
|
|
struct SwsContext* swscale_ctx;
|
|
|
|
AVFrame* input_avframe;
|
|
|
|
AVFrame* output_avframe;
|
2015-11-03 08:58:23 +08:00
|
|
|
enum AVPixelFormat default_input_pf;
|
|
|
|
enum AVPixelFormat default_output_pf;
|
2013-11-26 22:34:26 +08:00
|
|
|
unsigned int default_width;
|
|
|
|
unsigned int default_height;
|
|
|
|
};
|
|
|
|
#endif // HAVE_LIBSWSCALE && HAVE_LIBAVUTIL
|
2014-02-05 17:13:27 +08:00
|
|
|
|
2015-05-30 01:23:00 +08:00
|
|
|
#if !LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100)
|
2014-02-05 17:13:27 +08:00
|
|
|
#define AV_CODEC_ID_NONE CODEC_ID_NONE
|
|
|
|
#define AV_CODEC_ID_PCM_MULAW CODEC_ID_PCM_MULAW
|
|
|
|
#define AV_CODEC_ID_PCM_ALAW CODEC_ID_PCM_ALAW
|
|
|
|
#define AV_CODEC_ID_PCM_S16BE CODEC_ID_PCM_S16BE
|
|
|
|
#define AV_CODEC_ID_QCELP CODEC_ID_QCELP
|
|
|
|
#define AV_CODEC_ID_MP2 CODEC_ID_MP2
|
|
|
|
#define AV_CODEC_ID_MP3 CODEC_ID_MP3
|
|
|
|
#define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG
|
|
|
|
#define AV_CODEC_ID_H261 CODEC_ID_H261
|
|
|
|
#define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO
|
|
|
|
#define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
|
|
|
|
#define AV_CODEC_ID_MPEG2TS CODEC_ID_MPEG2TS
|
|
|
|
#define AV_CODEC_ID_H263 CODEC_ID_H263
|
|
|
|
#define AV_CODEC_ID_H264 CODEC_ID_H264
|
|
|
|
#define AV_CODEC_ID_MPEG4 CODEC_ID_MPEG4
|
|
|
|
#define AV_CODEC_ID_AAC CODEC_ID_AAC
|
|
|
|
#define AV_CODEC_ID_AMR_NB CODEC_ID_AMR_NB
|
|
|
|
#endif
|
|
|
|
|
2014-04-26 04:12:58 +08:00
|
|
|
/*
|
|
|
|
* Some versions of libav does not contain this definition.
|
|
|
|
*/
|
|
|
|
#ifndef AV_ERROR_MAX_STRING_SIZE
|
|
|
|
#define AV_ERROR_MAX_STRING_SIZE 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* C++ friendly version of av_err2str taken from http://libav-users.943685.n4.nabble.com/Libav-user-g-4-7-2-fails-to-compile-av-err2str-td4656417.html.
|
|
|
|
* Newer g++ versions fail with "error: taking address of temporary array" when using native libav version.
|
|
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
inline static const std::string av_make_error_string(int errnum)
|
|
|
|
{
|
|
|
|
char errbuf[AV_ERROR_MAX_STRING_SIZE];
|
2015-05-29 23:38:02 +08:00
|
|
|
#if LIBAVUTIL_VERSION_CHECK(50, 13, 0, 13, 0)
|
2014-04-26 04:12:58 +08:00
|
|
|
av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
|
|
|
|
#else
|
|
|
|
snprintf(errbuf, AV_ERROR_MAX_STRING_SIZE, "libav error %d", errnum);
|
|
|
|
#endif
|
|
|
|
return (std::string)errbuf;
|
|
|
|
}
|
2015-05-29 23:38:02 +08:00
|
|
|
|
2014-04-26 04:12:58 +08:00
|
|
|
#undef av_err2str
|
|
|
|
#define av_err2str(errnum) av_make_error_string(errnum).c_str()
|
|
|
|
|
2015-05-29 23:38:02 +08:00
|
|
|
#endif // __cplusplus
|
2014-04-26 04:12:58 +08:00
|
|
|
|
2014-10-12 04:38:38 +08:00
|
|
|
|
2013-10-10 12:16:11 +08:00
|
|
|
#endif // ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H )
|
2008-07-25 00:57:39 +08:00
|
|
|
|
|
|
|
#endif // ZM_FFMPEG_H
|