View Full Version : closed thread "suggestion for new x264-parameter"
akapuma
20th January 2012, 21:34
Hello,
the thread "suggestion for new x264-parameter" was closed today, because it was old. But I think, the idea was good. I made a small picture:
http://akapuma.info/externebilder/scenecut.png
1 - P/I = 1 - (bit size of P-frame) / (bit size of I-frame)
x264 calculates the blue curve with the parameters "scenecut" and "keyint". If 1-P/I is lower than the blue curve, an IDR frame is set.
Problem: often, the value 1-P/I is never less then the blue curve. In this case, the IDR frame is set after keyint is reached (here: 250). Depending on the movie, 50% of the IDR frames are set at "keyint"-position (here: 250). This is not good, because it's better to set an IDR frame at a scene change, not at a fixed value.
My idea was, to increase the sensitivity of the curve - see red curve. The result would be a more clever usage of IDR frames.
Example:
1-P/I at frame 240 is 45 ("small" scene change)
1-P/I at frame 250 is 90 (no scene change)
=> Blue curve: IDR is set at frame 250 - not reasonable
=> Red curve: IDR is set at frame 240 - reasonable
There are no hard cuts at position 250.
As makeshift, I use scenecut = 80 and keyint = 500. This is a linear extension of the blue curve. I know, that the gain is negligible. But theoretical, it's better.
Best regards
akapuma
Dark Shikari
20th January 2012, 22:15
Your comparison is nonsensical, because you are comparing keyint 500 to keyint 250.
The keyframe interval is a restriction on the encoder chosen for usability of the resulting stream. Any improved keyframe placement algorithm must abide by exactly the same limitation. Over 50% of the frames are placed at keyint 250... because most scenes last more than 10 seconds. If you don't care about keyframe interval, you can simply set it to infinite.
movmasty
21st January 2012, 18:20
Hello,
You are welcome. :cool:
movmasty
21st January 2012, 18:24
If you don't care about keyframe interval, you can simply set it to infinite.
How to write 'infinite' in the command?
Dont tell me that is to write <infinite>.......
movmasty
21st January 2012, 18:35
As makeshift, I use scenecut = 80 and keyint = 500. This is a linear extension of the blue curve. I know, that the gain is negligible. But theoretical, it's better.
also --min-keyint influences that displacement since scenecut could be at 505.
Right today i wanted to cut a clip at a scene change, but the keyframes were somewhere else, just before and just after,
the after was not at the max keyint, just in between change and max keyint,
very close to scene change to tell the truth, but not there.
We dont have to consider the x264 engine like a God.
upyzl
22nd January 2012, 03:31
How to write 'infinite' in the command?
Dont tell me that is to write <infinite>.......
--keyint infinite
MeteorRain
22nd January 2012, 05:02
also --min-keyint influences that displacement since scenecut could be at 505.
Right today i wanted to cut a clip at a scene change, but the keyframes were somewhere else, just before and just after,
the after was not at the max keyint, just in between change and max keyint,
very close to scene change to tell the truth, but not there.
We dont have to consider the x264 engine like a God.
i'm not quite sure, but can 2-pass solve the problem?
MatLz
22nd January 2012, 07:36
i'm not quite sure, but can 2-pass solve the problem?I don't think so. I think 2pass is part of the problem this clueless troll encounts. CRF should have been fine I guess.
Some direct show input + vfw + 2pass + clueless troll == problems
movmasty
22nd January 2012, 13:33
I don't think so. I think 2pass is part of the problem this clueless troll encounts. CRF should have been fine I guess.
Some direct show input + vfw + 2pass + clueless troll == problems
Does someone understands something in this syntax ?
movmasty
22nd January 2012, 13:35
i'm not quite sure, but can 2-pass solve the problem?
Dont think so since keyframes are decided in the first pass,
maybe nth passes.
MatLz
22nd January 2012, 16:13
Right today i wanted to cut a clip at a scene change, but the keyframes were somewhere else, just before and just after,
the after was not at the max keyint, just in between change and max keyint,
very close to scene change to tell the truth, but not there.
We dont have to consider the x264 engine like a God.Can you provide a source sample that does show the problem ?
How do you feed x264 with this source ?
What is the revision number of the x264 you used ?
The settings used ?
Without these informations, your statement is nothing else but trolling.
MeteorRain
26th January 2012, 11:28
Dont think so since keyframes are decided in the first pass,
maybe nth passes.
we could change the policy and let 2nd-pass do little tweak on key-framing. I mean, if we really need this.
Can you provide a source sample that does show the problem ?
How do you feed x264 with this source ?
What is the revision number of the x264 you used ?
The settings used ?
Without these informations, your statement is nothing else but trolling.
I would guess that, it's a 255 frames long continuous scene, with max-gop 250 and min-gop 10, which could potentially produce the problem?
But anyway, I think this is really not a big deal. You can always cut at key frames, and re-encode the first gop and join them together.
Juce
26th January 2012, 21:04
But if you're thinking about improving it, why not go for the optimal solution? Don't enforce keyint at all on the 1st pass, then the 2nd pass can insert keyframes wherever it needs to to minimize the bitrate cost while satisfying keyint. e.g. assume keyint 300 and it turns out that there was a good scenecut at frame 350, then the 2nd pass can pick any frame between 50 and 300 to become the extra keyframe.Is there a way atm to tell x264 to do this? :)I tried something:E:\testi\x264>x264 LosslessMaikaze.mkv --bitrate 1000 --pass 1 --ssim --tune ssim -o nul --keyint 48 --quiet
encoded 5000 frames, 33.61 fps, 1009.04 kb/s
E:\testi\x264>x264 LosslessMaikaze.mkv --bitrate 1000 --pass 2 --ssim --tune ssim -o nul --keyint 48
ffms [info]: 720x480p 1:1 @ 24000/1001 fps (vfr)
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Slow SlowCTZ
x264 [info]: profile High, level 3.0
x264 [info]: frame I:116 Avg QP: 9.85 size: 81826
x264 [info]: frame P:1482 Avg QP:14.01 size: 9429
x264 [info]: frame B:3402 Avg QP:18.51 size: 753
x264 [info]: consecutive B-frames: 6.7% 5.1% 7.7% 80.5%
x264 [info]: mb I I16..4: 19.0% 30.2% 50.7%
x264 [info]: mb P I16..4: 2.2% 1.5% 1.6% P16..4: 23.7% 9.6% 8.5% 0.0% 0
.0% skip:53.0%
x264 [info]: mb B I16..4: 0.2% 0.1% 0.0% B16..8: 13.6% 1.4% 0.2% direct:
1.1% skip:83.4% L0:41.8% L1:47.7% BI:10.5%
x264 [info]: 8x8 transform intra:29.2% inter:64.5%
x264 [info]: coded y,uvDC,uvAC intra: 70.0% 72.7% 60.3% inter: 8.4% 6.7% 1.8%
x264 [info]: i16 v,h,dc,p: 50% 20% 16% 14%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 19% 29% 4% 5% 5% 6% 5% 5%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 17% 17% 6% 7% 7% 7% 6% 6%
x264 [info]: i8c dc,h,v,p: 48% 20% 24% 8%
x264 [info]: Weighted P-Frames: Y:5.1% UV:4.3%
x264 [info]: ref P L0: 63.0% 6.1% 19.6% 11.3% 0.0%
x264 [info]: ref B L0: 78.3% 17.5% 4.2%
x264 [info]: ref B L1: 91.2% 8.8%
x264 [info]: SSIM Mean Y:0.9952056 (23.193db)
x264 [info]: kb/s:998.39
encoded 5000 frames, 13.78 fps, 998.39 kb/sE:\testi\x264>x264 LosslessMaikaze.mkv --crf 18 --pass 1 --ssim --tune ssim -o nul --keyint infinite --bframes 0 --quiet
encoded 5000 frames, 33.49 fps, 670.98 kb/s
E:\testi\x264>..\php\php mkqpfile.php > qpfile.txt
E:\testi\x264>x264 LosslessMaikaze.mkv --bitrate 1000 --pass 1 --ssim --tune ssim -o nul --keyint infinite --no-scenecut --qpfile qpfile.txt --quiet
encoded 5000 frames, 34.20 fps, 1008.65 kb/s
E:\testi\x264>x264 LosslessMaikaze.mkv --bitrate 1000 --pass 2 --ssim --tune ssim -o nul --keyint infinite --no-scenecut --qpfile qpfile.txt
ffms [info]: 720x480p 1:1 @ 24000/1001 fps (vfr)
x264 [info]: using SAR=1/1
x264 [info]: using cpu capabilities: MMX2 SSE2Slow SlowCTZ
x264 [info]: profile High, level 3.0
x264 [info]: frame I:114 Avg QP: 9.62 size: 83042
x264 [info]: frame P:1486 Avg QP:13.98 size: 9421
x264 [info]: frame B:3400 Avg QP:18.43 size: 757
x264 [info]: consecutive B-frames: 6.9% 5.1% 6.7% 81.3%
x264 [info]: mb I I16..4: 18.9% 31.3% 49.9%
x264 [info]: mb P I16..4: 2.1% 1.4% 1.5% P16..4: 24.1% 9.6% 8.4% 0.0% 0
.0% skip:52.9%
x264 [info]: mb B I16..4: 0.2% 0.1% 0.0% B16..8: 13.8% 1.4% 0.2% direct:
1.1% skip:83.2% L0:40.9% L1:48.8% BI:10.3%
x264 [info]: 8x8 transform intra:30.0% inter:64.4%
x264 [info]: coded y,uvDC,uvAC intra: 70.3% 72.9% 60.7% inter: 8.4% 6.8% 1.8%
x264 [info]: i16 v,h,dc,p: 49% 21% 16% 14%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 19% 29% 4% 5% 5% 6% 5% 5%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 17% 17% 6% 7% 7% 7% 6% 6%
x264 [info]: i8c dc,h,v,p: 48% 21% 24% 8%
x264 [info]: Weighted P-Frames: Y:5.0% UV:4.2%
x264 [info]: ref P L0: 63.3% 6.0% 19.5% 11.2% 0.0%
x264 [info]: ref B L0: 78.2% 17.3% 4.4%
x264 [info]: ref B L1: 90.9% 9.1%
x264 [info]: SSIM Mean Y:0.9952398 (23.224db)
x264 [info]: kb/s:998.94
encoded 5000 frames, 13.67 fps, 998.94 kb/smkqpfile.php:<?php
$log = file("x264_2pass.log");
$keyint_opt = 48;
$frames = array();
class Frame {
public $type;
public $imb;
public function __construct( $imb, $type = null ) {
$this->type = $type;
$this->imb = $imb;
}
}
function readint( $row, $opt ) {
sscanf( strstr( $row, $opt .':' ), $opt .':%d', &$val );
return $val;
}
function addkeybetween( $start, $end ) {
global $keyint_opt;
global $frames;
$count = ceil( ( $end - $start ) / $keyint_opt ) - 1;
if( $count < 1 ) return;
$tolerance = $keyint_opt * ( $count + 1 ) - ( $end - $start );
$maximb = -1;
$maximbindex = floor( $start + ( $end - $start ) / 2 );
for( $i = 1; $i <= $count; $i++ ) {
for( $j = 0; $j <= $tolerance; $j++ ) {
$index = $start + $i * $keyint_opt - $j;
if( !isset( $frames[$index] ) ) continue;
if( $frames[$index]->imb > $maximb ) {
$maximb = $frames[$index]->imb;
$maximbindex = $index;
}
}
}
if( isset( $frames[$maximbindex] ) ) $frames[$maximbindex]->type = 'I';
else {
$frames[$maximbindex] = new Frame( 0, 'I' );
ksort( $frames );
}
}
foreach($log as $key => &$row) {
$row = trim( $row );
if( empty( $row ) ) {
unset( $log[$key] );
continue;
}
if(strncasecmp('#', $row, 1) == 0) {
unset( $log[$key] );
continue;
}
}
foreach($log as &$row) {
$index = readint( $row, 'in' );
$imb = readint( $row, 'imb' );
sscanf( strstr( $row, 'type:' ), 'type:%1s', &$type );
$frames[$index] = new Frame( $imb, $type );
}
unset( $log );
ksort( $frames );
$framecount = 0;
foreach($frames as $i => &$row) {
if( $i > $framecount ) $framecount = $i;
}
$framecount++;
do {
$incomplete = false;
$previous = 0;
foreach($frames as $i => &$frame) {
if( $frame->type == 'I' ) {
if( $i - $previous > $keyint_opt ) {
$incomplete = true;
addkeybetween( $previous, $i );
}
$previous = $i;
}
else continue;
}
if( $framecount - $previous > $keyint_opt ) {
$incomplete = true;
addkeybetween( $previous, $framecount );
}
} while( $incomplete == true );
ksort( $frames );
foreach($frames as $i => &$frame) {
if( $frame->type == 'I' || $frame->type == 'i' ) echo $i .' '. $frame->type ."\n";
}
exit;
?>SSIM is improved slightly, but is it worth the effort?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.