termux-packages
termux-packages copied to clipboard
[Bug]: FFmpeg doesn't cut videos in Termux
Problem description
Hello, I’ve always used FFmpeg on Termux to cut videos, but after an update to the packages, something changed and I can no longer cut any video file. The command freezes after displaying some “unavailable from libmediandk.so
” warnings and nothing else happens, as in the output below:
.../0/Kwaicutter $ ffmpeg -ss 00:00:00 -to 00:00:06 -i video.mp4 output.mp4
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Android (9352603, based on r450784d1) clang version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6)
configuration: --arch=armeabi-v7a --as=arm-linux-androideabi-clang --cc=arm-linux-androideabi-clang --cxx=arm-linux-androideabi-clang++ --nm=llvm-nm --pkg-config=/home/builder/.termux-build/_cache/android-r25c-api-24-v2/bin/pkg-config --strip=llvm-strip --cross-prefix=arm-linux-androideabi- --disable-indevs --disable-outdevs --enable-indev=lavfi --disable-static --disable-symver --enable-cross-compile --enable-gnutls --enable-gpl --enable-version3 --enable-jni --enable-lcms2 --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgme --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librav1e --enable-libsoxr --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-mediacodec --enable-opencl --enable-shared --prefix=/data/data/com.termux/files/usr --target-os=android --extra-libs=-landroid-glob --disable-vulkan --enable-neon --disable-libfdk-aac
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2022-06-19T07:07:42.000000Z
Duration: 00:00:16.51, start: 0.000000, bitrate: 1128 kb/s
Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 998 kb/s, 12 fps, 12 tbr, 12288 tbn (default)
Metadata:
creation_time : 2022-06-19T07:07:42.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 06/19/2022.
vendor_id : [0][0][0][0]
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2022-06-19T07:07:42.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 06/19/2022.
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_mediacodec))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[amediacodec_ndk @ 0xa6552a80] getName() unavailable from libmediandk.so
[amediacodec_ndk @ 0xa6552a80] releaseName() unavailable from libmediandk.so
[amediacodec_ndk @ 0xa6552a80] setInputSurface() unavailable from libmediandk.so
[amediacodec_ndk @ 0xa6552a80] signalEndOfInputStream() unavailable from libmediandk.so
What I’ve tried so far, without success:
- Uninstall with
pkg uninstall ffmpeg
, remove dependencies withpkg autoclean
and reinstall ffmpeg. - Clear Termux data in Android settings and then reinstall ffmpeg.
- Change the default repository with
termux-change-repo
and test other installations. None of this worked.
Extra details:
- Other tasks are performed normally with ffmpeg.
- Android version: 7.0
- Phone: LG K10 2017
What steps will reproduce the bug?
- Choose an .mp4 video to cut.
- Give the cut command in the format
ffmpeg -ss 00:00:00 -to 00:00:06 -i your-video.mp4 output.mp4
- Press enter.
What is the expected behavior?
The expected result after this step by step is the terminal freezing without the task being completed.
System information
termux-info:
Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=13084
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
arm
Subscribed repositories:
# sources.list
deb https://termux.librehat.com/apt/termux-main stable main
Updatable packages:
All packages up to date
termux-tools version:
1.39.0
Android version:
7.0
Kernel build information:
Linux localhost 3.18.35 #1 SMP PREEMPT Tue Dec 4 19:58:55 IST 2018 armv7l Android
Device manufacturer:
LGE
Device model:
LG-M250
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api
It seems that the hardware decoding via mediacodec is broken for old Android. As a workaround you can force use software decoding via libx264 which is previous behavior.
ffmpeg -ss 00:00:00 -to 00:00:06 -i your-video.mp4 -c:v libx264 output.mp4
ffmpeg -ss 00:00:00 -to 00:00:06 -i your-video.mp4 -c:v libx264 output.mp4
Thanks, that works perfectly.
is broken for old Android
Hello, I think it's not only broken for old android. It's broken for me too. I'm on Poco F3 with Android 12, and I'm also having some issues, although they're different.
Here's the error I get, if anyone's curious:
[amediacodec_ndk @ 0xb4000078264a0380] Encoder configure failed, -10000
[h264_mediacodec @ 0xb4000078264afc00] MediaCodec configure failed, Generic error in an external library
[vost#0:0/h264_mediacodec @ 0xb4000078264a9f80] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Error while filtering: Generic error in an external library
[out#0/mp4 @ 0xb40000782641cd80] Nothing was written into output file, because at least one of its streams received no packets.
Can confirm on android 12 h264_mediaencoder
is broken and theres been other reports of it being broken on other devices so i dont know why it was enabled in the first place.
@Happiness777 @Senjosei Can you post the full command line?
Android 13 too. Here on a moto g32. Everything up to date in termux.
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (native) -> h264 (h264_mediacodec))
Stream #0:1 -> #0:1 (opus (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_mediacodec @ 0xb400007589ace030] Use 1 as the default MediaFormat i-frame-interval, please set gop_size properly (>= fps)
[amediacodec_ndk @ 0xb400007559ac9410] Encoder configure failed, -10000
[h264_mediacodec @ 0xb400007589ace030] MediaCodec configure failed, Generic error in an external library
Can confirm on android 12
h264_mediaencoder
is broken and theres been other reports of it being broken on other devices so i dont know why it was enabled in the first place.
I'm on android 13 lineageOS redmi note 10, and i have the same issue, tho it's fixed by truboxl's answer i looked around and someone said it was because of this commit enabling mediacodec by default https://github.com/termux/termux-packages/commit/097206d50d34ab7fc0eb4c0ff20ae80ee73fd901 so if possible please revert it 🙏
Can confirm on android 12
h264_mediaencoder
is broken and theres been other reports of it being broken on other devices so i dont know why it was enabled in the first place.
It's not FFmpeg mediacodec is broken. Most of the time, it's just the device doesn't support pixfmt yuv420p, and there is no way to get the info from NDK API. Just try:
ffmpeg -hwaccel mediacodec -i /sdcard/DCIM/Scene3-Middle.mp4 -c:a copy -c:v h264_mediacodec -b:v 2M -pix_fmt nv12 out.mp4
It should work.
There is another bug in FFmpeg 6.1 which has been fixed in master, which I haven't backported it yet.
It should work.
Yeah, it works, thanks. Although when I tried to use it in my lazily made script, it produced weird/a little broken video with a small green strip at the bottom of it. I'll try fixing it later, I think. I'm too lazy rn :P
It should work.
Yeah, it works, thanks. Although when I tried to use it in my lazily made script, it produced weird/a little broken video with a small green strip at the bottom of it. I'll try fixing it later, I think. I'm too lazy rn :P
It's likely due to aligment issue of mediacodec. Try to use video resolution which are multiple of 16 if it's possible, e.g., 1920x1088.