-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup avformat-based preprocessors (#2665)
- Loading branch information
Showing
9 changed files
with
281 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*! \file pp-avformat.c | ||
* \copyright GNU General Public License v3 | ||
* | ||
* \ingroup postprocessing | ||
* \ref postprocessing | ||
*/ | ||
|
||
#include "pp-avformat.h" | ||
|
||
void janus_pp_setup_avformat(void) { | ||
/* Setup FFmpeg */ | ||
#if ( LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,9,100) ) | ||
av_register_all(); | ||
#endif | ||
/* Adjust logging to match the postprocessor's */ | ||
av_log_set_level(janus_log_level <= LOG_NONE ? AV_LOG_QUIET : | ||
(janus_log_level == LOG_FATAL ? AV_LOG_FATAL : | ||
(janus_log_level == LOG_ERR ? AV_LOG_ERROR : | ||
(janus_log_level == LOG_WARN ? AV_LOG_WARNING : | ||
(janus_log_level == LOG_INFO ? AV_LOG_INFO : | ||
(janus_log_level == LOG_VERB ? AV_LOG_VERBOSE : AV_LOG_DEBUG)))))); | ||
|
||
} | ||
|
||
AVFormatContext *janus_pp_create_avformatcontext(const char *format, const char *metadata, const char *destination) { | ||
janus_pp_setup_avformat(); | ||
|
||
AVFormatContext *ctx = avformat_alloc_context(); | ||
if(!ctx) | ||
return NULL; | ||
|
||
/* We save the metadata part as a comment (see #1189) */ | ||
if(metadata) | ||
av_dict_set(&ctx->metadata, "comment", metadata, 0); | ||
|
||
ctx->oformat = av_guess_format(format, NULL, NULL); | ||
if(ctx->oformat == NULL) { | ||
JANUS_LOG(LOG_ERR, "Error guessing format\n"); | ||
avformat_free_context(ctx); | ||
return NULL; | ||
} | ||
|
||
int res = avio_open(&ctx->pb, destination, AVIO_FLAG_WRITE); | ||
if(res < 0) { | ||
JANUS_LOG(LOG_ERR, "Error opening file for output (%d)\n", res); | ||
avformat_free_context(ctx); | ||
return NULL; | ||
} | ||
|
||
return ctx; | ||
} | ||
|
||
AVStream *janus_pp_new_audio_avstream(AVFormatContext *fctx, int codec_id, int samplerate, int channels, const uint8_t *extradata, int size) { | ||
AVStream *st = avformat_new_stream(fctx, NULL); | ||
if(!st) | ||
return NULL; | ||
|
||
#ifdef USE_CODECPAR | ||
AVCodecParameters *c = st->codecpar; | ||
#else | ||
AVCodecContext *c = st->codec; | ||
#endif | ||
c->codec_id = codec_id; | ||
c->codec_type = AVMEDIA_TYPE_AUDIO; | ||
c->sample_rate = samplerate; | ||
c->channels = channels; | ||
if(extradata) { | ||
c->extradata_size = size; | ||
c->extradata = av_memdup(extradata, size); | ||
} | ||
|
||
return st; | ||
} | ||
|
||
AVStream *janus_pp_new_video_avstream(AVFormatContext *fctx, int codec_id, int width, int height) { | ||
AVStream *st = avformat_new_stream(fctx, NULL); | ||
if(!st) | ||
return NULL; | ||
|
||
#ifdef USE_CODECPAR | ||
AVCodecParameters *c = st->codecpar; | ||
#else | ||
AVCodecContext *c = st->codec; | ||
#endif | ||
c->codec_id = codec_id; | ||
c->codec_type = AVMEDIA_TYPE_VIDEO; | ||
c->width = width; | ||
c->height = height; | ||
|
||
return st; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*! \file pp-avformat.h | ||
* \copyright GNU General Public License v3 | ||
* | ||
* \ingroup postprocessing | ||
* \ref postprocessing | ||
*/ | ||
|
||
#ifndef JANUS_PP_AVFORMAT | ||
#define JANUS_PP_AVFORMAT | ||
|
||
#include "../debug.h" | ||
|
||
#include <libavcodec/avcodec.h> | ||
#include <libavformat/avformat.h> | ||
|
||
#define LIBAVCODEC_VER_AT_LEAST(major, minor) \ | ||
(LIBAVCODEC_VERSION_MAJOR > major || \ | ||
(LIBAVCODEC_VERSION_MAJOR == major && \ | ||
LIBAVCODEC_VERSION_MINOR >= minor)) | ||
|
||
#if LIBAVCODEC_VER_AT_LEAST(51, 42) | ||
#define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P | ||
#endif | ||
|
||
#if LIBAVCODEC_VER_AT_LEAST(56, 56) | ||
#ifndef CODEC_FLAG_GLOBAL_HEADER | ||
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER | ||
#endif | ||
#ifndef FF_INPUT_BUFFER_PADDING_SIZE | ||
#define FF_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE | ||
#endif | ||
#endif | ||
|
||
#if LIBAVCODEC_VER_AT_LEAST(57, 14) | ||
#define USE_CODECPAR | ||
#endif | ||
|
||
void janus_pp_setup_avformat(void); | ||
|
||
AVFormatContext *janus_pp_create_avformatcontext(const char *format, const char *metadata, const char *destination); | ||
|
||
AVStream *janus_pp_new_video_avstream(AVFormatContext *fctx, int codec_id, int width, int height); | ||
AVStream *janus_pp_new_audio_avstream(AVFormatContext *fctx, int codec_id, int samplerate, int channels, const uint8_t *extradata, int size); | ||
|
||
|
||
#endif |
Oops, something went wrong.