From 094443aeaf2f073aabf03da701dfef5e3527bec8 Mon Sep 17 00:00:00 2001 From: odrling Date: Sat, 24 Apr 2021 17:26:03 +0200 Subject: [PATCH] media-video/x264-encoder: add some patches from aMod --- media-video/x264-encoder/files/enc-time.diff | 73 ++++++++++++++ media-video/x264-encoder/files/est-size.diff | 39 ++++++++ media-video/x264-encoder/files/fadecomp.diff | 96 +++++++++++++++++++ .../x264-encoder/x264-encoder-9999.ebuild | 2 +- 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 media-video/x264-encoder/files/enc-time.diff create mode 100644 media-video/x264-encoder/files/est-size.diff create mode 100644 media-video/x264-encoder/files/fadecomp.diff diff --git a/media-video/x264-encoder/files/enc-time.diff b/media-video/x264-encoder/files/enc-time.diff new file mode 100644 index 0000000..cb9a9c5 --- /dev/null +++ b/media-video/x264-encoder/files/enc-time.diff @@ -0,0 +1,73 @@ +diff -uNrp ./x264.logfile/x264.c ./x264.enctime/x264.c +--- ./x264.logfile/x264.c 2018-05-04 20:38:52.735094600 +0300 ++++ ./x264.enctime/x264.c 2018-05-04 20:50:15.213061200 +0300 +@@ -1910,11 +1910,24 @@ static int encode_frame( x264_t *h, hnd_ + + static int64_t print_status( int64_t i_start, int64_t i_previous, int i_frame, int i_frame_total, int64_t i_file, x264_param_t *param, int64_t last_ts ) + { ++ static int print_progress_header = 1; + char buf[200]; + int64_t i_time = x264_mdate(); + if( i_previous && i_time - i_previous < UPDATE_INTERVAL ) + return i_previous; ++ ++ if( print_progress_header ) ++ { ++ if( i_frame_total ) ++ fprintf( stderr, " %6s %13s %5s %8s %9s %9s\n", ++ "", "frames ", "fps ", "kb/s ", "elapsed", "remain " ); ++ else ++ fprintf( stderr, "%6s %5s %8s %9s\n", "frames", "fps ", "kb/s ", "elapsed" ); ++ print_progress_header = 0; ++ } ++ + int64_t i_elapsed = i_time - i_start; ++ int secs = i_elapsed / 1000000; + double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0; + double bitrate; + if( last_ts ) +@@ -1924,12 +1937,13 @@ static int64_t print_status( int64_t i_s + if( i_frame_total ) + { + int eta = i_elapsed * (i_frame_total - i_frame) / ((int64_t)i_frame * 1000000); +- sprintf( buf, "x264 [%.1f%%] %d/%d frames, %.2f fps, %.2f kb/s, eta %d:%02d:%02d", ++ sprintf( buf, "x264 [%5.1f%%] %6d/%-6d %5.2f %8.2f %3d:%02d:%02d %3d:%02d:%02d", + 100. * i_frame / i_frame_total, i_frame, i_frame_total, fps, bitrate, +- eta/3600, (eta/60)%60, eta%60 ); ++ secs/3600, (secs/60)%60, secs%60, eta/3600, (eta/60)%60, eta%60 ); + } + else +- sprintf( buf, "x264 %d frames: %.2f fps, %.2f kb/s", i_frame, fps, bitrate ); ++ sprintf( buf, "x264 %6d %5.2f %8.2f %3d:%02d:%02d", ++ i_frame, fps, bitrate, secs/3600, (secs/60)%60, secs%60 ); + fprintf( stderr, "%s \r", buf+5 ); + x264_cli_set_console_title( buf ); + fflush( stderr ); // needed in windows +@@ -2116,8 +2130,11 @@ fail: + + i_end = x264_mdate(); + /* Erase progress indicator before printing encoding stats. */ +- if( opt->b_progress ) +- fprintf( stderr, " \r" ); ++ if( opt->b_progress && i_frame_output ) ++ { ++ print_status( i_start, 0, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts ); ++ fprintf( stderr, "\n" ); ++ } + if( h ) + x264_encoder_close( h ); + fprintf( stderr, "\n" ); +@@ -2132,9 +2149,11 @@ fail: + { + double fps = (double)i_frame_output * (double)1000000 / + (double)( i_end - i_start ); ++ int secs = (i_end - i_start) / 1000000; + +- x264_cli_printf( X264_LOG_INFO, "encoded %d frames, %.2f fps, %.2f kb/s\n", i_frame_output, fps, +- (double) i_file * 8 / ( 1000 * duration ) ); ++ x264_cli_printf( X264_LOG_INFO, "encoded %d frames, %.2f fps, %.2f kb/s, duration %d:%02d:%02d.%02d\n", i_frame_output, fps, ++ (double) i_file * 8 / ( 1000 * duration ), ++ secs/3600, (secs/60)%60, secs%60, (int)((i_end - i_start)%1000000/10000) ); + } + + return retval; diff --git a/media-video/x264-encoder/files/est-size.diff b/media-video/x264-encoder/files/est-size.diff new file mode 100644 index 0000000..309ba64 --- /dev/null +++ b/media-video/x264-encoder/files/est-size.diff @@ -0,0 +1,39 @@ +diff -uNrp ./x264.003/x264.c ./x264.004/x264.c +--- ./x264.003/x264.c 2018-05-05 00:03:09.866224400 +0300 ++++ ./x264.004/x264.c 2018-05-05 00:04:33.918824700 +0300 +@@ -1919,10 +1919,10 @@ static int64_t print_status( int64_t i_s + if( print_progress_header ) + { + if( i_frame_total ) +- fprintf( stderr, " %6s %13s %5s %8s %9s %9s\n", +- "", "frames ", "fps ", "kb/s ", "elapsed", "remain " ); ++ fprintf( stderr, " %6s %13s %5s %8s %9s %9s %7s %7s\n", ++ "", "frames ", "fps ", "kb/s ", "elapsed", "remain ", "size", "est.size" ); + else +- fprintf( stderr, "%6s %5s %8s %9s\n", "frames", "fps ", "kb/s ", "elapsed" ); ++ fprintf( stderr, "%6s %5s %8s %9s %7s\n", "frames", "fps ", "kb/s ", "elapsed", "size" ); + print_progress_header = 0; + } + +@@ -1937,13 +1937,17 @@ static int64_t print_status( int64_t i_s + if( i_frame_total ) + { + int eta = i_elapsed * (i_frame_total - i_frame) / ((int64_t)i_frame * 1000000); +- sprintf( buf, "x264 [%5.1f%%] %6d/%-6d %5.2f %8.2f %3d:%02d:%02d %3d:%02d:%02d", ++ double estsz = (double) i_file * i_frame_total / (i_frame * 1024.); ++ sprintf( buf, "x264 [%5.1f%%] %6d/%-6d %5.2f %8.2f %3d:%02d:%02d %3d:%02d:%02d %7.2f %1sB %7.2f %1sB", + 100. * i_frame / i_frame_total, i_frame, i_frame_total, fps, bitrate, +- secs/3600, (secs/60)%60, secs%60, eta/3600, (eta/60)%60, eta%60 ); ++ secs/3600, (secs/60)%60, secs%60, eta/3600, (eta/60)%60, eta%60, ++ i_file < 1048576 ? (double) i_file / 1024. : (double) i_file / 1048576., i_file < 1048576 ? "K":"M", ++ estsz < 1024 ? estsz : estsz / 1024, estsz < 1024 ? "K" : "M" ); + } + else +- sprintf( buf, "x264 %6d %5.2f %8.2f %3d:%02d:%02d", +- i_frame, fps, bitrate, secs/3600, (secs/60)%60, secs%60 ); ++ sprintf( buf, "x264 %6d %5.2f %8.2f %3d:%02d:%02d %7.2f %sB", ++ i_frame, fps, bitrate, secs/3600, (secs/60)%60, secs%60, ++ i_file < 1048576 ? (double) i_file / 1024. : (double) i_file / 1048576., i_file < 1048576 ? "K":"M" ); + fprintf( stderr, "%s \r", buf+5 ); + x264_cli_set_console_title( buf ); + fflush( stderr ); // needed in windows diff --git a/media-video/x264-encoder/files/fadecomp.diff b/media-video/x264-encoder/files/fadecomp.diff new file mode 100644 index 0000000..205a78c --- /dev/null +++ b/media-video/x264-encoder/files/fadecomp.diff @@ -0,0 +1,96 @@ +diff -uNrp ./x264.opts1/common/base.c ./x264.opts2/common/base.c +--- ./x264.opts1/common/base.c 2018-05-04 19:38:38.702651100 +0300 ++++ ./x264.opts2/common/base.c 2018-05-04 19:39:02.143412100 +0300 +@@ -1244,6 +1244,8 @@ int x264_param_parse( x264_param_t *p, c + p->rc.i_aq_mode = atoi(value); + OPT("aq-strength") + p->rc.f_aq_strength = atof(value); ++ OPT("fade-compensate") ++ p->rc.f_fade_compensate = atof(value); + OPT("pass") + { + int pass = x264_clip3( atoi(value), 0, 3 ); +@@ -1382,7 +1384,10 @@ char *x264_param2string( x264_param_t *p + s += sprintf( s, " subme=%d", p->analyse.i_subpel_refine ); + s += sprintf( s, " psy=%d", p->analyse.b_psy ); + if( p->analyse.b_psy ) +- s += sprintf( s, " psy_rd=%.2f:%.2f", p->analyse.f_psy_rd, p->analyse.f_psy_trellis ); ++ { ++ s += sprintf( s, " fade_compensate=%.2f", p->rc.f_fade_compensate ); ++ s += sprintf( s, " psy_rd=%.2f:%.2f", p->analyse.f_psy_rd, p->analyse.f_psy_trellis ); ++ } + s += sprintf( s, " mixed_ref=%d", p->analyse.b_mixed_references ); + s += sprintf( s, " me_range=%d", p->analyse.i_me_range ); + s += sprintf( s, " chroma_me=%d", p->analyse.b_chroma_me ); +diff -uNrp ./x264.opts1/encoder/encoder.c ./x264.opts2/encoder/encoder.c +--- ./x264.opts1/encoder/encoder.c 2018-05-04 19:38:33.636593300 +0300 ++++ ./x264.opts2/encoder/encoder.c 2018-05-04 19:39:02.149407400 +0300 +@@ -1124,10 +1124,15 @@ static int validate_parameters( x264_t * + x264_log( h, X264_LOG_WARNING, "--tune %s should be used if attempting to benchmark %s!\n", s, s ); + } + ++ if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_NONE ) ++ h->param.rc.f_fade_compensate += 0.1; ++ if( !h->param.rc.b_mb_tree ) ++ h->param.rc.f_fade_compensate = 0; + if( !h->param.analyse.b_psy ) + { + h->param.analyse.f_psy_rd = 0; + h->param.analyse.f_psy_trellis = 0; ++ h->param.rc.f_fade_compensate = 0; + } + h->param.analyse.f_psy_rd = x264_clip3f( h->param.analyse.f_psy_rd, 0, 10 ); + h->param.analyse.f_psy_trellis = x264_clip3f( h->param.analyse.f_psy_trellis, 0, 10 ); +diff -uNrp ./x264.opts1/encoder/slicetype.c ./x264.opts2/encoder/slicetype.c +--- ./x264.opts1/encoder/slicetype.c 2018-05-04 19:47:15.672399600 +0300 ++++ ./x264.opts2/encoder/slicetype.c 2018-05-04 19:47:16.695603800 +0300 +@@ -451,7 +451,7 @@ void x264_weights_analyse( x264_t *h, x2 + else + SET_WEIGHT( weights[plane], 1, minscale, mindenom, minoff ); + +- if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_FAKE && weights[0].weightfn && !plane ) ++ if( weights[0].weightfn && !plane ) + fenc->f_weighted_cost_delta[i_delta_index] = (float)minscore / origscore; + } + +@@ -1023,7 +1023,7 @@ static void macroblock_tree_finish( x264 + int fps_factor = round( CLIP_DURATION(average_duration) / CLIP_DURATION(frame->f_duration) * 256 / MBTREE_PRECISION ); + float weightdelta = 0.0; + if( ref0_distance && frame->f_weighted_cost_delta[ref0_distance-1] > 0 ) +- weightdelta = (1.0 - frame->f_weighted_cost_delta[ref0_distance-1]); ++ weightdelta = (1.0 - frame->f_weighted_cost_delta[ref0_distance-1]) * 10.0f * h->param.rc.f_fade_compensate; + + /* Allow the strength to be adjusted via qcompress, since the two + * concepts are very similar. */ +Binary files ./x264.opts1/x264.7z and ./x264.opts2/x264.7z differ +diff -uNrp ./x264.opts1/x264.c ./x264.opts2/x264.c +--- ./x264.opts1/x264.c 2018-05-04 19:38:38.713642700 +0300 ++++ ./x264.opts2/x264.c 2018-05-04 19:39:02.169391900 +0300 +@@ -815,6 +815,8 @@ static void help( x264_param_t *defaults + " - 3: Auto-variance AQ with bias to dark scenes\n", defaults->rc.i_aq_mode ); + H1( " --aq-strength Reduces blocking and blurring in flat and\n" + " textured areas. [%.1f]\n", defaults->rc.f_aq_strength ); ++ H1( " --fade-compensate Allocate more bits to fades [%.1f]\n", defaults->rc.f_fade_compensate ); ++ H2( " Approximate sane range: 0.0 - 1.0\n" ); + H1( "\n" ); + H0( " -p, --pass Enable multipass ratecontrol\n" + " - 1: First pass, creates stats file\n" +@@ -1155,6 +1157,7 @@ static struct option long_options[] = + { "no-dct-decimate", no_argument, NULL, 0 }, + { "aq-strength", required_argument, NULL, 0 }, + { "aq-mode", required_argument, NULL, 0 }, ++ { "fade-compensate", required_argument, NULL, 0 }, + { "deadzone-inter", required_argument, NULL, 0 }, + { "deadzone-intra", required_argument, NULL, 0 }, + { "level", required_argument, NULL, 0 }, +diff -uNrp ./x264.opts1/x264.h ./x264.opts2/x264.h +--- ./x264.opts1/x264.h 2018-05-04 19:38:38.724634000 +0300 ++++ ./x264.opts2/x264.h 2018-05-04 19:39:02.174387800 +0300 +@@ -445,6 +445,7 @@ typedef struct x264_param_t + + int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */ + float f_aq_strength; ++ float f_fade_compensate; /* Give more bits to fades. */ + int b_mb_tree; /* Macroblock-tree ratecontrol. */ + int i_lookahead; + diff --git a/media-video/x264-encoder/x264-encoder-9999.ebuild b/media-video/x264-encoder/x264-encoder-9999.ebuild index 2189526..b848c94 100644 --- a/media-video/x264-encoder/x264-encoder-9999.ebuild +++ b/media-video/x264-encoder/x264-encoder-9999.ebuild @@ -37,7 +37,7 @@ DEPEND="${RDEPEND} x86-fbsd? ( ${ASM_DEP} )" BDEPEND="virtual/pkgconfig" -PATCHES=() +PATCHES=( ${FILESDIR}/enc-time.diff ${FILESDIR/enc-size.diff} ${FILESDIR}/fadecomp.diff ) src_prepare() { default