From c1ed4cf8075beb2ce098027ec35693ba0b3eaec8 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Tue, 20 Jun 2017 11:32:39 +1000 Subject: [PATCH] motion: h264 encoder respects quality settings --- package/motion/tune-h264-encode-quality.patch | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 package/motion/tune-h264-encode-quality.patch diff --git a/package/motion/tune-h264-encode-quality.patch b/package/motion/tune-h264-encode-quality.patch new file mode 100644 index 0000000000..29d561b3d9 --- /dev/null +++ b/package/motion/tune-h264-encode-quality.patch @@ -0,0 +1,33 @@ +diff --git a/ffmpeg.c b/ffmpeg.c +index 8f66121..9634a20 100644 +--- a/ffmpeg.c ++++ b/ffmpeg.c +@@ -451,20 +451,27 @@ static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1){ + static int ffmpeg_set_quality(struct ffmpeg *ffmpeg){ + + char crf[4]; ++ int bit_rate; + + ffmpeg->opts = 0; + if (ffmpeg->vbr > 100) ffmpeg->vbr = 100; + if (ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_H264 || + ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_HEVC){ + if (ffmpeg->vbr > 0) { ++ if (ffmpeg->vbr < 10) ffmpeg->vbr = 10; ++ //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; + } + snprintf(crf, 4, "%d",ffmpeg->vbr); +- av_dict_set(&ffmpeg->opts, "preset", "ultrafast", 0); ++ av_dict_set(&ffmpeg->opts, "preset", "slow", 0); + av_dict_set(&ffmpeg->opts, "tune", "zerolatency", 0); + av_dict_set(&ffmpeg->opts, "crf", crf, 0); ++ 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){