From 6ba62abe6425e30911b934cc461421df9c7a615a Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Thu, 17 Aug 2017 12:56:33 +1000 Subject: [PATCH] motion: only tune h264_omx encode quality --- package/motion/tune-h264-encode-quality.patch | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/package/motion/tune-h264-encode-quality.patch b/package/motion/tune-h264-encode-quality.patch index 0f78b6fc78..994754f022 100644 --- a/package/motion/tune-h264-encode-quality.patch +++ b/package/motion/tune-h264-encode-quality.patch @@ -1,8 +1,8 @@ diff --git a/ffmpeg.c b/ffmpeg.c -index a4d3757..124b41f 100644 +index a4d3757..368c855 100644 --- a/ffmpeg.c +++ b/ffmpeg.c -@@ -451,21 +451,29 @@ static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1){ +@@ -451,7 +451,7 @@ static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1){ static int ffmpeg_set_quality(struct ffmpeg *ffmpeg){ @@ -11,13 +11,12 @@ index a4d3757..124b41f 100644 ffmpeg->opts = 0; if (ffmpeg->vbr > 100) ffmpeg->vbr = 100; - if (ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_H264 || +@@ -459,13 +459,24 @@ static int ffmpeg_set_quality(struct ffmpeg *ffmpeg){ ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_HEVC){ if (ffmpeg->vbr > 0) { -+ if (ffmpeg->vbr < 10) ffmpeg->vbr = 10; + ffmpeg->vbr = (int)(( (100-ffmpeg->vbr) * 51)/100); + //bit_rate = ffmpeg->width * ffmpeg->height * ffmpeg->fps * quality_factor + bit_rate = (ffmpeg->width * ffmpeg->height * ffmpeg->fps * ffmpeg->vbr) >> 8; - ffmpeg->vbr = (int)(( (100-ffmpeg->vbr) * 51)/100); } else { + bit_rate = ffmpeg->bps; ffmpeg->vbr = 28; @@ -26,14 +25,18 @@ index a4d3757..124b41f 100644 - av_dict_set(&ffmpeg->opts, "preset", "ultrafast", 0); - av_dict_set(&ffmpeg->opts, "tune", "zerolatency", 0); - av_dict_set(&ffmpeg->opts, "crf", crf, 0); -+ // Clip to max bit rate -+ if (bit_rate > 2500000) -+ bit_rate = 2500000; + av_dict_set(&ffmpeg->opts, "preset", "ultrafast", 0); + av_dict_set(&ffmpeg->opts, "tune", "zerolatency", 0); + av_dict_set_int(&ffmpeg->opts, "crf", ffmpeg->vbr, 0); -+ ffmpeg->ctx_codec->profile = FF_PROFILE_H264_HIGH; -+ ffmpeg->ctx_codec->bit_rate = bit_rate; ++ if ((strcmp(ffmpeg->codec->name, "h264_omx") == 0) || (strcmp(ffmpeg->codec->name, "mpeg4_omx") == 0)) { ++ // Clip bit rate to min and max ++ if (bit_rate < 40000) ++ bit_rate = 40000; ++ else if (bit_rate > 3000000) ++ bit_rate = 3000000; ++ ffmpeg->ctx_codec->profile = FF_PROFILE_H264_HIGH; ++ ffmpeg->ctx_codec->bit_rate = bit_rate; ++ } } else { /* The selection of 8000 in the else is a subjective number based upon viewing output files */ if (ffmpeg->vbr > 0){