Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg.exec hangs forever without error when I try to resize a video, but only when using the multithreaded version, while using a Chromium based browser or Safari. No issues on Firefox. #772

Open
Boux opened this issue Aug 13, 2024 · 7 comments

Comments

@Boux
Copy link

Boux commented Aug 13, 2024

Describe the bug
If I try to resize a video, either with the -s param or something like -vf scale=-2:480, the execution will simply hang forever and never give an error, but only when using the core-mt version (umd). If I try with the single-threaded version (core), everything works fine

To Reproduce

  • Use Google Chrome on macOS (similar things happen on Chromium on Linux)
  • Go to the /apps/vanilla-app/public/transcode-mt.html file in this project
  • Modify this line: await ffmpeg.exec(['-i', name, 'output.mp4']); to await ffmpeg.exec(['-i', name, '-filter:v', 'scale=-2:480', 'output.mp4']);
  • It hangs
  • Do the same modification to the non-mt html file
  • It does not hang
  • Same issue on Safari
  • Everything works on Firefox, mt or non-mt

Expected behavior
ffmpeg.exec should not hang and successfully encode the video, or at the very least give an error.

Logs
Here are the logs (directly from ffmpeg.on("log" ...)

[FFmpeg] ffmpeg version 5.1.4 Copyright (c) 2000-2023 the FFmpeg developers
[FFmpeg]   built with emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.40 (5c27e79dd0a9c4e27ef2326841698cdd4f6b5784)
[FFmpeg]   configuration: --target-os=none --arch=x86_32 --enable-cross-compile --disable-asm --disable-stripping --disable-programs --disable-doc --disable-debug --disable-runtime-cpudetect --disable-autodetect --nm=emnm --ar=emar --ranlib=emranlib --cc=emcc --cxx=em++ --objcc=emcc --dep-cc=emcc --extra-cflags='-I/opt/include -O3 -msimd128 -sUSE_PTHREADS -pthread' --extra-cxxflags='-I/opt/include -O3 -msimd128 -sUSE_PTHREADS -pthread' --enable-gpl --enable-libx264 --enable-libx265 --enable-libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libopus --enable-zlib --enable-libwebp --enable-libfreetype --enable-libfribidi --enable-libass --enable-libzimg
[FFmpeg]   libavutil      57. 28.100 / 57. 28.100
[FFmpeg]   libavcodec     59. 37.100 / 59. 37.100
[FFmpeg]   libavformat    59. 27.100 / 59. 27.100
[FFmpeg]   libavdevice    59.  7.100 / 59.  7.100
[FFmpeg]   libavfilter     8. 44.100 /  8. 44.100
[FFmpeg]   libswscale      6.  7.100 /  6.  7.100
[FFmpeg]   libswresample   4.  7.100 /  4.  7.100
[FFmpeg]   libpostproc    56.  6.100 / 56.  6.100
[FFmpeg] Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_1503edd15afe4f709ee5c8c782ca25dd.mp4':
[FFmpeg]   Metadata:
[FFmpeg]     major_brand     : isom
[FFmpeg]     minor_version   : 512
[FFmpeg]     compatible_brands: isomiso2avc1mp41
[FFmpeg]     encoder         : Lavf59.16.100
[FFmpeg]   Duration: 00:02:19.10, start: 0.000000, bitrate: 1929 kb/s
[FFmpeg]   Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 1729 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
[FFmpeg]     Metadata:
[FFmpeg]       handler_name    : VideoHandler
[FFmpeg]       vendor_id       : [0][0][0][0]
[FFmpeg]   Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
[FFmpeg]     Metadata:
[FFmpeg]       handler_name    : SoundHandler
[FFmpeg]       vendor_id       : [0][0][0][0]
[FFmpeg] Stream mapping:
[FFmpeg]   Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
[FFmpeg]   Stream #0:1 -> #0:1 (aac (native) -> aac (native))
(this is where it hangs)

Desktop

  • macOS 13.3.1
  • Chrome, Safari

Additional context
If there are issues with reproducing the bug, I'm not against the idea of doing a video call and sharing my screen

@Boux
Copy link
Author

Boux commented Aug 13, 2024

Followup: for some crazy unexplained reason, after MUCH trial and error, if I add the params "-c:a", "copy", so something like await ffmpeg.exec(['-i', name, "-c:a", "copy", '-filter:v', 'scale=-2:480', 'output.mp4']);, everything works. No idea why, I'm just gonna do this, I'm glad it works and at this point I don't even care to know why, yes it's currently 4:30 am.

@0xJacky
Copy link

0xJacky commented Aug 27, 2024

Same issue

@vayron
Copy link

vayron commented Aug 30, 2024

0.12.5~0.12.10 same issue, the old version 0.11.5 work

@yafkari
Copy link

yafkari commented Sep 8, 2024

Hahahha the solution of @Boux really worked, I literally just added "-c:a", "copy" to the parameters and it started to process the input.

Before that I was just getting to the logging of the streams info like that:

image

(Using @ffmpeg/[email protected]/dist/umd)

EDIT: Still have the issue when trying to do things like -i myfile.png myfile.webp though. (But jpg to webp worked)

EDIT2: While trying to convert an mp4 to avi without -c:v copy, it was still hanging forever even with the c:a copy trick. By setting manually c:v libx264 it started.

@ezengaston
Copy link

ezengaston commented Oct 23, 2024

Same issue. The solution by @Boux worked. Here are the details:

This is my original code that recently stopped working when I tried to compress an mp4 video:
await ffmpeg.exec([ "-i", name, "-vcodec", "libx264", "-crf", "23", "-acodec", "aac", "-b:a", "128k", "output.mp4"]);

I had to remove -acodec aac to make it work. Here is the updated code:

await ffmpeg.exec([ "-i", name, "-c:a", "copy", "-vcodec", "libx264", "-crf", "23", "-b:a", "128k", "output.mp4"]);

I guess this bug somehow related to audio encoding.

@opheliagame
Copy link

I was struggling with the filter as well and on removing the filter everything else was working but with the filter -c:a aac was freezing. -c:a copy seems to do the trick for now.

@opheliagame
Copy link

would anyone know if it is possible to use -c:a copy in this command

ffmpeg command: -ss 0.00 -t 1.48 -i 0-combined.webm -ss 0.00 -t 1.32 -i 1-combined.webm -filter_complex [0:v]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:-1:-1,setsar=1[v0]; [1:v]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:-1:-1,setsar=1[v1]; [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a] -map [v] -map [a] output.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants