diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 88387033cc..a0d7c592a7 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -298,6 +298,13 @@ struct switch_file_interface { struct switch_file_interface *next; }; +typedef enum { + SWITCH_VIDEO_ENCODE_SPEED_DEFAULT; + SWITCH_VIDEO_ENCODE_SPEED_SLOW, + SWITCH_VIDEO_ENCODE_SPEED_MEDIUM, + SWITCH_VIDEO_ENCODE_SPEED_FAST +} switch_video_encode_speed_t; + typedef struct switch_mm_s { int samplerate; int channels; @@ -308,6 +315,7 @@ typedef struct switch_mm_s { int vh; float fps; int vbuf; + switch_video_encode_speed_t vencspd; } switch_mm_t; /*! an abstract representation of a file handle (some parameters based on compat with libsndfile) */ diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index bc6ef65128..02420c2899 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -299,6 +299,20 @@ 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->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; + } } if (codec_id == AV_CODEC_ID_VP8) { diff --git a/src/switch_core_file.c b/src/switch_core_file.c index 1ed96db3d3..69433dbdb2 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -84,6 +84,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, fh->mm.channels = 1; fh->mm.keyint = 60; fh->mm.ab = 128; + fh->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_DEFAULT; if (*file_path == '{') { char *timeout; @@ -186,6 +187,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid buffer size: %d\n", tmp); } } + + if ((val = switch_event_get_header(fh->params, "vencspd"))) { + if (!strcasecmp(val, "slow")) { + fh->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_SLOW; + } else if (!strcasecmp(val, "medium")) { + fh->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_MEDIUM; + } else if (!strcasecmp(val, "fast")) { + fh->mm.vencspd = SWITCH_VIDEO_ENCODE_SPEED_FAST; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid video encode speed: %s\n", val); + } + } } if (switch_directory_exists(file_path, fh->memory_pool) == SWITCH_STATUS_SUCCESS) {