View previous topic :: View next topic |
Author |
Message |
EliasJonsson n00b
Joined: 18 Oct 2017 Posts: 53
|
Posted: Fri Apr 30, 2021 9:10 am Post subject: Raspberry pi hardware transcoding |
|
|
Is it possible to enable hardware accelerated ffmpeg video transcoding on Rapsberry Pi 4B running gentoo?
I have installed Gentoo on Raspberry Pi 4B but have no knowledge how one would go about enabling hardware accellerated video transcoding.
Code: |
ffmpeg -i tvattmaskin_oljud_2021-04-28.mp4 -c:v h264_v4l2m2m -b:v 8M -c:a copy test.mp4
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Gentoo 10.2.0-r5 p6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/share/doc/ffmpeg-4.3.2/html --mandir=/usr/share/man --enable-shared --cc=aarch64-unknown-linux-gnu-gcc --cxx=aarch64-unknown-linux-gnu-g++ --ar=aarch64-unknown-linux-gnu-ar --nm=aarch64-unknown-linux-gnu-nm --ranlib=aarch64-unknown-linux-gnu-ranlib --pkg-config=aarch64-unknown-linux-gnu-pkg-config --optflags='-O2 -pipe -march=armv8-a+crc -mtune=cortex-a72 -ftree-vectorize -fpredictive-commoning -fomit-frame-pointer' --disable-static --enable-avfilter --enable-avresample --disable-stripping --disable-optimizations --disable-libcelt --disable-indev=v4l2 --disable-outdev=v4l2 --disable-indev=alsa --disable-indev=oss --disable-indev=jack --disable-indev=sndio --disable-outdev=alsa --disable-outdev=oss --disable-outdev=sndio --enable-nonfree --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-gcrypt --enable-gnutls --disable-gmp --enable-gpl --disable-hardcoded-tables --enable-iconv --disable-libtls --disable-libxml2 --disable-lzma --enable-network --disable-opencl --disable-openssl --enable-postproc --disable-libsmbclient --disable-ffplay --disable-sdl2 --disable-vaapi --disable-vdpau --disable-vulkan --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable-libcaca --disable-openal --disable-opengl --disable-libv4l2 --disable-libpulse --disable-libdrm --disable-libjack --disable-libopencore-amrwb --disable-libopencore-amrnb --disable-libcodec2 --enable-libdav1d --enable-libfdk-aac --disable-libopenjpeg --disable-libbluray --disable-libgme --disable-libgsm --disable-libaribb24 --disable-mmal --disable-libmodplug --disable-libopus --disable-libilbc --disable-librtmp --disable-libssh --disable-libspeex --disable-libsrt --disable-librsvg --disable-ffnvcodec --enable-libvorbis --enable-libvpx --disable-libzvbi --disable-appkit --disable-libbs2b --disable-chromaprint --disable-cuda-llvm --disable-libflite --disable-frei0r --disable-libfribidi --disable-fontconfig --disable-ladspa --disable-libass --disable-libtesseract --disable-lv2 --disable-libfreetype --disable-libvidstab --disable-librubberband --disable-libzmq --disable-libzimg --disable-libsoxr --enable-pthreads --disable-libvo-amrwbenc --disable-libmp3lame --disable-libkvazaar --disable-libaom --disable-libopenh264 --disable-librav1e --disable-libsnappy --enable-libtheora --disable-libtwolame --enable-libwebp --enable-libx264 --enable-libx265 --disable-libxvid --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-altivec --disable-vsx --disable-power8 --disable-amd3dnow --disable-amd3dnowext --disable-aesni --disable-avx --disable-avx2 --disable-fma3 --disable-fma4 --disable-mmx --disable-mmxext --disable-sse --disable-sse2 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-xop --cpu=armv8-a+crc --disable-doc --disable-htmlpages --enable-manpages
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tvattmaskin_oljud_2021-04-28.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
location-eng : +60.6231+015.6054/
location : +60.6231+015.6054/
Duration: 00:00:16.53, start: 0.000000, bitrate: 1876 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1738 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x5564afdf00] Could not find a valid device
[h264_v4l2m2m @ 0x5564afdf00] can't configure encoder
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!
|
Here is my /boot/config.txt
Code: |
# set 64 bit mode
arm_64bit=1
enable_gic=1
armstub=armstub8-gic.bin
# have a properly sized image
disable_overscan=1
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# lets have the VC4 hardware accelerated video
dtoverlay=vc4-fkms-v3d
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# gpu_mem is for closed-source driver only; since we are only using the
# open-source driver here, set low
gpu_mem=16
#some overclocking of the RPi4
#over_voltage=6
#arm_freq=2000
#enables ffmpeg hardware accellerated video transcoding?
dtoverlay=rpivid-v4l2
|
and loaded modules:
Code: |
gen ~/raspberrypi/linux # lsmod
Module Size Used by
vc4 274432 0
cec 57344 1 vc4
drm_kms_helper 249856 2 vc4
snd_soc_core 237568 1 vc4
snd_compress 20480 1 snd_soc_core
cdc_acm 32768 2
snd_bcm2835 28672 0
snd_pcm_dmaengine 20480 1 snd_soc_core
brcmfmac 323584 0
brcmutil 24576 1 brcmfmac
snd_pcm 131072 5 vc4,snd_bcm2835,snd_compress,snd_soc_core,snd_pcm_dmaengine
snd_timer 36864 1 snd_pcm
sha256_generic 16384 0
snd 102400 5 snd_bcm2835,snd_timer,snd_compress,snd_soc_core,snd_pcm
v3d 81920 0
syscopyarea 16384 1 drm_kms_helper
sysfillrect 16384 1 drm_kms_helper
gpu_sched 45056 1 v3d
sysimgblt 16384 1 drm_kms_helper
cfg80211 876544 1 brcmfmac
bcm2835_codec 49152 0
bcm2835_isp 32768 0
fb_sys_fops 16384 1 drm_kms_helper
bcm2835_v4l2 45056 0
rpivid_hevc 49152 0
rfkill 36864 2 cfg80211
bcm2835_mmal_vchiq 32768 3 bcm2835_codec,bcm2835_v4l2,bcm2835_isp
v4l2_mem2mem 40960 2 bcm2835_codec,rpivid_hevc
videobuf2_vmalloc 20480 1 bcm2835_v4l2
videobuf2_dma_contig 24576 3 bcm2835_codec,rpivid_hevc,bcm2835_isp
vc_sm_cma 36864 2 bcm2835_mmal_vchiq,bcm2835_isp
videobuf2_memops 20480 2 videobuf2_vmalloc,videobuf2_dma_contig
videobuf2_v4l2 32768 5 bcm2835_codec,bcm2835_v4l2,rpivid_hevc,v4l2_mem2mem,bcm2835_isp
raspberrypi_hwmon 16384 0
videobuf2_common 61440 6 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,rpivid_hevc,v4l2_mem2mem,bcm2835_isp
videodev 311296 7 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,videobuf2_common,rpivid_hevc,v4l2_mem2mem,bcm2835_isp
mc 57344 7 videodev,bcm2835_codec,videobuf2_v4l2,videobuf2_common,rpivid_hevc,v4l2_mem2mem,bcm2835_isp
uio_pdrv_genirq 16384 0
uio 24576 1 uio_pdrv_genirq
nvmem_rmem 16384 0
sch_fq_codel 20480 6
drm 557056 5 gpu_sched,drm_kms_helper,v3d,vc4
drm_panel_orientation_quirks 20480 1 drm
fuse 131072 1
backlight 20480 1 drm
ipv6 540672 30
|
|
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54578 Location: 56N 3W
|
Posted: Fri Apr 30, 2021 9:32 am Post subject: |
|
|
EliasJonsson,
I'm not sure if you can get hardware accelerated transcoding but hardware accelerated video decoding is possible.
Remove from config.txt. You need either 128 or 256, I've forgotten which, to get /dev/rpivid-h264mem /dev/rpivid-hevcmem /dev/rpivid-intcmem /dev/rpivid-vp9mem to appear. The GPU needs more RAM to do its hardware thing.
Further, ffmpeg, used to need some patches to make this work too. I don't know if they have been unstreamed or not.
With an up to date kernel and Pi4 firmware, the config.txt entries
Code: | enable_gic=1
armstub=armstub8-gic.bin | are no longer required.
This can get you hardware accelerated video playback using ffmpeg. I don't think you can save the decoded video to a file, which is what transcoding means to me. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
EliasJonsson n00b
Joined: 18 Oct 2017 Posts: 53
|
Posted: Fri Apr 30, 2021 10:08 am Post subject: |
|
|
NeddySeagoon,
Thank you for pointing me in the right direction. As a result of that, I switched to the proprietary driver and increased its available memory:
/boot/config.txt
Code: | # set 64 bit mode
arm_64bit=1
# have a properly sized image
disable_overscan=1
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# lets have the VC4 hardware accelerated video
#dtoverlay=vc4-fkms-v3d
dtoverlay=vc4-kms-v3d-pi4.dtbo
gpu_mem=256
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
#some overclocking of the RPi4
#over_voltage=6
#arm_freq=2000
#enables ffmpeg hardware accellerated video transcoding
dtoverlay=rpivid-v4l2
|
and compilied ffmpeg with the v4l use flag:
/etc/portage/package.use
Code: | media-video/ffmpeg x264 x265 vorbis webp theora vpx fdk v4l |
then finally I was able to transcode using hardware acceleration:
ffmpeg -y -i tvattmaskin_oljud_2021-04-28.mp4 -c:v h264_v4l2m2m -b:v 1M -c:a copy test.mp4
Code: |
ffmpeg -y -i tvattmaskin_oljud_2021-04-28.mp4 -c:v h264_v4l2m2m -b:v 1M -c:a copy test.mp4
ffmpeg version 4.3.2 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Gentoo 10.2.0-r5 p6)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/share/doc/ffmpeg-4.3.2/html --mandir=/usr/share/man --enable-shared --cc=aarch64-unknown-linux-gnu-gcc --cxx=aarch64-unknown-linux-gnu-g++ --ar=aarch64-unknown-linux-gnu-ar --nm=aarch64-unknown-linux-gnu-nm --ranlib=aarch64-unknown-linux-gnu-ranlib --pkg-config=aarch64-unknown-linux-gnu-pkg-config --optflags='-O2 -pipe -march=armv8-a+crc -mtune=cortex-a72 -ftree-vectorize -fpredictive-commoning -fomit-frame-pointer' --disable-static --enable-avfilter --enable-avresample --disable-stripping --disable-optimizations --disable-libcelt --disable-indev=alsa --disable-indev=oss --disable-indev=jack --disable-indev=sndio --disable-outdev=alsa --disable-outdev=oss --disable-outdev=sndio --enable-nonfree --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-gcrypt --enable-gnutls --disable-gmp --enable-gpl --disable-hardcoded-tables --enable-iconv --disable-libtls --disable-libxml2 --disable-lzma --enable-network --disable-opencl --disable-openssl --enable-postproc --disable-libsmbclient --disable-ffplay --disable-sdl2 --disable-vaapi --disable-vdpau --disable-vulkan --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable-libcaca --disable-openal --disable-opengl --disable-libv4l2 --disable-libpulse --disable-libdrm --disable-libjack --disable-libopencore-amrwb --disable-libopencore-amrnb --disable-libcodec2 --enable-libdav1d --enable-libfdk-aac --disable-libopenjpeg --disable-libbluray --disable-libgme --disable-libgsm --disable-libaribb24 --disable-mmal --disable-libmodplug --disable-libopus --disable-libilbc --disable-librtmp --disable-libssh --disable-libspeex --disable-libsrt --disable-librsvg --disable-ffnvcodec --enable-libvorbis --enable-libvpx --disable-libzvbi --disable-appkit --disable-libbs2b --disable-chromaprint --disable-cuda-llvm --disable-libflite --disable-frei0r --disable-libfribidi --disable-fontconfig --disable-ladspa --disable-libass --disable-libtesseract --disable-lv2 --disable-libfreetype --disable-libvidstab --disable-librubberband --disable-libzmq --disable-libzimg --disable-libsoxr --enable-pthreads --disable-libvo-amrwbenc --disable-libmp3lame --disable-libkvazaar --disable-libaom --disable-libopenh264 --disable-librav1e --disable-libsnappy --enable-libtheora --disable-libtwolame --enable-libwebp --enable-libx264 --enable-libx265 --disable-libxvid --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-altivec --disable-vsx --disable-power8 --disable-amd3dnow --disable-amd3dnowext --disable-aesni --disable-avx --disable-avx2 --disable-fma3 --disable-fma4 --disable-mmx --disable-mmxext --disable-sse --disable-sse2 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-xop --cpu=armv8-a+crc --disable-doc --disable-htmlpages --enable-manpages
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tvattmaskin_oljud_2021-04-28.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
location-eng : +60.6231+015.6054/
location : +60.6231+015.6054/
Duration: 00:00:16.53, start: 0.000000, bitrate: 1876 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1738 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandle
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x55b0593f00] Using device /dev/video11
[h264_v4l2m2m @ 0x55b0593f00] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x55b0593f00] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x55b0593f00] Failed to set gop size: Invalid argument
Output #0, mp4, to 'test.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
location : +60.6231+015.6054/
location-eng : +60.6231+015.6054/
encoder : Lavf58.45.100
Stream #0:0(eng): Video: h264 (h264_v4l2m2m) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 1000 kb/s, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandle
encoder : Lavc58.91.100 h264_v4l2m2m
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandle
[mp4 @ 0x55b0563950] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.
frame= 496 fps= 46 q=-0.0 Lsize= 2294kB time=00:00:16.50 bitrate=1139.0kbits/s speed=1.54x
video:2019kB audio:260kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.673500%
|
Problem solved. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|