Coder Social home page Coder Social logo

soyersoyer / fmp4streamer Goto Github PK

View Code? Open in Web Editor NEW
76.0 76.0 6.0 389 KB

Fmp4streamer streams your V4L2 camera directly to any browser and media player as MP4 (H264).

License: Apache License 2.0

Python 100.00%
fmp4 h264 hls http http-streaming ios iphone linux mjpg mp4 mp4-streaming mp4-video pi-camera python raspberry-pi streaming v4l2 v4l2-m2m video webcam

fmp4streamer's People

Contributors

ch3ri0ur avatar dans98 avatar soyersoyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fmp4streamer's Issues

ISO 14496

I noticed that you referenced ISO 14496 part 12 and 15 in bmff.py. I'm working on a similar project to this one right now. Would you have any recommendations for ways to get these standards, drafts, detailed descriptions, or reference/other implementations? I've only been able to get ISO 14496-12:2003 so far, which is quite outdated judging by page count, and the 2020 edition for 67 € at evs.ee.

Latency

Hi, how can i reduce the latency? There Is a buffer config?
Thanks

Error

I am so sorry, i have an error running the fmp4streamer.py.

Waiting for the first h264 frame...Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/home/pi/Desktop/touchUI/fmp4streamer/v4l2camera.py", line 274, in run
self.start_capturing()
File "/home/pi/Desktop/touchUI/fmp4streamer/v4l2camera.py", line 243, in start_capturing
ioctl(self.fd, v4l2.VIDIOC_STREAMON, struct.pack('I', v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE))
OSError: [Errno 22] Invalid argument

Trouble when starting fmp4streamer

Platform: Raspberry pi 2W
OS: Raspberry Pi, Bullseye
Camera v1.3
Hardware works fine
Camera autodetect = 1

Configuration file:
fmp4.txt

Here is the messages displayed when running fmp4streamer
Capture d’écran de 2023-08-27 06-07-48

How can I make it run?

Add audio from USB microphone

Great project! Any chance of adding audio from the USB microphone when creating the mp4 frames? If you have some pointers on how to do that I can do some coding and submit a PR.

IP Camera Adapter

Hello, I have been able to connect to my raspberry pi video via an internet browser and have gotten to watch the video live. However, I am attempting to connect to it with an MJPEG IP camera adapter but I keep getting an error: "Some other HTTP error: 301". I understand this is probably because the MP4Streamer is listening in on the H264 stream, but I was hoping you might have an idea of a work-around or some way to fix this. I apologize if this is a dumb question but I am fairly new to the Raspberry pi game.
Thank you

Logitech C920 no H264 on Pi Zero W

I have C920 here and 1920x1080@30fps doesn't work.
Raspberry Pi Zero W + OS Buster Lite version.
Only I can get is 5 fps with capture_format = YUYV

Device: /dev/video0
Name: HD Pro Webcam C920
Driver: uvcvideo

Controls
brightness = 128	( default: 128 min: 0 max: 255)
contrast = 128	( default: 128 min: 0 max: 255)
saturation = 128	( default: 128 min: 0 max: 255)
white_balance_temperature_auto = 1	( default: 1 min: 0 max: 1)
gain = 169	( default: 0 min: 0 max: 255)
power_line_frequency = 60 Hz	( default: 60 Hz values: 'Disabled' '50 Hz' '60 Hz' )
white_balance_temperature = 3066	( default: 4000 min: 2000 max: 6500)
sharpness = 128	( default: 128 min: 0 max: 255)
backlight_compensation = 0	( default: 0 min: 0 max: 1)
exposure_auto = Aperture Priority Mode	( default: Aperture Priority Mode values: 'Manual Mode' 'Aperture Priority Mode' )
exposure_absolute = 333	( default: 250 min: 3 max: 2047)
exposure_auto_priority = 1	( default: 0 min: 0 max: 1)
pan_absolute = 0	( default: 0 min: -36000 max: 36000 step: 3600)
tilt_absolute = 0	( default: 0 min: -36000 max: 36000 step: 3600)
focus_absolute = 0	( default: 0 min: 0 max: 250 step: 5)
focus_auto = 1	( default: 1 min: 0 max: 1)
zoom_absolute = 100	( default: 100 min: 100 max: 500)
uvcx_h264_stream_mux = None	( default: None values: 'None' 'H264' )
uvcx_h264_width = 1920	( default: 1920 min: 160 max: 1920)
uvcx_h264_height = 1080	( default: 1080 min: 120 max: 1080)
uvcx_h264_frame_interval = 333333	( default: 333333 min: 333333 max: 2000000)
uvcx_h264_bitrate = 3000000	( default: 3000000 min: 64000 max: 12000000)
uvcx_h264_rate_control_mode = CBR	( default: CBR values: 'CBR' 'VBR' 'Const QP' )
uvcx_h264_profile = Constrained	( default: Constrained values: 'Constrained' 'Baseline' 'Main' 'High' )
uvcx_h264_i_frame_period = 10000	( default: 10000 min: 0 max: 50000)
uvcx_h264_slice_mode = SlicesPerFrame	( default: SlicesPerFrame values: 'Off' 'BitsPerSlice' 'MBsPerSlice' 'SlicesPerFrame' )
uvcx_h264_slice_units = 4	( default: 4 min: 0 max: 68)
uvcx_h264_entropy = CAVLC	( default: CAVLC values: 'CAVLC' 'CABAC' )
uvcx_h264_usage = Realtime	( default: Realtime values: 'Realtime' 'Broadcast' 'Storage' )
uvcx_h264_leaky_bucket_size = 1000	( default: 1000 min: 500 max: 4000)

Device: /dev/video11
Name: bcm2835-codec-encode
Driver: bcm2835-codec

Controls

Codec Controls

video_bitrate_mode = Variable Bitrate	( default: Variable Bitrate values: 'Variable Bitrate' 'Constant Bitrate' )
video_bitrate = 10000000	( default: 10000000 min: 25000 max: 25000000 step: 25000)
sequence_header_mode = Joined With 1st Frame	( default: Joined With 1st Frame values: 'Separate Buffer' 'Joined With 1st Frame' )
repeat_sequence_header = 0	( default: 0 min: 0 max: 1)
Force Key Frame = 
h264_i_frame_period = 1	( default: 60 min: 0 max: 2147483647)
h264_level = 4.2	( default: 4 values: '1' '1b' '1.1' '1.2' '1.3' '2' '2.1' '2.2' '3' '3.1' '3.2' '4' '4.1' '4.2' )
h264_profile = High	( default: High values: 'Baseline' 'Constrained Baseline' 'Main' 'High' )

To set one, put ctrl_name = Value into fmp4streamer.conf under the device

Port 80 unusable?

Hello,

Is there a way to use port 80?
It seems service canot start when I try

● fmp4streamer.service - fmp4streamer
     Loaded: loaded (/home/pi/fmp4streamer-3.4.7/fmp4streamer.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-09-16 19:29:21 CEST; 55s ago
   Main PID: 1132 (python3)
      Tasks: 2 (limit: 724)
        CPU: 1.571s
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/fmp4streamer.service
             └─1132 python3 -u fmp4streamer.py

Sep 16 19:29:23 cam python3[1132]:     server = StreamingServer((config.get('server', 'listen'), config.getint('server', 'port')), StreamingHandler)
Sep 16 19:29:23 cam python3[1132]:   File "/usr/lib/python3.9/socketserver.py", line 452, in __init__
Sep 16 19:29:23 cam python3[1132]:     self.server_bind()
Sep 16 19:29:23 cam python3[1132]:   File "/home/pi/fmp4streamer-3.4.7/fmp4streamer.py", line 218, in server_bind
Sep 16 19:29:23 cam python3[1132]:     server.HTTPServer.server_bind(self)
Sep 16 19:29:23 cam python3[1132]:   File "/usr/lib/python3.9/http/server.py", line 138, in server_bind
Sep 16 19:29:23 cam python3[1132]:     socketserver.TCPServer.server_bind(self)
Sep 16 19:29:23 cam python3[1132]:   File "/usr/lib/python3.9/socketserver.py", line 466, in server_bind
Sep 16 19:29:23 cam python3[1132]:     self.socket.bind(self.server_address)
Sep 16 19:29:23 cam python3[1132]: PermissionError: [Errno 13] Permission denied

Allow camera to be turned on/off

I'm thinking about using this for a baby monitor, and I don't need the camera on the whole time. I also have single-client access.

So my idea was to only access the camera when a client is connected.

I tried playing with it a bit and I naively thought that creating/destroying the camera thread inside elif on line 145 would do, but of course the fd needs to be closed/reopened, and it doesn't work like that. Also, closing it is not so simple because it would need to signal the main_loop to stop, wait for it to stop using the device file, and then close it.

Any thoughts on how I could approach this? Or would you consider offering a "disconnect camera when no user is connected" (which is probably much simpler for single-client use)?

Thanks

Piping h264 video stream to stdout

Hi,
First of all, thank you for the great project. I am currently working with a Raspberry Pi 2 and a Logitech C925e.
The local streaming with your project works on the first try, but unfortunately this is not what I want to achieve.
I would like to transfer the h264 stream of the camera via rtmp to Youtube.
I already got this working successfully with ffmpeg and the raspberry pi camera and I think the easiest way would be to use the ffmpeg software for the Logitech camera as well.
For this project I would have to write the h264 camera data to stdout and forward it to ffmpeg.
Currently I am not sure how to implement this. Where can I find the h264 video data and how can I write it to stdout?

I would be grateful for any help.
Best regards,
Sven

Frame Tearing with a Kiyo Pro at 1080p

I'm running this on an RPi 4 with a Kiyo Pro at 1080p. Here's my config:

[server]
listen =
port = 8000
[/dev/video0]
width = 1920
height = 1080
fps = 30

# Device capture format (default: H264)
# H264, MJPGH264, YUYV, MJPG, JPEG
capture_format = NV12

# Decoder M2M device (default: disabled)
# To decode the stream to a compatible format with the encoder (eg MJPG -> NV12 -> H264)
# decoder = /dev/video10

# Encoder M2M device (default: disabled)
# To encode the stream to H264 (eg YUYV -> H264 or MJPG -> NV12 -> H264)
encoder = /dev/video11

# Auto Sleep mode (default: yes)
# Sleep the camera when no one is watching the stream
auto_sleep = yes

# Controls

# you can set any V4L2 control too, list them with the -l option
h264_profile = High
h264_level = 4.2
h264_i_frame_period = 15

uvcx_h264_i_frame_period = 1000
uvcx_h264_profile = High

# Advanced (change only if you know, what you are doing)

# Buffer memory configurations (MMAP or DMABUF)
# Sometimes contigous memory is not large enough for hardwares and tuning needed

# default: DMABUF if encoder or decoder else MMAP
# capture_memory = DMABUF

# decoder_memory = MMAP-DMABUF
# encoder_memory = MMAP-MMAP

# Input format for the decoder (default: MJPG if capture_format == JPEG else capture_format)
# If the capture_format isn't supported by the decoder directly,
# but it can decode it with another format eg (capture_format = JPEG, decoder_input_format = MJPG)
# decoder_input_format = MJPG

# Input format for the encoder (default: NV12 if decoder else capture_format)
# encoder_input_format = NV12

My problem is that randomly and particularly when there's motion (like waving my hand in front of the camera), the video feed will "tear" where below some line the image in my browser will be corrupted. It's almost like the frame data is getting truncated, but I don't see how that could make sense for h264 encoded video?

I'm going to try a different camera to be sure and see if I can upload a video that shows the issue if it still reproes. Have you heard of or seen anything similar before?

Clarify with examples of some popular webcams

Hi

I'm not sure if I'm misunderstanding this project.

Perhaps I can clarify what my expectations were:
I'm wanting to stream something like 1080p from a Logitech C930e at a more realistic frame rate like 30fps.
Using just the RPI you would run into 1 of two situations when you attempt that

  1. You stream JPEG files which has an insane data rate and thus kills the RPI network
  2. You encode it to a format like H.264/H.265 etc. and save on data rate but kill the CPU

My understanding of this project is, you can do 2 without killing the CPU.

However when I configure a Logitech C930e I just get worse performance than simply using mjpg-streamer, the latency goes way up on the image. It is basically lagging seconds behind.

My ask is, is it possible to perhaps clarify the goal of the project and provide some examples, especially for the popular webcams. I realise you did this to an extent with the Raspberry Pi cam, but you seem to also own a Logitech C930e (or similar) but I don't see any examples that motivate this project to me at all.

OFC, you can simply just ignore me and I'm sure many others will still continue using your project but as it stands now I think your adoption could be significantly improved, in for example, the 3d printer space if some of the above becomes possible (point 2 above specifically)

ERROR:root:/dev/video0 H264 format not available with RPi 4 and RPi Camera V2

Hi,

I run this on a RPi 4 (Octoprint installed without mjpg-streamer) with a RPi Camera V2.
When I start it, I get this output

python3 fmp4streamer.py
WARNING:root:Can't find h264_profile v4l2 control
WARNING:root:Can't find h264_level v4l2 control
WARNING:root:Can't find h264_i_frame_period v4l2 control
ERROR:root:/dev/video0 H264 format not available

How can I solve this issue?

Thanks a lot
Josef

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.