aodzip / cedar

Allwinner CedarX Compatible Mainline Kernel Driver ( Not Official )
98 stars 65 forks source link

ffmpeg - Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height #7

Open niyazFattahov opened 3 years ago

niyazFattahov commented 3 years ago

Im trying use this cedar with ffmpeg and get:

ffmpeg -f lavfi -i testsrc=duration=2:size=1280x720:rate=30 testsrc.h264 -y

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 8.4.0 (Buildroot 2020.02.1) configuration: --enable-cross-compile --cross-prefix=/home/niyaz/licheepizero_linux_build_latest/buildroot_rootfs/buildroot-2020.02.1/output/host/bin/arm-buildroot-linux-uclibcgnueabihf- --sysroot=/home/niyaz/licheepizero_linux_build_latest/buildroot_rootfs/buildroot-2020.02.1/output/host/arm-buildroot-linux-uclibcgnueabihf/sysroot --host-cc=/usr/bin/gcc --arch=arm --target-os=linux --disable-stripping --pkg-config=/home/niyaz/licheepizero_linux_build_latest/buildroot_rootfs/buildroot-2020.02.1/output/host/bin/pkg-config --disable-static --enable-shared --prefix=/usr --enable-avfilter --disable-version3 --enable-logging --enable-optimizations --disable-extra-warnings --enable-avdevice --enable-avcodec --enable-avformat --enable-network --disable-gray --enable-swscale-alpha --disable-small --enable-dct --enable-fft --enable-mdct --enable-rdft --disable-crystalhd --disable-dxva2 --enable-runtime-cpudetect --disable-hardcoded-tables --disable-mipsdsp --disable-mipsdspr2 --disable-msa --enable-hwaccels --disable-cuda --disable-cuvid --disable-nvenc --disable-avisynth --disable-frei0r --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libdc1394 --disable-libgsm --disable-libilbc --disable-libvo-amrwbenc --disable-symver --disable-doc --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-avresample --disable-ffprobe --disable-postproc --enable-swscale --enable-indevs --disable-alsa --enable-outdevs --enable-pthreads --enable-zlib --disable-bzlib --disable-libfdk-aac --disable-libcdio --disable-gnutls --enable-openssl --disable-libdrm --disable-libopenh264 --disable-vaapi --disable-vdpau --disable-mmal --disable-omx --disable-omx-rpi --disable-libopencv --disable-libopus --disable-libvpx --disable-libass --disable-libbluray --disable-libmfx --disable-librtmp --disable-libmp3lame --disable-libmodplug --disable-libspeex --disable-libtheora --disable-libwavpack --enable-iconv --disable-libfreetype --disable-fontconfig --disable-libopenjpeg --disable-libx264 --disable-libx265 --disable-libdav1d --disable-x86asm --disable-mmx --disable-sse --disable-sse2 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-avx --disable-avx2 --enable-armv6 --enable-vfp --enable-neon --disable-altivec --extra-libs=-latomic --enable-pic --cpu=cortex-a7 --enable-omx --enable-swscale --enable-swscale-alpha --enable-filter=scale libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 Input #0, lavfi, from 'testsrc=duration=2:size=1280x720:rate=30': Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1280x720 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn, 30 tbc Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_omx)) Press [q] to stop, [?] for help [h264_omx @ 0x6d440] libOMX_Core.so not found [h264_omx @ 0x6d440] libOmxCore.so not found 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!

Unturned3 commented 3 years ago

May I ask how did you manage to solve the problem?

niyazFattahov commented 3 years ago

Did you select glibc libracy in Toolchain menu of your buildroot config? by default it was uclibc and this is not right library. It was the reason for me. Now libOmxCore.so was found, and ffmpeg works with codec. But you will have to make clean, full compile

Unturned3 commented 3 years ago

Yeah, I selected glibc in toolchain... But I still get the "ERROR: OMX_Core.h not found" message when compiling ffmpeg with --enable-omx

niyazFattahov commented 3 years ago

I thought you're asking about ffmpeg run issue, not about compilation ffmpeg, because you were are asking here. I had problem with OMX_Core.h not found, but don't remember what I did to solve this, nothing special

niyazFattahov commented 3 years ago

you should try dirclean/rebuild libcedar/ffmpeg

petit-miner commented 2 years ago

Yeah, I selected glibc in toolchain... But I still get the "ERROR: OMX_Core.h not found" message when compiling ffmpeg with --enable-omx

RTFM, no seriously you will need to compile libcedar first (make in buildroot) and after the first build select ffmpeg and the build again. It seems like Buildroot tries to build ffmpeg before libcedar and thats the reason why it fails.

Unturned3 commented 2 years ago

It seems like Buildroot tries to build ffmpeg before libcedar and thats the reason why it fails.

Yes, I figured that out after much head-scratching... I did RTFM, but I must've ran a make clean or something of that effect in the middle of the process and forgot about it, so when I tried to re-build ffmpeg it ended up with that error.

By the way, if you don't mind me asking, did you have any success with the encoder? I remember that @niyazFattahov posted somewhere that the most he was able to achieve was 640x480 50FPS encoding at 100% CPU load, and it didn't work for anything above that. The 100% CPU occupation kind of defeats the point of a hardware encoder...

petit-miner commented 2 years ago

I'm currently stuck on the part with ffmpeg runtime issue, I hope I can fix it by compiling with glibc. The datasheet of the V3s mentions encoding of up to 720p @ 60 FPS. Yeah thats true, but if you do it in software it isn't in realtime anymore, so the encoder is somewhat useful.

niyazFattahov commented 2 years ago

720@60 if you use this library without ffmpeg I think: https://github.com/allwinner-zh/media-codec https://github.com/allwinner-zh/media-codec-lib and on bsp version (linux 3.4), not mainline

niyazFattahov commented 2 years ago

I've compiled it on Buildroot 2020.02.1, but stuck at launching ./a.out file for reading raw 1080p and getting .h264 here instruction you can try: https://www.cxyzjd.com/article/takeopen/79490010

Unturned3 commented 2 years ago

I'm currently stuck on the part with ffmpeg runtime issue, I hope I can fix it by compiling with glibc.

Did you use musl or uclibc-ng? I encountered lots of obscure build errors when using these. glibc is probably the safest bet for now (at least it solved the build errors in my case).

I've compiled it on Buildroot 2020.02.1, but stuck at launching ./a.out file for reading raw 1080p and getting .h264 here instruction you can try: https://www.cxyzjd.com/article/takeopen/79490010

Where can I get the bsp version with the 3.4 kernel? I've actually only used mainline so far.

petit-miner commented 2 years ago

I used uclibc-ng but ran into some runtime issues on the V3s itself. I'm recompiling with glibc as @niyazFattahov suggested.

niyazFattahov commented 2 years ago

I've compiled it on Buildroot 2020.02.1, but stuck at launching ./a.out file for reading raw 1080p and getting .h264 here instruction you can try: https://www.cxyzjd.com/article/takeopen/79490010

Where can I get the bsp version with the 3.4 kernel? I've actually only used mainline so far.

I compiled media-codec library on mainline linux in buildroot 2020.02.1 not bsp. BSP for v3s located here but it does not have cedar driver support: https://github.com/chengge/v3s-linux-sdk

petit-miner commented 2 years ago

FYI: 720P @ 30FPS seems to be working, I have only tested it with a testvideo within ffmpeg but should work just fine with a camera too.

niyazFattahov commented 2 years ago

FYI: 720P @ 30FPS seems to be working, I have only tested it with a testvideo within ffmpeg but should work just fine with a camera too.

v4l2 camera work only 720x480 resolution max, more resolution throw error like "ion_alloc_error"

Unturned3 commented 2 years ago

FYI: 720P @ 30FPS seems to be working, I have only tested it with a testvideo within ffmpeg but should work just fine with a camera too.

How's the CPU load when running 720p@30fps? I'll give it another try tomorrow

niyazFattahov commented 2 years ago

720p@30fps does not work with camera, only work with testvideo camera require MEMORY allocation, testvideo not requrie

petit-miner commented 2 years ago

Yes, that could be a problem, but I think I captured atleast a video with 720p before. That was without encoder, but I think I solved that with increasing the cma zones in the kernel settings.

niyazFattahov commented 2 years ago

increasing the cma zones didnt help me with ion_alloc problem

petit-miner commented 2 years ago

I can't test the performance, since ffmpeg is kinda stuck when trying to capture frames from my OV5640 and encode it to H264. Kernel is still running and I can exit ffmpeg and the created video file is empty. Same Issue here: https://github.com/aodzip/libcedarc/issues/2

niyazFattahov commented 2 years ago

I can't test the performance, since ffmpeg is kinda stuck when trying to capture frames from my OV5640 and encode it to H264. Kernel is still running and I can exit ffmpeg and the created video file is empty. Same Issue here: aodzip/libcedarc#2

could you write exact ffmpeg command do you use? use avi format not mp4

jlee167 commented 2 years ago

@petit-miner Are you guys using V3S Board like Lichee Pi? I am currently making a custom board with S3 to encode 1080p @ 30fps with this library.

I tried binary blob for 3.4 on H3 and V3S. Got good 1080 @30 on H3 through camera but failed encoding simple yuv file on V3S due to limited memory. I was hoping S3 will be good enough since it's got more RAM than V3S :/

petit-miner commented 2 years ago

@petit-miner Are you guys using V3S Board like Lichee Pi? I am currently making a custom board with S3 to encode 1080p @ 30fps with this library.

I tried binary blob for 3.4 on H3 and V3S. Got good 1080 @30 on H3 through camera but failed encoding simple yuv file on V3S due to limited memory. I was hoping S3 will be good enough since it's got more RAM than V3S :/

I'm using a custom board with an V3s. I can encode 720p, however it isn't in realtime. I'm trying to get the encoderdemo working, however I can't compile the encoderdemo.

petit-miner commented 2 years ago

w's the CPU load when running 720p@30fps? I'll give it another try tomorrow

It seems like the way we test the video encoder was somewhat wrong. My V3s is busy at 100% CPU just generating the testsrc video. If I create a raw yuv420P file:

ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 -c:v rawvideo -pix_fmt yuv420p test.yuv

and then pass it trough the encoder with ffmpeg I get encoding in realtime @ 720p:

ffmpeg -re -f rawvideo -pix_fmt yuv420p -s:v 1280x720 -r 30 -i test.yuv output.h264

However the video seems speed up like crazy and is much shorter as my raw yuv420p testfile. I also verified that the testfile looks ok. I tried adding -re to ffmpeg to slow it down somewhat but it didn't help at all. The encoderdemo program supplied by allwinner showed the exact same behaviour. Funny enough when we overloaded the CPU with generating the testsrc, the generated video file looked fine and I didnt have such issues.