caydey / ffshare

An android app to compress image, video and audio files through ffmpeg before sharing them
GNU General Public License v3.0
615 stars 30 forks source link

width not divisible by 2 (853x480) #72

Closed esetleges closed 5 months ago

esetleges commented 6 months ago

Command: ffmpeg -y -i PXL_20240425_145644740.mp4 -preset medium -crf 23 -vf format=yuv420p -c:v h264 -vf scale=-1:480,setsar=1 d09cef30-bf5b-4a48-98b7-68ad97467f1c.mp4 Output: ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d) configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libdav1d --enable-libkvazaar --enable-libx264 --enable-libxvid --enable-libx265 --enable-libvidstab --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libtwolame --disable-sdl2 --enable-libvo-amrwbenc --enable-libzimg --disable-openssl --enable-zlib --enable-mediacodec --enable-gpl libavutil 57. 28.100 / 57. 28.100 libavcodec 59. 37.100 / 59. 37.100 libavformat 59. 27.100 / 59. 27.100 libavdevice 59. 7.100 / 59. 7.100 libavfilter 8. 44.100 / 8. 44.100 libswscale 6. 7.100 / 6. 7.100 libswresample 4. 7.100 / 4. 7.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'saf:8.mp4': Metadata: major_brand : isom minor_version : 131072 compatible_brands: isomiso2mp41 creation_time : 2024-04-25T14:58:29.000000Z location : +11.1780+119.3919/ location-eng : +11.1780+119.3919/ com.android.manufacturer: Google com.android.model: Pixel 8 SpecialTypeID : com.google.android.apps.camera.gallery.specialtype.SpecialType-AMETHYST com.android.capture.fps: 30.000000 Duration: 00:00:32.64, start: 0.000000, bitrate: 43416 kb/s Stream #0:00x1: Data: none (mett / 0x7474656D), 46 kb/s (default) Metadata: creation_time : 2024-04-25T14:58:29.000000Z handler_name : MetaHandle Stream #0:10x2: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default) Metadata: creation_time : 2024-04-25T14:58:29.000000Z handler_name : SoundHandle vendor_id : [0][0][0][0] Stream #0:20x3: Video: hevc (hvc1 / 0x31637668), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 3840x2160, 43170 kb/s, SAR 1:1 DAR 16:9, 29.99 fps, 120 tbr, 90k tbn (default) Metadata: creation_time : 2024-04-25T14:58:29.000000Z handler_name : VideoHandle vendor_id : [0][0][0][0] Multiple -filter, -af or -vf options specified for stream 0, only the last option '-filter:v scale=-1:480,setsar=1' will be used. Stream mapping: Stream #0:2 -> #0:0 (hevc (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help [libx264 @ 0xb40000707375ff80] width not divisible by 2 (853x480) Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height Conversion failed!

Result: FAILURE App Version: 1.2.8a

caydey commented 5 months ago

https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2

caydey commented 5 months ago

looks like the h264 codec requires the width to be divisible by 2, a solution is to either add a row of black pixels to the right of all frames or remove a row of pixels from the right

esetleges commented 5 months ago

Thanks for responding, and yes it is correct: output height and width either should be divisible by 2 .

For me cropping a line is more nice than adding a black one.

Temp workflow is choosing a different output (ie 720/360px instead of 480px)

esetleges commented 5 months ago

Thank you for fixing this. Testing later!

gbdomubpkm commented 5 months ago

Hello. Is it normal that currently for H264 - MPEG4 AVC (part 10) 852 364, 932 480 videos, i get 'error compressing media' ? It's just a question to try to understand what this could relate to. Maybe this isn’t the right issue here for this anyway 🙂 ! Thank you in any case for all the past and future improvements.

gbdomubpkm commented 4 months ago

Not sure about i said before, because by restarting the compression 3 times, it ends up working (failure on the first 2 tries) ! Strange.

Edit : Confirmed on numerous videos: conversion works on the third attempt.