guysoft / OctoPi

Scripts to build OctoPi, a Raspberry PI distro for controlling 3D printers over the web
GNU General Public License v3.0
2.45k stars 366 forks source link

HLS V4L2 M2M encoder #784

Closed chudsaviet closed 1 year ago

chudsaviet commented 1 year ago
  1. Building FFmpeg from source for HLS.
  2. Using V4L2 M2M encoder.

Tested on Raspberry Pi OS 32bit and 64bit. CPU load on Rpi4 is around 10%.

guysoft commented 1 year ago

Thanks for your contribution!

chudsaviet commented 1 year ago

@guysoft , I see this pull request caused build time to increase from 10 minutes to 2 hours. I can go disable unnecessary codecs from ffmpeg build, but it won’t help dramatically.

cp2004 commented 1 year ago

I wonder if there is a way ffmpeg could be built once, and then the binary just downloaded from somewhere as part of the OctoPi image? Since it is building from a specific commit it seems like it shouldn't have to re-build every time.

guysoft commented 1 year ago

Should be able to be built once. I will have to look in to it though

guysoft commented 1 year ago

Could be built and exported once using copy_and_export_folder from CustomPiOS. Then loaded if it already exists from a web server.

guysoft commented 1 year ago

@chudsaviet Hey, This is currently breaking the nightly, because the nightly build is done on a raspberrypi running a 32bit userspace and a 64bit kernel.

The ffmpeg build determines the build arch according to the kernel used and this causes the build to fail.

There should be a flag to tell it explicitly based on on what CustomPiOS is building what arch to build for.

Attaching a filed log:

cd FFmpeg-FFmpeg-9450f75
+ ./configure --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-ffplay --disable-ffprobe
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      aarch64 (genericcd FFmpeg-FFmpeg-9450f75
+ ./configure --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-ffplay --disable-ffprobe
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      aarch64 (generic

consoleText.txt

chudsaviet commented 1 year ago

I was building in Docker on a M1 Mac, both 32 bit and 64bit worked.
Anyway, we will have to switch to prebuilt binary. And when FFmpeg will have the next version released, we will be able to switch back to FFmpeg from repository.

guysoft commented 1 year ago

I think there should be a way to pass the configure what arch to build for.

chudsaviet commented 1 year ago

Yes, I believe configure uses arch command to determine architecture.

guysoft commented 1 year ago

Fixed, builds on both now

guysoft commented 1 year ago

Current devel branch exports ffmpeg HLS that is built to the workspace folder. So we could have some logic that you place that inside OctoPi/src/modules/octopi/filesystem/hls . Then the build script can use unpack and check it it has a pre-built binary or not. So you could have a shorter build time.

chudsaviet commented 1 year ago

I see. Exact mechanism is not the problem.
The problem is managing binaries and their security. I'm not very eager to go this deep. Also, after next FFmpeg version will be released, we will be able just to use ffmpeg from OS repo. I was working on next things:

  1. Minimizing FFmpeg build options, so its builds much faster.
  2. Ensuring that in CustomPiOS /tmp is mounted as tmpfs, so the build is faster. Can you help me on this?
guysoft commented 1 year ago

It seems like it would just be best to wait after FFmpeg version will be released.

  1. I am not sure what to remove
  2. You don't necessarily have access to tmpfs. It depends on your build environment.
guysoft commented 1 year ago

We might want to add instructions how to activate it if you would like to add that

chudsaviet commented 1 year ago

Yeah, sorry, I had much work last couple of weeks.
“activate it” - what do you mean? “I am not sure what to remove” - there are dozens of codecs in ffmpeg, and for HLS, we don’t need most of them. We can build a limited ffmpeg just for HLS, and use standard ffmpeg from repository for everything else.

guysoft commented 1 year ago

I mean that I am not sure the setting in octopi.txt is documented.

chudsaviet commented 1 year ago

It was experimental, so I haven't documented it in the past.
Which document shall I put the info to?

guysoft commented 1 year ago

It should go https://github.com/guysoft/OctoPi/wiki But that also needs some care ATM, I don't know if its worth sending you there to document. Unless if you think it would help.