Anime4000 / IFME

Powerful x265 GUI Encoder
https://x265.github.io/
GNU General Public License v2.0
239 stars 53 forks source link

How to use the built in Libx265 in FFmpeg? #210

Closed canbonbon closed 3 years ago

canbonbon commented 3 years ago

Hello Anime4000, hope you are doing great in the new year. I tried my best but I could not make your new IFME 2.0 work on my machines. So explored a little more and found out that new versions of FFMpeg contain the new x265 version 3.4. So a lot of people actually just use that instead of downloading the HEVC compiler separately and the piping the output form one to another. I tried that but the resultant file size is much larger than what gets created in IFME (old version). Here are the two commands I had used:

"C:\Tools\ffmpeg64\ffmpeg" -hide_banner -ss 0 -i %1 -map_metadata 0 -map_chapters 0 -metadata title="%~n1" -pix_fmt yuv420p10le -c:v libx265 -preset fast -x265-params crf=23:qcomp=0.8:aq-mode=1:aq_strength=1.0:qg-size=16:psy-rd=0.7:psy-rdoq=5.0:rdoq-level=1:merange=44 -c:a copy -c:s copy "C:\converted-HEVC\%~n1.HEVC.mkv"

or

"C:\Tools\ffmpeg64\ffmpeg" -hide_banner -ss 0 -i %1 -map_metadata 0 -map_chapters 0 -metadata title="%~n1" -pix_fmt yuv420p10le -c:v libx265 -preset fast -x265-params crf=23 -c:a copy -c:s copy "C:\converted-HEVC\%~n1.HEVC.mkv"

In both cases the file size was significantly larger than what gets created by IFME. As you can see I did not pass too many parameters so probably FFmpeg and libx265 are using many defaults. Can you please assist in letting me know what additional parameters I could pass to make this generate comparable file size? I see in the logs that IFME actually pipes the output from FFMpeg and somehow is able to calculate the Frame size (-f xxxxx). That could be one thing that might be resulting in smaller file size and that is something I don't know how to do automatically. But maybe I am wrong.

Could you please suggest what parameters could be passed to make this work and generate smaller size files without compromising on quality too much. I am using CRF=23 but that did not make too much of a difference. Thanks again.

Anime4000 commented 3 years ago

If you using version 20.05, take a look at plugin\video.ffmpeg\_plugin000_vp9.json file. You can follow this as example to using ffmpeg as standalone (no pipe)

{
    "GUID": "deadbeef-f265-f265-f265-f265f265f265",
    "Name": "Libx265 FFmpeg Encoder",
    "Version": "",
    "X64": false,
    "Format": [
        "mkv",
        "webm"
    ],
    "Author": {
        "Developer": "FFmpeg developers",
        "URL": "https://ffmpeg.org/"
    },
    "Update": {
        "VersionURL": null,
        "DownloadURL": null
    },
    "Video": {
        "Extension": "mp4",
        "Encoder": [
            {
                "BitDepth": 8,
                "Binary": "../ffmpeg64/ffmpeg"
            }
        ],
        "Preset": [
            "ultrafast",
            "superfast",
            "veryfast",
            "faster",
            "fast",
            "medium",
            "slow",
            "slower",
            "veryslow",
            "placebo"
        ],
        "PresetDefault": "medium",
        "Tune": [
            "off",
            "psnr",
            "ssim",
            "grain",
            "zerolatency",
            "fastdecode"
        ],
        "TuneDefault": "psnr",
        "Args": {
            "Pipe": false,
            "UnPipe": "-an -sn -dn -c:v libx265",
            "Y4M": null,
            "Input": "-hide_banner -v error -stats -i",
            "Output": "-y",
            "Preset": "-preset",
            "Tune": "-tune",
            "BitDepth": null,
            "FrameCount": null,
            "PassFirst": null,
            "PassLast": null,
            "PassNth": null,
            "Command": "-map_metadata -1 -map_chapters -1"
        },
        "Mode": [
            {
                "Name": "Constant Quality",
                "Args": "-crf",
                "MultiPass": false,
                "Prefix": "",
                "Postfix": "",
                "Value": {
                    "DecimalPlace": 0,
                    "Step": 1,
                    "Min": 0,
                    "Max": 51,
                    "Default": 24
                }
            },
            {
                "Name": "Constant Bit Rate",
                "Args": "-b:v",
                "MultiPass": false,
                "Prefix": "",
                "Postfix": "k",
                "Value": {
                    "DecimalPlace": 0,
                    "Step": 1024,
                    "Min": 128,
                    "Max": 10485760,
                    "Default": 1024
                }
            }
        ]
    }
}

For high compression & High Quality, I use: 720p: CRF 24 @ veryslow 1080p: CRF 24 @ slower 1440p: CRF 24 @ slow 4K: CRF 24 @ medium

You need a Good Processor for this task, Recommended Processor:

  1. AMD Ryzen 7 3700X, 8 Core 16 Threads (1440p & Lower)
  2. AMD Ryzen 9 3900X 12 Core 24 Threads (4K to 6K)
  3. AMD Ryzen 9 3950X 16 Core 32 Threads (8K)

If you have Ryzen 9 3950X and you encoder 1080p, x265 unable to use all 32 threads, there are way to force (--pme --pmod) x265 to use all 32 threads to make encode faster, but you will sacrifice some quality.

https://www.facebook.com/x265project/posts/we-are-pleased-to-announce-that-we-have-reached-the-v14-milestone-on-many-core-m/1533207660229647/

canbonbon commented 3 years ago

Thanks for your response. I only have IFME-20.05.2_Debug version and that does not have that file. But I will copy from your post and try. Once again, just wanted to let you know that IFME-20.05.2_Debug does not work. So I have been using the very very old IFME 7.7 version. I have checked both and they do not have that file.

Here is the output from IFME 7.7:

ifme [info]: Run command: "C:\Tools\Internet Friendly Media Encoder\plugin\ffmpeg64\ffmpeg" -hide_banner -v error -i "Test.mkv" -strict -1 -map 0:0 -f yuv4mpegpipe -pix_fmt yuv420p10le -s 1920x1036 -r 24 - | "C:\Tools\Internet Friendly Media Encoder\plugin\video.x265gcc\x265-10.exe" - --y4m -p medium --crf 23.0 -t ssim --output-depth 10 -f 143641 -o video0000_und.h265 y4m [info]: 1920x1036 fps 24/1 i420p10 sar 1:1 unknown frame count raw [info]: output file: video0000_und.h265 x265 [info]: HEVC encoder version 3.2_IFME-ZEN_2 x265 [info]: build info [Windows][GCC 9.3.0][64 bit] 10bit x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 x265 [info]: Main 10 profile, Level-4 (Main tier) x265 [info]: Thread pool created using 4 threads x265 [info]: Slices : 1 x265 [info]: frame threads / pool features : 2 / wpp(17 rows) x265 [info]: Coding QT: max CU size, min CU size : 64 / 8 x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra x265 [info]: ME / range / subpel / merge : hex / 57 / 2 / 3 x265 [info]: Keyframe min / max / scenecut / bias: 24 / 250 / 40 / 5.00 x265 [info]: Lookahead / bframes / badapt : 20 / 4 / 2 x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0 x265 [info]: References / ref-limit cu / depth : 3 / off / on x265 [info]: AQ: mode / str / qg-size / cu-tree : 2 / 1.0 / 32 / 1 x265 [info]: Rate Control / qCompress : CRF-23.0 / 0.60 x265 [info]: tools: rd=3 early-skip rskip signhide tmvp b-intra x265 [info]: tools: strong-intra-smoothing lslices=6 deblock sao

as you can see, the biggest thing about this is this parameter: -f 143641. I don't know how it did that and how can I automatically calculate it.

Thanks again for all your help.

Anime4000 commented 3 years ago

the total frame is calculated by length in second * fps since IFME will make video constant frame rate

Anime4000 commented 3 years ago

Frame Rate -r now using filter -vf fps= for proper timing, IFME always output Constant FPS