ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

Does not support H265 encoding, does not support 4K video encoding

Open Jveshi opened this issue 1 year ago • 12 comments

Describe the bug

  1. Does not support h265 encoding.
  2. Does not support 4K video encoding.

Question 1

I am trying to do H265 encoding with the following code and it fails.

await ffmpeg.run('-i', 'test.mp4' , '-vcodec' , 'libx265' , '-acodec' , 'aac' , '-b:v' , '3000k' , '-maxrate' , '4000k' , '-minrate' , '3000k' , '-s' , '1920x1080' , '-b:a' , '192k' , 'test_out.mp4');

But it can be successful when using H264 encoding.

await ffmpeg.run('-i', 'test.mp4' , '-vcodec' , 'libx264' , '-acodec' , 'aac' , '-b:v' , '3000k' , '-maxrate' , '4000k' , '-minrate' , '3000k' , '-s' , '1920x1080' , '-b:a' , '192k' , 'test_out.mp4');

Maybe H265 encoding does not support multi-threading yet?

image

Error screenshot

image

Question 2

At first I tried to convert 4K video to 1080P video

await ffmpeg.run('-i', 'test.mp4' , '-vcodec' , 'libx264' , '-acodec' , 'aac' , '-b:v' , '3000k' , '-maxrate' , '4000k' , '-minrate' , '3000k' , '-s' , '1920x1080' , '-b:a' , '192k' , 'test_out.mp4');

The program runs fine for a short time, but errors appear soon after (An error occurs when the program executes less than 1%)

image

Then I remove the width and height constraints, the error occurs immediately

await ffmpeg.run('-i', 'test.mp4' , '-vcodec' , 'libx264' , '-acodec' , 'aac' , '-b:v' , '3000k' , '-maxrate' , '4000k' , '-minrate' , '3000k' , '-b:a' , '192k' , 'test_out.mp4');

Error screenshot

image

I hid the website domain in the screenshot, it has nothing to do with the question

Desktop:

  • OS: windows 10 22H2
  • Browser: chrome 114.0.5735.134

Jveshi avatar Jun 22 '23 08:06 Jveshi

I just tried 2K (2560x1440) video encoding and it's ok.

Jveshi avatar Jun 22 '23 12:06 Jveshi

3K (3200×1800) video encoding is also possible

Jveshi avatar Jun 22 '23 13:06 Jveshi

Even adjusting the code rate to 10000k will not work

image

Jveshi avatar Jun 22 '23 13:06 Jveshi

I am the same. Which version are you using?

xielinjiang0112 avatar Aug 01 '23 09:08 xielinjiang0112

I am the same. Which version are you using?

v0.11.6 The last time I checked this project was in June. A new version has been released recently. I will check for changes when I am free. And you? Have you tried the new version?

Jveshi avatar Aug 02 '23 17:08 Jveshi

I am the same. Which version are you using?

I tested V0.12.2, it still doesn't work, and no error is reported in the console, the program seems to terminate directly.

Jveshi avatar Aug 03 '23 08:08 Jveshi

With all the information, I think it is not supported at the moemnt, need more research to figure out why not.

jeromewu avatar Aug 06 '23 04:08 jeromewu

With all the information, I think it is not supported at the moemnt, need more research to figure out why not.

Thanks, looking forward to the new version

Jveshi avatar Aug 06 '23 05:08 Jveshi

How large is your input file? The FAQs say that the maximum input file size is a hard 2GB which you may be easily going over by encoding 4k and h265 video. The error message is OOM (out of memory) which suggests this too.

markjaniczak avatar Aug 18 '23 05:08 markjaniczak

How large is your input file? The FAQs say that the maximum input file size is a hard 2GB which you may be easily going over by encoding 4k and h265 video. The error message is OOM (out of memory) which suggests this too.

I have noticed that the file size is below 2GB. Specifically, this image is the video I used for testing. image image

I have also tested other videos with different resolutions and bitrates, as shown in the previous messages

Jveshi avatar Aug 18 '23 06:08 Jveshi

Tried with [email protected] encoding a 4k and I got OOM error too, but it's fine when down scaling it under 2k or below. command:

await ffmpeg.exec([
          "-i", tempInputName,
          "-c:v", "libx264",
          "-vf", "scale='if(gt(iw,2048),2048,-2)':'if(gt(ih,1080),1080,-2)'", // with out this, 4k transcoding will got OOM
          "-threads", "4",
          "-crf", "23",
          "-preset", "veryfast",
          "-c:a", "aac",
          "-b:a", "128k",
          tempOutputName
]);

iketiunn avatar Apr 12 '24 09:04 iketiunn

issue might related: https://github.com/ffmpegwasm/ffmpeg.wasm/issues/359 And for a 4k output, try to change the -preset to superfast or ultrafast may help.

iketiunn avatar Apr 14 '24 07:04 iketiunn