Closed jmarshall120 closed 2 years ago
@jmarshall120 Hmm, I just checked but I don't have any trouble using HLS. What are the contents of /run/shm/hls/ directory? Also, please check to see if there are any nginx configurations related to the 403 Forbidden error.
Sorry, I knew I forgot to post some info the other day. /run/shm/hls is empty while picam is running:
pi@rpiz2:~ $ ls /run/shm/hls/ -al
total 0
drwxr-xr-x 2 www-data www-data 40 Jul 20 19:05 .
drwxrwxrwt 6 root root 120 Jul 20 19:05 ..
I've tried sudo ./picam -o /run/shm/hls --alsadev hw:1,0
with and without sudo
. The directory is empty both ways.
There's no configuration in nginx for the 403 error. My intuition is telling me that picam is not creating the output in the /run/shm/hls directory for some reason, despite the output of the picam command not showing any errors.
//////////////////////////////// I've narrowed the problem down to likely audio-related
So I've managed to get the stream partially working; however, I had to disable audio capture. I'm using this command now, which I am able to stream to a client: sudo ./picam -o /run/shm/hls --time
This also results in the index.m3u8 and multiple .ts files being in /run/shm/hls.
When specifying the audio device there have been no errors thrown. I've also confirmed my user is a member of the audio group:
pi@rpiz2:~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users input render netdev gpio i2c spi
EDIT: I don't have ffmpeg installed at present.
Thanks for your feedback. Unfortunately, I am unable to reproduce the issue regardless of the availability of audio. HLS files are successfully created with or without audio. Can you post the full picam output with the option --verbose
?
I still haven't worked this out. The /run/shm/hls directory only fills up when --noaudio is used (or the wrong asladev is sepcified so it disables audio automatically)
pi@tpiz2w:~$ cat run_picam.sh
sudo bash /home/pi/make_dirs.sh
cd /home/pi/picam && sudo ./picam -o /run/shm/hls --time --alsadev hw:1,0 --verbose > /var/log/picam.log 2>&1
pi@rpiz2:~ $ ./run_picam.sh
^C^C
pi@rpiz2:~$ cat /var/log/picam.log
video_width=1920
video_height=1080
video_fps=30.000000
video_pts_step=3000
video_gop_size=30
video_hflip=0
video_vflip=0
video_bitrate=4500000
video_avc_profile=baseline
video_avc_level=4.1
video_qp_min=-1
video_qp_max=-1
video_qp_initial=-1
video_slice_dquant=-1
alsa_dev=hw:1,0
audio_channels=1
audio_sample_rate=48000
audio_bitrate=40000
audio_volume_multiply=5.000000
is_hlsout_enabled=1
is_hls_encryption_enabled=0
hls_keyframes_per_segment=1
hls_number_of_segments=3
hls_encryption_key_uri=stream.key
hls_encryption_key=0x75b0a81de17487c88a47507a7e1fdf73
hls_encryption_iv=0x000102030405060708090a0b0c0d0e0f
hls_output_dir=/run/shm/hls
rtsp_enabled=0
rtsp_video_control_path=/tmp/node_rtsp_rtmp_videoControl
rtsp_audio_control_path=/tmp/node_rtsp_rtmp_audioControl
rtsp_video_data_path=/tmp/node_rtsp_rtmp_videoData
rtsp_audio_data_path=/tmp/node_rtsp_rtmp_audioData
tcp_enabled=0
tcp_output_dest=�)N�
auto_exposure_enabled=0
auto_exposure_threshold=5.000000
is_vfr_enabled=0
white_balance=auto
exposure_control=auto
awb_red_gain=0.000000
awb_blue_gain=0.000000
metering=average
manual_exposure_compensation=0
exposure_compensation=0.000000
manual_exposure_aperture=0
exposure_aperture=0
manual_exposure_shutter_speed=0
exposure_shutter_speed=0
manual_exposure_sensitivity=0
exposure_sensitivity=0
roi_left=0.000000
roi_top=0.000000
roi_width=1.000000
roi_height=1.000000
min_fps=-1.000000
max_fps=-1.000000
is_timestamp_enabled=1
timestamp_format=%a %b %d %l:%M:%S %p
timestamp_layout=15
timestamp_horizontal_margin=10
timestamp_vertical_margin=10
is_timestamp_abs_pos_enabled=0
timestamp_pos_x=0
timestamp_pos_y=0
timestamp_text_align=1
timestamp_font_name=FreeMono:style=Bold
timestamp_font_file=
timestamp_font_face_index=(null)
timestamp_font_points=14.000000
timestamp_font_dpi=96
timestamp_color=ffffff
timestamp_stroke_color=000000
timestamp_stroke_width=1
timestamp_letter_spacing=0
is_preview_enabled=0
is_previewrect_enabled=0
preview_x=0
preview_y=0
preview_width=0
preview_height=0
preview_hdmi=0
is_audio_preview_enabled=0
audio_preview_dev=plughw:0,0
record_buffer_keyframes=5
state_dir=state
hooks_dir=hooks
timestamp_initwith_font_name with font_name=FreeMono:style=Bold
opening ALSA device for capture: hw:1,0
final microphone channels: -1
configuring devices
Running without preview window
Opening camera...
[0:09:09.998477433] [1066] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3700-f30ad033
[0:09:10.084805819] [1068] INFO RPI raspberrypi.cpp:1368 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
Acquired camera -856006208
Configuring video...
[0:09:10.086533162] [1066] INFO Camera camera.cpp:1029 configuring streams: (0) 1920x1080-YUV420
[0:09:10.087206912] [1068] INFO RPI raspberrypi.cpp:759 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1920x1080-SGBRG10_1X10 - Selected unicam format: 1920x1080-pGAA
Camera streams configured
Available controls:
AeEnable : [false..true]
ExposureTime : [118..969249]
NoiseReductionMode : [0..4]
FrameDurationLimits : [32660..969367]
ColourCorrectionMatrix : [-16.000000..16.000000]
Saturation : [0.000000..32.000000]
AeMeteringMode : [0..3]
Contrast : [0.000000..32.000000]
ExposureValue : [-8.000000..8.000000]
AwbMode : [0..7]
AeConstraintMode : [0..3]
ScalerCrop : [(0, 0)/64x64..(0, 0)/1928x1080]
AnalogueGain : [1.000000..63.937500]
ColourGains : [0.000000..32.000000]
Brightness : [-1.000000..1.000000]
AeExposureMode : [0..3]
AwbEnable : [false..true]
Sharpness : [0.000000..16.000000]
Buffers allocated and mapped
preview: startPreview begin
preview: startPreview end
Video setup complete
Opened VideoEncoder on /dev/video11 as fd 26
Got 6 output buffers
Got 12 capture buffers
Codec streaming started
Requests created
Using crop P���U
cfr frame_time=33333
camera_set_metering_mode: average
camera_set_exposure_control: auto
camera_set_white_balance: auto
strcmp(off,auto)=223
strcmp(custom,auto)=128
strcmp(auto,auto)=0
found
enable AWB: 0
camera_set_custom_awb_gains: red=0.0, blue=0.0
Camera started!
audio setup
sample_rate: 48000
nb_samples: 1024
format: 1
audio_codec_ctx->ch_layout: 548899807632
av_frame->channel_layout: 548899807632
buffer_size=2048
allocated 2048 bytes for audio samples
audio_pts_step: 1920
configuring audio capture device
audio_sample_rate: 48000 (48000)
actual sample rate=48000 dir=0
setting microphone buffer size to 102400 (buffer_size=2048 alsa_buffer_multiply=50)
microphone: buffer size: 102400 frames (channels=1 buffer_size=2048 multiply=50)
microphone: setting period size to 1024
actual_period_size=1024 dir=0
audio capture device:
Hardware PCM card 1 'USB PnP Sound Device' device 0 subdevice 0
Its setup is:
stream : CAPTURE
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 1
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 102400
period_size : 1024
period_time : 21333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 1
stop_threshold : 102400
silence_threshold: 0
silence_size : 0
boundary : 7205759403792793600
appl_ptr : 0
hw_ptr : 0
audio device configured
[microphone started]capturing started
............................... 31.43 fps k=1 a-v=240 c-a=-32144 u=0 d=0 pts=120720
.............................. 29.96 fps k=2 a-v=-1440 c-a=-30339 u=0 d=0 pts=210720
.............................. 29.80 fps k=3 a-v=720 c-a=-31890 u=0 d=0 pts=300720
.............................. 30.31 fps k=4 a-v=-960 c-a=-31134 u=0 d=0 pts=390720
.............................. 29.90 fps k=5 a-v=-720 c-a=-31076 u=0 d=0 pts=480720
.............................. 29.97 fps k=6 a-v=-480 c-a=-31220 u=0 d=0 pts=570720
.............................. 30.04 fps k=7 a-v=-240 c-a=-31575 u=0 d=0 pts=660720
.............................. 30.05 fps k=8 a-v=-1920 c-a=-30044 u=0 d=0 pts=750720
.............................. 29.99 fps k=9 a-v=-1680 c-a=-30238 u=0 d=0 pts=840720
.............................. 30.08 fps k=10 a-v=-1440 c-a=-30709 u=0 d=0 pts=930720
.............................. 29.97 fps k=11 a-v=-1200 c-a=-30842 u=0 d=0 pts=1020720
.............................. 30.01 fps k=12 a-v=-960 c-a=-31108 u=0 d=0 pts=1110720
.............................. 30.05 fps k=13 a-v=-2640 c-a=-29581 u=0 d=0 pts=1200720
.............................. 30.01 fps k=14 a-v=-2400 c-a=-29829 u=0 d=0 pts=1290720
.............................. 30.07 fps k=15 a-v=-2160 c-a=-30281 u=0 d=0 pts=1380720
.............................. 30.03 fps k=16 a-v=-1920 c-a=-30590 u=0 d=0 pts=1470720
.............................. 29.68 fps k=17 a-v=-1680 c-a=-29848 u=0 d=0 pts=1560720
.............................. 30.35 fps k=18 a-v=-3360 c-a=-29195 u=0 d=0 pts=1650720
.............................. 29.75 fps k=19 a-v=-1200 c-a=-30590 u=0 d=0 pts=1740720
.............................. 29.99 fps k=20 a-v=-2880 c-a=-28871 u=0 d=0 pts=1830720
...............stop requested (signal=2)
.Halting
StopCamera
Camera stopped!
VideoEncoder closed
stopAudioThread begin
joining audio thread
joined audio thread
teardown_audio_capture_device
stopAudioThread end
stopRecThread begin
stopRecThread end
stop_watching_hooks
pthread_join hooks_thread
shutdown successful
Closing Libcamera application (preview frames displayed 617, dropped 0
StopCamera
Camera stopped!
preview: stopPreview begin
preview: stopPreview end
Tearing down requests, buffers and configuration
Camera closed
@jmarshall120 Are you able to record audio from the microphone with the arecord
command?
Yep, able to get an audio recording using
arecord --format=S16_LE --rate=48100 --file-type=wav out.wav
I've tried with 16000 too which also works (quality varies of course).
Thanks so much for your continued help!
Regarding arecord
command, --rate=48000
work as well?
Yep, all bit rates appear to work, just the quality is bad but I believe that's just the USB microphone.
Maybe time for a fresh Raspian install and go from scratch again?
@jmarshall120 Hmm, I don't know if starting over from scratch will solve the problem. Does it record audio when recorded with the following command while picam is running?
touch hooks/start_record && sleep 10 && touch hooks/stop_record
Recorded files will be created in the rec/archive/ directory.
@iizukanao Sorry for my slow response. Yes, that command does create a file that I can play back.
@jmarshall120 Hmm, I have no idea why only HLS does not work. If you could provide the SD card image, I might be able to look into it.
My apologies. I have confirmed that this issue occurs on 64-bit OS. I will be fixing this issue soon.
This bug has been fixed in version 2.0.4.
Thank you for all your hard work!
Thank you for letting me know the issue!
With the release of picam 2.0, I have migrated to Bullseye and completed the upgrade to the new picam version. Unfortunately, I am having issues using HLS.
I have included the required section in my /etc/nginx/sites-available/default file:
server { ... location /hls/ { root /run/shm; } ... }
I have temporarily disabled the picam init.d script and I am executing the following (in the picam folder), with it's output all looking fine (_makedirs.sh is executed prior):
sudo ./picam -o /run/shm/hls --alsadev hw:1,0
created directory: ./rec/tmp
[0:12:08.177808082] [675] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3700-f30ad033
[0:12:08.280450654] [677] INFO RPI raspberrypi.cpp:1368 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
[0:12:08.282136701] [675] INFO Camera camera.cpp:1029 configuring streams: (0) 1920x1080-YUV420
[0:12:08.282851078] [677] INFO RPI raspberrypi.cpp:759 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1920x1080-SGBRG10_1X10 - Selected unicam format: 1920x1080-pGAA
capturing started
I then attempt to access the stream using Firefox from a client computer and am met with the nginx "403 Forbidden" page
I then attempt to stream to VLC on the client using
http://192.168.2.8/hls/index.m3u8
which is throwing a "VLC is unable to open..." error.Here is the output of /var/log/nginx/access.log
192.168.2.166 - - [18/Jul/2022:20:17:52 +1000] "GET /hls/ HTTP/1.1" 403 125 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
192.168.2.166 - - [18/Jul/2022:20:20:29 +1000] "GET /hls/index.m3u8 HTTP/1.1" 404 153 "-" "VLC/3.0.17.2 LibVLC/3.0.17.2"
Here is the output of /var/log/nginx/error.log
2022/07/18 20:17:52 [error] 460#460: *1 directory index of "/run/shm/hls/" is forbidden, client: 192.168.2.166, server: _, request: "GET /hls/ HTTP/1.1", host: "192.168.2.8"
2022/07/18 20:20:29 [error] 460#460: *2 open() "/run/shm/hls/index.m3u8" failed (2: No such file or directory), client: 192.168.2.166, server: _, request: "GET /hls/index.m3u8 HTTP/1.1", host: "192.168.2.8"
I have also used
chown -R www-data:www-data
andchmod 744
on the /run/shm/hls directoryMy guess is that the index.m3u8 stream file isn't being created in the /run/shm/hls folder. Any ideas?