FS-8240 add video profile param for recording 264 and make it default

This commit is contained in:
Anthony Minessale 2015-09-30 11:42:40 -05:00
parent e7cbb77e54
commit 32b43866f8
3 changed files with 52 additions and 12 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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) {