Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#10009 closed defect (invalid)

FFmpeg not buildable without pthreads?

Reported by: Jozef Chutka Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: threads
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by Jozef Chutka)

When configuring ffmpeg (2 days old master version 5661c87) with emscripten with flags --disable-pthreads --disable-w32threads --disable-os2threads:

emconfigure ./configure --target-os=none --arch=x86_32 --enable-cross-compile --enable-version3
  --enable-zlib --enable-libopenh264...
  --disable-x86asm --disable-inline-asm --disable-stripping
  --disable-programs --disable-doc --disable-debug --disable-runtime-cpudetect
  --disable-autodetect
  --extra-cflags="-O3 -msimd128"
  --extra-cxxflags="-O3 -msimd128"
  --extra-ldflags="-O3 -msimd128"
  --pkg-config-flags="--static"
  --nm="llvm-nm" --ar=emar --ranlib=emranlib --cc=emcc --cxx=em++ --objcc=emcc --dep-cc=emcc
  --disable-pthreads --disable-w32threads --disable-os2threads

emmake make -j

emcc -O3 -msimd128 -I. -I./fftools -I$BUILD_DIR/include
  -Llibavcodec -Llibavdevice ... -L$BUILD_DIR/lib
  -Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
  -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lm ...
  fftools/cmdutils.c fftools/ffmpeg.c fftools/ffmpeg_demux.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/ffmpeg_mux.c fftools/ffmpeg_mux_init.c fftools/ffmpeg_opt.c fftools/objpool.c fftools/opt_common.c fftools/sync_queue.c fftools/thread_queue.c
  -lworkerfs.js -s USE_SDL=2 -s INVOKE_RUN=0 -s EXIT_RUNTIME=1 -s MODULARIZE=1
  -s EXPORT_NAME="createFFmpeg" -s EXPORTED_FUNCTIONS="[_main]" -s EXPORTED_RUNTIME_METHODS="[callMain, FS, WORKERFS]" -s INITIAL_MEMORY=128mb -s ENVIRONMENT=worker -o ffmpeg.js

Configure runs ok, however the following command fails with some phtread related errors:

fftools/ffmpeg_demux.c:358:5: error: call to undeclared function 'pthread_join'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    pthread_join(d->thread, NULL);
    ^
fftools/ffmpeg_demux.c:358:5: note: did you mean 'pthread_kill'?
/ffmpeg/modules/emsdk/upstream/emscripten/cache/sysroot/include/signal.h:226:5: note: 'pthread_kill' declared here
int pthread_kill(pthread_t, int);
    ^
fftools/ffmpeg_demux.c:397:16: error: call to undeclared function 'pthread_create'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    if ((ret = pthread_create(&d->thread, NULL, input_thread, d))) {
               ^
2 errors generated.
emcc: error: '/ffmpeg/modules/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -Werror=implicit-function-declaration -I/ffmpeg/modules/emsdk/upstream/emscripten/cache/sysroot/include/SDL2 --sysroot=/ffmpeg/modules/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -O3 -I/ffmpeg/build/include -msimd128 -I. -I./fftools -I/ffmpeg/build/include -Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments fftools/ffmpeg_demux.c -c -o /tmp/emscripten_temp_0b3ma1cz/ffmpeg_demux_2.o' failed (returned 1)
root@cs-1036883351707-default:/ffmpeg# 

I can build a version with pthreads by removing --disable-*threads flags from emconfigure and adding -pthread -s PROXY_TO_PTHREAD=1 -s USE_PTHREADS=1 into emcc.

I tried various flags but could not get building single thread version. As I only have setup for emscripten build, I can not confirm if some more standard single thread build works or not. But having references to pthread_create() or pthread_join() in ffmpeg_demux.c seems suspicious.

Can you please verify if single thread ffmpeg version is still buildable, and if so, do you have any idea what I am doing wrong?

Change History (4)

comment:1 by Jozef Chutka, 18 months ago

Description: modified (diff)

comment:2 by mkver, 18 months ago

Resolution: invalid
Status: newclosed

Actually, FFmpeg (the cli tool, not the libraries) depends upons threading since commit 760ce4bc0bd11f74f0851c0a662dd5cae888df83. It seems to me you manually tried to compile the fftools after having run configure with --disable-programs. This is not supported and I am therefore closing this as invalid. Reopen if I am wrong about this.

comment:3 by Carl Eugen Hoyos, 18 months ago

Component: ffmpegundetermined
Keywords: threads added; pthreads removed

comment:4 by Jozef Chutka, 18 months ago

My setup is working for cli tool with emscripten inspired by https://github.com/ffmpegwasm/ffmpeg.wasm-core/blob/n4.3.1-wasm/wasm/build-scripts/configure-ffmpeg.sh and https://github.com/ffmpegwasm/ffmpeg.wasm-core/blob/n4.3.1-wasm/wasm/build-scripts/build-ffmpeg.sh ...

Are there arguments to be changed to follow the supported path?

I understand threading is out of the quesstion now.

Note: See TracTickets for help on using tickets.