From 32b43866f8cdfb9a3246caff69c99b6f0f030f9c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Sep 2015 11:42:40 -0500 Subject: [PATCH] FS-8240 add video profile param for recording 264 and make it default --- src/include/switch_module_interfaces.h | 8 +++++ src/mod/applications/mod_av/avformat.c | 43 +++++++++++++++++++------- src/switch_core_file.c | 13 ++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index feb9337d54..1d31bc8b88 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -305,6 +305,12 @@ typedef enum { SWITCH_VIDEO_ENCODE_SPEED_FAST } switch_video_encode_speed_t; +typedef enum { + SWITCH_VIDEO_PROFILE_BASELINE, + SWITCH_VIDEO_PROFILE_MAIN, + SWITCH_VIDEO_PROFILE_HIGH +} switch_video_profile_t; + typedef struct switch_mm_s { int samplerate; int channels; @@ -314,7 +320,9 @@ typedef struct switch_mm_s { int vw; int vh; float fps; + float source_fps; int vbuf; + switch_video_profile_t vprofile; switch_video_encode_speed_t vencspd; } switch_mm_t; diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 6b1accb7c1..ab3fc2b9ce 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -312,18 +312,34 @@ static switch_status_t add_stream(MediaStream *mst, AVFormatContext *fc, AVCodec if (codec_id == AV_CODEC_ID_H264) { c->ticks_per_frame = 2; + switch (mm->vprofile) { + case SWITCH_VIDEO_PROFILE_BASELINE: + av_opt_set(c->priv_data, "profile", "baseline", 0); + c->level = 41; + break; + case SWITCH_VIDEO_PROFILE_MAIN: + av_opt_set(c->priv_data, "profile", "main", 0); + av_opt_set(c->priv_data, "level", "5", 0); + break; + case SWITCH_VIDEO_PROFILE_HIGH: + av_opt_set(c->priv_data, "profile", "high", 0); + av_opt_set(c->priv_data, "level", "52", 0); + break; + } + switch (mm->vencspd) { - case SWITCH_VIDEO_ENCODE_SPEED_SLOW: - av_opt_set(c->priv_data, "preset", "veryslow", 0); - break; - case SWITCH_VIDEO_ENCODE_SPEED_MEDIUM: - av_opt_set(c->priv_data, "preset", "medium", 0); - break; - case SWITCH_VIDEO_ENCODE_SPEED_FAST: - av_opt_set(c->priv_data, "preset", "ultrafast", 0); - break; - default: - break; + case SWITCH_VIDEO_ENCODE_SPEED_SLOW: + av_opt_set(c->priv_data, "preset", "veryslow", 0); + break; + case SWITCH_VIDEO_ENCODE_SPEED_MEDIUM: + av_opt_set(c->priv_data, "preset", "medium", 0); + break; + case SWITCH_VIDEO_ENCODE_SPEED_FAST: + av_opt_set(c->priv_data, "preset", "veryfast", 0); + av_opt_set(c->priv_data, "tune", "zerolatency", 0); + break; + default: + break; } } @@ -1147,7 +1163,8 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) { context->has_video = 1; } - context->read_fps = (int)ceil(av_q2d(context->video_st.st->avg_frame_rate)); + handle->mm.source_fps = ceil(av_q2d(context->video_st.st->avg_frame_rate)); + context->read_fps = (int)handle->mm.source_fps; } } @@ -1510,6 +1527,8 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa handle->samplerate = 44100; handle->mm.samplerate = 44100; handle->mm.ab = 128; + //handle->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_FAST; + handle->mm.vprofile = SWITCH_VIDEO_PROFILE_BASELINE; if (!handle->mm.vb && handle->mm.vw && handle->mm.vh) { switch(handle->mm.vh) { diff --git a/src/switch_core_file.c b/src/switch_core_file.c index 69433dbdb2..c6d92ded06 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -85,6 +85,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, fh->mm.keyint = 60; fh->mm.ab = 128; fh->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_DEFAULT; + fh->mm.vprofile = SWITCH_VIDEO_PROFILE_BASELINE; if (*file_path == '{') { char *timeout; @@ -199,6 +200,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid video encode speed: %s\n", val); } } + + if ((val = switch_event_get_header(fh->params, "vprofile"))) { + if (!strcasecmp(val, "baseline")) { + fh->mm.vprofile = SWITCH_VIDEO_PROFILE_BASELINE; + } else if (!strcasecmp(val, "main")) { + fh->mm.vprofile = SWITCH_VIDEO_PROFILE_MAIN; + } else if (!strcasecmp(val, "high")) { + fh->mm.vprofile = SWITCH_VIDEO_PROFILE_HIGH; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid video profile: %s\n", val); + } + } } if (switch_directory_exists(file_path, fh->memory_pool) == SWITCH_STATUS_SUCCESS) {