Proryanator / encoder-benchmark

A tool to benchmark your hardware's real-time video encoding capabilities.
GNU General Public License v3.0
63 stars 5 forks source link

Add option to allow HEVC on devices that can't encode B frames #28

Closed e-dong closed 3 weeks ago

e-dong commented 9 months ago

I tried running the encoder benchmark on my linux laptop and I ran into this error:

[yuv4mpegpipe @ 0x5613eff6e6c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, yuv4mpegpipe, from '1080-120.y4m':
  Duration: 00:00:19.86, start: 0.000000, bitrate: 2985989 kb/s
  Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p(tv, progressive), 1920x1080, 120 fps, 120 tbr, 120 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
[hevc_nvenc @ 0x5613eff71a00] B frames as references are not supported
[hevc_nvenc @ 0x5613eff71a00] No capable devices found

According to https://github.com/GyanD/codexffmpeg/issues/78, adding -b_ref_mode 0 fixes this issue.

Applied it to this!

    pub fn get_benchmark_settings(&self) -> String {
        return format!("-preset p1 -tune ll -profile:v {} -rc cbr -cbr true -gpu {} -b_ref_mode 0", self.profiles.get(0).unwrap(), self.gpu);
    }

Boom, it's working!

[eric@ezekiel ~/repos/encoder-benchmark]$ cargo run --bin benchmark
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/benchmark`
  ___                        _                     ___                     _                           _   
 | __|  _ _    __   ___   __| |  ___   _ _   ___  | _ )  ___   _ _    __  | |_    _ __    __ _   _ _  | |__
 | _|  | ' \  / _| / _ \ / _` | / -_) | '_| |___| | _ \ / -_) | ' \  / _| | ' \  | '  \  / _` | | '_| | / /
 |___| |_||_| \__| \___/ \__,_| \___| |_|         |___/ \___| |_||_| \__| |_||_| |_|_|_| \__,_| |_|   |_\_\

Version v0.6.0-alpha
Source code: https://github.com/Proryanator/encoder-benchmark

[0] - h264_nvenc
[1] - hevc_nvenc
[2] - h264_amf
[3] - hevc_amf
[4] - h264_qsv
[5] - hevc_qsv
[6] - av1_qsv
Choose encoder [0-6]: 1

Run decode benchmark along with encode benchmark? [y/n]: y

Run full benchmark? [y/n]: n
[0] - 720-60.y4m
[1] - 720-120.y4m
[2] - 1080-60.y4m
[3] - 1080-120.y4m
[4] - 2k-60.y4m
[5] - 2k-120.y4m
[6] - 4k-60.y4m
[7] - 4k-120.y4m

Choose video file to encode [0-7]: 3

Run with verbose mode? [y/n]: y

[Permutation:   1/2]
[Encode Benchmark]
[Resolution:    1920x1080]
[Encoder:       hevc_nvenc]
[FPS:           120]
[Bitrate:       40Mb/s]
[-preset p1 -tune ll -profile:v main -rc cbr -cbr true -gpu 0 -b_ref_mode 0]
V: ffmpeg args: [-progress tcp://localhost:1234 -stats_period 0.5 -y -i 1080-120.y4m -b:v 40M -c:v hevc_nvenc -preset p1 -tune ll -profile:v main -rc cbr -cbr true -gpu 0 -b_ref_mode 0 1080-120.mp4]
V: ffmpeg args no network calls (copy this and run locally, minus the quotes): [-y -i 1080-120.y4m -b:v 40M -c:v hevc_nvenc -preset p1 -tune ll -profile:v main -rc cbr -cbr true -gpu 0 -b_ref_mode 0 -f null -]
V: Successfully spawned encoding child
⠁ [00:00:00] [------------------------------------------------------------------------------------------] 0/2383 frames (00:00:00)Not able to connect to ffmpeg stat output, will try again...
Connected to ffmpeg's -progress output via TCP...
V: Calculated fps: 0
⠒ [00:00:01] [##############>-------------------------------------------------------------------------] 389/2383 frames (00:00:11)V: Calculated fps: 256
⠤ [00:00:02] [#######################>----------------------------------------------------------------] 646/2383 frames (00:00:08)V: Calculated fps: 258
⠋ [00:00:03] [#################################>------------------------------------------------------] 894/2383 frames (00:00:06)V: Calculated fps: 236
⠂ [00:00:04] [########################################>----------------------------------------------] 1120/2383 frames (00:00:05)V: Calculated fps: 238
⠂ [00:00:05] [#################################################>-------------------------------------] 1347/2383 frames (00:00:04)V: Calculated fps: 242
⠚ [00:00:06] [#########################################################>-----------------------------] 1585/2383 frames (00:00:03)V: Calculated fps: 234
⠋ [00:00:07] [##################################################################>--------------------] 1822/2383 frames (00:00:02)V: Calculated fps: 232
⠖ [00:00:08] [###########################################################################>-----------] 2061/2383 frames (00:00:01)V: Calculated fps: 228
⠓ [00:00:09] [####################################################################################>--] 2307/2383 frames (00:00:00)V: Calculated fps: 232
  [00:00:10] [#######################################################################################] 2383/2383 frames (00:00:00)
  Average FPS:  246
  1%'ile:       212
  90%'ile:      260

[Permutation:   2/2]
[Decode Benchmark]
[Resolution:    1920x1080]
[Encoder:       hevc_nvenc]
[FPS:           120]
[Bitrate:       40Mb/s]
[-preset p1 -tune ll -profile:v main -rc cbr -cbr true -gpu 0 -b_ref_mode 0]
V: ffmpeg args: [-progress tcp://localhost:1234 -stats_period 0.5 -y -hwaccel cuda -i 1080-120.mp4 -f null -]
V: ffmpeg args no network calls (copy this and run locally, minus the quotes): [-y -hwaccel cuda -i 1080-120.mp4 -f null -]
V: Successfully spawned encoding child
⠁ [00:00:00] [------------------------------------------------------------------------------------------] 0/2383 frames (00:00:00)Not able to connect to ffmpeg stat output, will try again...
Connected to ffmpeg's -progress output via TCP...
V: Calculated fps: 0
⠉ [00:00:01] [##########################>-------------------------------------------------------------] 730/2383 frames (00:00:04)V: Calculated fps: 518
⠈ [00:00:02] [############################################>------------------------------------------] 1225/2383 frames (00:00:02)V: Calculated fps: 518
⠒ [00:00:03] [##############################################################>------------------------] 1714/2383 frames (00:00:01)V: Calculated fps: 500
⠉ [00:00:04] [#################################################################################>-----] 2226/2383 frames (00:00:00)V: Calculated fps: 518
  [00:00:05] [#######################################################################################] 2383/2383 frames (00:00:00)
  Average FPS:  497
  1%'ile:       472
  90%'ile:      518

Giving ffmpeg a change to let go of the decode file, hang tight...
Benchmark runtime: 21s
Press any key to close the program...% 

To fix permutor-cli I had to add this

args.push_str(" -b_ref_mode 0");

To impl NvencSettings

Proryanator commented 9 months ago

Ooo nice! That'd be an easy fix 👍