ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
14.57k stars 858 forks source link

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

Open Jveshi opened 1 year ago

Jveshi commented 1 year ago

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:

Jveshi commented 1 year ago

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

Jveshi commented 1 year ago

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

Jveshi commented 1 year ago

Even adjusting the code rate to 10000k will not work

image

xielinjiang0112 commented 1 year ago

I am the same. Which version are you using?

Jveshi commented 1 year ago

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 commented 1 year ago

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.

jeromewu commented 1 year ago

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

Jveshi commented 1 year ago

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

markjaniczak commented 1 year ago

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.

Jveshi commented 1 year ago

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

iketiunn commented 7 months ago

Tried with core-mt@0.12.6 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 commented 7 months ago

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.