#include "ffmpeg_codecs.hpp"
#include <libavutil/mathematics.h>
-
-#if LIBAVUTIL_BUILD > CALC_FFMPEG_VERSION(51,11,0)
- #include <libavutil/opt.h>
-#endif
+#include <libavutil/opt.h>
#if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 \
? CALC_FFMPEG_VERSION(51, 63, 100) : CALC_FFMPEG_VERSION(54, 6, 0))
#endif
#endif
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
#if defined(__APPLE__)
#define AV_NOPTS_VALUE_ ((int64_t)0x8000000000000000LL)
# define CV_CODEC(name) name
#endif
-#if LIBAVUTIL_BUILD < (LIBAVUTIL_VERSION_MICRO >= 100 \
- ? CALC_FFMPEG_VERSION(51, 74, 100) : CALC_FFMPEG_VERSION(51, 42, 0))
-#define AVPixelFormat PixelFormat
-#define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
-#define AV_PIX_FMT_RGB24 PIX_FMT_RGB24
-#define AV_PIX_FMT_GRAY8 PIX_FMT_GRAY8
-#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
-#define AV_PIX_FMT_RGBA PIX_FMT_RGBA
-#define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P
-#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
-#define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P
-#define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P
-#define AV_PIX_FMT_GRAY16LE PIX_FMT_GRAY16LE
-#define AV_PIX_FMT_GRAY16BE PIX_FMT_GRAY16BE
-#endif
-
#ifndef PKT_FLAG_KEY
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
#endif
#ifndef USE_AV_INTERRUPT_CALLBACK
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 21, 0)
#define USE_AV_INTERRUPT_CALLBACK 1
-#else
-#define USE_AV_INTERRUPT_CALLBACK 0
-#endif
#endif
#ifndef USE_AV_SEND_FRAME_API
static int get_number_of_cpus(void)
{
-#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(52, 111, 0)
- return 1;
-#elif defined _WIN32
+#if defined _WIN32
SYSTEM_INFO sysinfo;
GetSystemInfo( &sysinfo );
#endif
}
-static
-inline void _opencv_ffmpeg_free(void** ptr)
-{
- if(*ptr) free(*ptr);
- *ptr = 0;
-}
static
inline int _opencv_ffmpeg_interrupt_callback(void *ptr)
*/
char * filename;
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
AVDictionary *dict;
-#endif
#if USE_AV_INTERRUPT_CALLBACK
AVInterruptCallbackMetadata interrupt_metadata;
#endif
rotation_angle = 0;
-#if (LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0))
#if (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 92, 100))
rotation_auto = true;
#else
rotation_auto = false;
#endif
dict = NULL;
-#else
- rotation_auto = false;
-#endif
rawMode = false;
rawModeInitialized = false;
if( video_st )
{
-#if LIBAVFORMAT_BUILD > 4628
avcodec_close( video_st->codec );
-
-#else
- avcodec_close( &(video_st->codec) );
-
-#endif
video_st = NULL;
}
if( ic )
{
-#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 24, 2)
- av_close_input_file(ic);
-#else
avformat_close_input(&ic);
-#endif
-
ic = NULL;
}
packet.data = NULL;
}
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
if (dict != NULL)
av_dict_free(&dict);
-#endif
if (packet_filtered.data)
{
}
InternalFFMpegRegister()
{
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
avformat_network_init();
-#endif
/* register all codecs, demux and protocols */
av_register_all();
ic->interrupt_callback.opaque = &interrupt_metadata;
#endif
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
#ifndef NO_GETENV
char* options = getenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
if(options == NULL)
}
int err = avformat_open_input(&ic, _filename, input_format, &dict);
-#else
- int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);
-#endif
if (err < 0)
{
CV_WARN(_filename);
goto exit_func;
}
- err =
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 6, 0)
- avformat_find_stream_info(ic, NULL);
-#else
- av_find_stream_info(ic);
-#endif
+ err = avformat_find_stream_info(ic, NULL);
if (err < 0)
{
CV_WARN("Could not find codec parameters");
}
for(i = 0; i < ic->nb_streams; i++)
{
-#if LIBAVFORMAT_BUILD > 4628
- AVCodecContext *enc = ic->streams[i]->codec;
-#else
- AVCodecContext *enc = &ic->streams[i]->codec;
-#endif
+ AVCodecContext* enc = ic->streams[i]->codec;
//#ifdef FF_API_THREAD_INIT
// avcodec_thread_init(enc, get_number_of_cpus());
enc->thread_count = get_number_of_cpus();
//#endif
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(52, 123, 0)
AVDictionaryEntry* avdiscard_entry = av_dict_get(dict, "avdiscard", NULL, 0);
- if (avdiscard_entry != 0) {
+ if (avdiscard_entry) {
if(strcmp(avdiscard_entry->value, "all") == 0)
enc->skip_frame = AVDISCARD_ALL;
else if (strcmp(avdiscard_entry->value, "bidir") == 0)
enc->skip_frame = AVDISCARD_DEFAULT;
else if (strcmp(avdiscard_entry->value, "none") == 0)
enc->skip_frame = AVDISCARD_NONE;
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 59, 100)
+ // NONINTRA flag was introduced with version bump at revision:
+ // https://github.com/FFmpeg/FFmpeg/commit/b152152df3b778d0a86dcda5d4f5d065b4175a7b
+ // This key is supported only for FFMPEG version
+#if LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(55, 67, 100)
else if (strcmp(avdiscard_entry->value, "nonintra") == 0)
enc->skip_frame = AVDISCARD_NONINTRA;
#endif
else if (strcmp(avdiscard_entry->value, "nonref") == 0)
enc->skip_frame = AVDISCARD_NONREF;
}
-#endif
-
-#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
-#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
-#endif
if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0)
{
} else {
codec = avcodec_find_decoder_by_name(av_dict_get(dict, "video_codec", NULL, 0)->value);
}
- if (!codec ||
-#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
- avcodec_open2(enc, codec, NULL)
-#else
- avcodec_open(enc, codec)
-#endif
- < 0)
+ if (!codec || avcodec_open2(enc, codec, NULL) < 0)
goto exit_func;
// checking width/height (since decoder can sometimes alter it, eg. vp6f)
rawModeInitialized = true;
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(58, 20, 100)
CV_CODEC_ID eVideoCodec = ic->streams[video_stream]->codecpar->codec_id;
-#elif LIBAVFORMAT_BUILD > 4628
- CV_CODEC_ID eVideoCodec = video_st->codec->codec_id;
#else
- CV_CODEC_ID eVideoCodec = video_st->codec.codec_id;
+ CV_CODEC_ID eVideoCodec = video_st->codec->codec_id;
#endif
const char* filterName = NULL;
if (eVideoCodec == CV_CODEC(CODEC_ID_H264)
return false;
}
#else
-#if LIBAVFORMAT_BUILD > 4628
AVCodecContext* ctx = ic->streams[video_stream]->codec;
-#else
- AVCodecContext* ctx = &ic->streams[video_stream]->codec;
-#endif
int err = av_bitstream_filter_filter(bsfc, ctx, NULL, &packet_filtered.data,
&packet_filtered.size, packet.data, packet.size, packet_filtered.flags & AV_PKT_FLAG_KEY);
if (err < 0)
}
// Decode video frame
- #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
- avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
- #elif LIBAVFORMAT_BUILD > 4628
- avcodec_decode_video(video_st->codec,
- picture, &got_picture,
- packet.data, packet.size);
- #else
- avcodec_decode_video(&video_st->codec,
- picture, &got_picture,
- packet.data, packet.size);
- #endif
+ avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
// Did we get a video frame?
if(got_picture)
case CAP_PROP_FPS:
return get_fps();
case CAP_PROP_FOURCC:
-#if LIBAVFORMAT_BUILD > 4628
codec_id = video_st->codec->codec_id;
codec_tag = (double) video_st->codec->codec_tag;
-#else
- codec_id = video_st->codec.codec_id;
- codec_tag = (double)video_st->codec.codec_tag;
-#endif
if(codec_tag || codec_id == AV_CODEC_ID_NONE)
{
return _opencv_ffmpeg_get_sample_aspect_ratio(ic->streams[video_stream]).den;
case CAP_PROP_CODEC_PIXEL_FORMAT:
{
-#if LIBAVFORMAT_BUILD > 4628
AVPixelFormat pix_fmt = video_st->codec->pix_fmt;
-#else
- AVPixelFormat pix_fmt = video_st->codec.pix_fmt;
-#endif
unsigned int fourcc_tag = avcodec_pix_fmt_to_codec_tag(pix_fmt);
return (fourcc_tag == 0) ? (double)-1 : (double)fourcc_tag;
}
case CAP_PROP_ORIENTATION_META:
return static_cast<double>(rotation_angle);
case CAP_PROP_ORIENTATION_AUTO:
-#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
- (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)))
+#if LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)
return static_cast<double>(rotation_auto);
#else
return 0;
#if 0 && LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 1, 100) && LIBAVFORMAT_VERSION_MICRO >= 100
double fps = r2d(av_guess_frame_rate(ic, ic->streams[video_stream], NULL));
#else
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0)
double fps = r2d(ic->streams[video_stream]->avg_frame_rate);
-#else
- double fps = r2d(ic->streams[video_stream]->r_frame_rate);
-#endif
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
if (fps < eps_zero)
void CvCapture_FFMPEG::get_rotation_angle()
{
rotation_angle = 0;
-#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
- (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)))
+#if LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)
AVDictionaryEntry *rotate_tag = av_dict_get(video_st->metadata, "rotate", NULL, 0);
if (rotate_tag != NULL)
rotation_angle = atoi(rotate_tag->value);
return setRaw();
return false;
case CAP_PROP_ORIENTATION_AUTO:
-#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
- (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)))
+#if LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)
rotation_auto = static_cast<bool>(value);
return true;
#else
rotation_auto = 0;
return false;
#endif
- break;
default:
return false;
}
static const char * icvFFMPEGErrStr(int err)
{
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
switch(err) {
case AVERROR_BSF_NOT_FOUND:
return "Bitstream filter not found";
default:
break;
}
-#else
- switch(err) {
- case AVERROR_NUMEXPECTED:
- return "Incorrect filename syntax";
- case AVERROR_INVALIDDATA:
- return "Invalid data in header";
- case AVERROR_NOFMT:
- return "Unknown format";
- case AVERROR_IO:
- return "I/O error occurred";
- case AVERROR_NOMEM:
- return "Memory allocation error";
- default:
- break;
- }
-#endif
return "Unspecified error";
}
int frame_rate, frame_rate_base;
AVCodec *codec;
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 10, 0)
st = avformat_new_stream(oc, 0);
-#else
- st = av_new_stream(oc, 0);
-#endif
if (!st) {
CV_WARN("Could not allocate stream");
return NULL;
}
-#if LIBAVFORMAT_BUILD > 4628
c = st->codec;
-#else
- c = &(st->codec);
-#endif
-#if LIBAVFORMAT_BUILD > 4621
c->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
-#else
- c->codec_id = oc->oformat->video_codec;
-#endif
if(codec_id != CV_CODEC(CODEC_ID_NONE)){
c->codec_id = codec_id;
c->codec_type = AVMEDIA_TYPE_VIDEO;
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54,25,0)
// Set per-codec defaults
CV_CODEC_ID c_id = c->codec_id;
avcodec_get_context_defaults3(c, codec);
// avcodec_get_context_defaults3 erases codec_id for some reason
c->codec_id = c_id;
-#endif
/* put sample parameters */
int64_t lbit_rate = (int64_t)bitrate;
frame_rate_base*=10;
frame_rate=(int)(fps*frame_rate_base + 0.5);
}
-#if LIBAVFORMAT_BUILD > 4752
c->time_base.den = frame_rate;
c->time_base.num = frame_rate_base;
/* adjust time base for supported framerates */
c->time_base.den= best->num;
c->time_base.num= best->den;
}
-#else
- c->frame_rate = frame_rate;
- c->frame_rate_base = frame_rate_base;
-#endif
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
c->pix_fmt = (AVPixelFormat) pixel_format;
c->mb_decision=2;
}
-#if LIBAVUTIL_BUILD > CALC_FFMPEG_VERSION(51,11,0)
/* Some settings for libx264 encoding, restore dummy values for gop_size
and qmin since they will be set to reasonable defaults by the libx264
preset system. Also, use a crf encode with the default quality rating,
if (c->priv_data)
av_opt_set(c->priv_data,"crf","23", 0);
}
-#endif
-#if LIBAVCODEC_VERSION_INT>0x000409
// some formats want stream headers to be separate
if(oc->oformat->flags & AVFMT_GLOBALHEADER)
{
-#if LIBAVCODEC_BUILD > CALC_FFMPEG_VERSION(56, 35, 0)
+ // flags were renamed: https://github.com/libav/libav/commit/7c6eb0a1b7bf1aac7f033a7ec6d8cacc3b5c2615
+#if LIBAVCODEC_BUILD >= (LIBAVCODEC_VERSION_MICRO >= 100 \
+ ? CALC_FFMPEG_VERSION(56, 60, 100) : CALC_FFMPEG_VERSION(56, 35, 0))
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}
-#endif
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(52, 42, 0)
#if defined(_MSC_VER)
AVRational avg_frame_rate = {frame_rate, frame_rate_base};
st->avg_frame_rate = avg_frame_rate;
#else
st->avg_frame_rate = (AVRational){frame_rate, frame_rate_base};
#endif
-#endif
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 20, 0)
st->time_base = c->time_base;
#endif
static const int OPENCV_NO_FRAMES_WRITTEN_CODE = 1000;
static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st,
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0)
uint8_t *, uint32_t,
-#else
- uint8_t * outbuf, uint32_t outbuf_size,
-#endif
AVFrame * picture )
{
-#if LIBAVFORMAT_BUILD > 4628
- AVCodecContext * c = video_st->codec;
-#else
- AVCodecContext * c = &(video_st->codec);
-#endif
+ AVCodecContext* c = video_st->codec;
int ret = OPENCV_NO_FRAMES_WRITTEN_CODE;
#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(57, 0, 0)
#else
AVPacket pkt;
av_init_packet(&pkt);
-#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0)
int got_output = 0;
pkt.data = NULL;
pkt.size = 0;
}
else
ret = OPENCV_NO_FRAMES_WRITTEN_CODE;
-#else
- int out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
- /* if zero size, it means the image was buffered */
- if (out_size > 0) {
-#if LIBAVFORMAT_BUILD > 4752
- if(c->coded_frame->pts != (int64_t)AV_NOPTS_VALUE)
- pkt.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_st->time_base);
-#else
- pkt.pts = c->coded_frame->pts;
-#endif
- if(c->coded_frame->key_frame)
- pkt.flags |= PKT_FLAG_KEY;
- pkt.stream_index= video_st->index;
- pkt.data= outbuf;
- pkt.size= out_size;
-
- /* write the compressed frame in the media file */
- ret = av_write_frame(oc, &pkt);
- }
-#endif
#endif
}
return ret;
height = frame_height;
// typecast from opaque data type to implemented struct
-#if LIBAVFORMAT_BUILD > 4628
- AVCodecContext *c = video_st->codec;
-#else
- AVCodecContext *c = &(video_st->codec);
-#endif
+ AVCodecContext* c = video_st->codec;
// FFmpeg contains SIMD optimizations which can sometimes read data past
// the supplied input buffer.
}
// free pictures
-#if LIBAVFORMAT_BUILD > 4628
if( video_st->codec->pix_fmt != input_pix_fmt)
-#else
- if( video_st->codec.pix_fmt != input_pix_fmt)
-#endif
{
if(picture->data[0])
free(picture->data[0]);
av_free(input_picture);
/* close codec */
-#if LIBAVFORMAT_BUILD > 4628
avcodec_close(video_st->codec);
-#else
- avcodec_close(&(video_st->codec));
-#endif
av_free(outbuf);
if (!(fmt->flags & AVFMT_NOFILE))
{
/* close the output file */
-
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(123<<8)+0)
-#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(49<<8)+0)
- url_fclose(oc->pb);
-#else
- url_fclose(&oc->pb);
-#endif
-#else
avio_close(oc->pb);
-#endif
-
}
/* free the stream */
/* auto detect the output format from the name and fourcc code. */
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
fmt = av_guess_format(NULL, filename, NULL);
-#else
- fmt = guess_format(NULL, filename, NULL);
-#endif
if (!fmt)
return false;
}
/* Lookup codec_id for given fourcc */
-#if LIBAVCODEC_VERSION_INT<((51<<16)+(49<<8)+0)
- if( (codec_id = codec_get_bmp_id( fourcc )) == CV_CODEC(CODEC_ID_NONE) )
- return false;
-#else
if( (codec_id = av_codec_get_id(fmt->codec_tag, fourcc)) == CV_CODEC(CODEC_ID_NONE) )
{
const struct AVCodecTag * fallback_tags[] = {
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0)
// APIchanges:
// 2012-01-31 - dd6d3b0 - lavf 54.01.0
// Add avformat_get_riff_video_tags() and avformat_get_riff_audio_tags().
avformat_get_riff_video_tags(),
-#endif
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 25, 100) && defined LIBAVFORMAT_VERSION_MICRO && LIBAVFORMAT_VERSION_MICRO >= 100
// APIchanges: ffmpeg only
// 2014-01-19 - 1a193c4 - lavf 55.25.100 - avformat.h
fourcc = supported_tag;
}
}
-#endif
// alloc memory for context
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
oc = avformat_alloc_context();
-#else
- oc = av_alloc_format_context();
-#endif
assert (oc);
/* set file name */
// set a few optimal pixel formats for lossless codecs of interest..
switch (codec_id) {
-#if LIBAVCODEC_VERSION_INT>((50<<16)+(1<<8)+0)
case CV_CODEC(CODEC_ID_JPEGLS):
// BGR24 or GRAY8 depending on is_color...
// supported: bgr24 rgb24 gray gray16le
// as of version 3.4.1
codec_pix_fmt = input_pix_fmt;
break;
-#endif
case CV_CODEC(CODEC_ID_HUFFYUV):
// supported: yuv422p rgb24 bgra
// as of version 3.4.1
break;
}
- double bitrate = MIN(bitrate_scale*fps*width*height, (double)INT_MAX/2);
+ double bitrate = std::min(bitrate_scale*fps*width*height, (double)INT_MAX/2);
// TODO -- safe to ignore output audio stream?
video_st = icv_add_video_stream_FFMPEG(oc, codec_id,
width, height, (int)(bitrate + 0.5),
fps, codec_pix_fmt);
- /* set the output parameters (must be done even if no
- parameters). */
-#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
- if (av_set_parameters(oc, NULL) < 0) {
- return false;
- }
-#endif
-
#if 0
#if FF_API_DUMP_FORMAT
dump_format(oc, 0, filename, 1);
return false;
}
- AVCodec *codec;
- AVCodecContext *c;
-
-#if LIBAVFORMAT_BUILD > 4628
- c = (video_st->codec);
-#else
- c = &(video_st->codec);
-#endif
+ AVCodecContext* c = video_st->codec;
c->codec_tag = fourcc;
/* find the video encoder */
- codec = avcodec_find_encoder(c->codec_id);
+ AVCodec* codec = avcodec_find_encoder(c->codec_id);
if (!codec) {
- fprintf(stderr, "Could not find encoder for codec id %d: %s\n", c->codec_id, icvFFMPEGErrStr(
- #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
- AVERROR_ENCODER_NOT_FOUND
- #else
- -1
- #endif
- ));
+ fprintf(stderr, "Could not find encoder for codec id %d: %s\n", c->codec_id,
+ icvFFMPEGErrStr(AVERROR_ENCODER_NOT_FOUND));
return false;
}
c->bit_rate = (int)lbit_rate;
/* open the codec */
- if ((err=
-#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
- avcodec_open2(c, codec, NULL)
-#else
- avcodec_open(c, codec)
-#endif
- ) < 0) {
+ if ((err= avcodec_open2(c, codec, NULL)) < 0) {
fprintf(stderr, "Could not open codec '%s': %s\n", codec->name, icvFFMPEGErrStr(err));
return false;
}
}
/* open the output file, if needed */
- if (!(fmt->flags & AVFMT_NOFILE)) {
-#if LIBAVFORMAT_BUILD < CALC_FFMPEG_VERSION(53, 2, 0)
- if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0)
-#else
- if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0)
-#endif
- {
+ if (!(fmt->flags & AVFMT_NOFILE))
+ {
+ if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0)
+ {
return false;
}
}
-#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
/* write the stream header, if any */
err=avformat_write_header(oc, NULL);
-#else
- err=av_write_header( oc );
-#endif
if(err < 0)
{