bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
12.2k stars 1.53k forks source link

HLS not working on Mobile Phone IOS or Android when there's no audio track #816

Closed Tabarane closed 2 years ago

Tabarane commented 2 years ago

Which version are you using?

v0.17.116

Which operating system are you using?

Describe the issue

Description using old version from rtsp-simple-server "0.17.11" HLS on mobile phone works normally , latest version it keep loading nothing show up

rtsp-simple-server log show that connection is made and is sending frames but still nothing showing up on mobile phone, we test with safari , chrome , Samsung internet

calebcoverdale commented 2 years ago

I can also confirm I am having the same issues on my end with newer version of iPhone OS + HLS. Issue doesn't happen on iPadOS, or macOS from what I have seen running the latest iOS15 Betas, but the issue persists specifically on iPhone.

Tabarane commented 2 years ago

does anyone need logs or something to help us fix this issue on latest version, i just did test with 017.17 and still the same issue exist :( just let me know how to help

aler9 commented 2 years ago

Hello @Tabarane , the issue you described is too generic and i wasn't able to replicate it. Please provide at least:

Tabarane commented 2 years ago

This is HLS configuration, attaching Log file in 5min , and i use Safari IOS to view, and Publish of the path is below

`###############################################
# HLS parameters

# disable support for the HLS protocol.
hlsDisable: no
# address of the HLS listener.
hlsAddress: :8888
# by default, HLS is generated only when requested by a user.
# this option allows to generate it always, avoiding the delay between request and generation.
hlsAlwaysRemux: no
# number of HLS segments to generate.
# increasing segments allows more buffering,
# decreasing segments decreases latency.
hlsSegmentCount: 3
# minimum duration of each segment.
# the final segment duration is also influenced by the interval between IDR frames,
# since the server changes the segment duration to include at least a IDR frame in each one.
hlsSegmentDuration: 1s
# Maximum size of each segment.
# This prevents RAM exhaustion.     
hlsSegmentMaxSize: 50M
# value of the Access-Control-Allow-Origin header provided in every HTTP response.
# This allows to play the HLS stream from an external website.
hlsAllowOrigin: '*'
###############################################`
`  video0:
   runOnDemand: ffmpeg -hide_banner -re -stream_loop -1 -i video0.webm -vf "drawtext='fontfile=./Robot.ttf:fontsize=14:fontcolor=yellow:text='%{localtime}':box=1:boxcolor=black@1:boxborderw=2:x=2:y=2" -vcodec h264_qsv -preset veryfast -r 25 -g 30 -s 1280x720 -b:v 1000k -max_muxing_queue_size 1024 -f rtsp rtsp://127.0.0.1:$RTSP_PORT/$RTSP_PATH 
   runOnDemandRestart: yes`

ffmpeg version n4.4-18-gc813f5e343

Server Log Debug

server.log

aler9 commented 2 years ago

Please try this configuration and let me know if it works. I tested it on Android and iOS and i couldn't find any problem.

paths:
  video0:
   runOnDemand: >
     ffmpeg -hide_banner -re -f lavfi -i testsrc=duration=1000:size=1280x720:rate=30
     -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024
     -f rtsp rtsp://127.0.0.1:$RTSP_PORT/$RTSP_PATH
   runOnDemandRestart: yes
Tabarane commented 2 years ago

@aler9 same issue, i have attached new log after new setting you mentioned also i have uploaded my config file for you in case it will help, i might not have big experience in FFMPEG parameter , please note im testing on Windows environments, the HLS transmission is working fine with my old parameter for video0 with older version of RTSP SIMPLE SERVER, like 0.17.11

my current tests is onRTSP SIMPLE SERVER 0.17.17 server.log config.yml.txt

aler9 commented 2 years ago

The configuration i posted above works perfectly for me. Since it was not possible to replicate the problem, we can't assert that the problem depends on the server. It may depend on any of the components you're using to stream (OS, ffmpeg, video file, phones). Nothing can be done here until you're able to correctly identify the problem.

I suggest you to take the exact configuration i posted above (with testsrc) and test it apart from your setup. When it works (and i'm sure it works), you can progressively add the rest of your configuration until you find the issue.

Tabarane commented 2 years ago

@aler9 ok i will start doing it step by step until i figure why, i will try not with file i will try with re-streaming RTSP or Proxy mode via HLS and will note all in the Server log and share again, my issue that it works with older version in same setup same scenario, i even had my friend phone which is Andriod phone and has the same issue, OS im trying on Ubuntu & Windows 10, will try also different FFMPEG in case it reached this level

Thanks alot will get back soon i hope here, Maybe @calebcoverdale can you share your files Log and it might help us

aler9 commented 2 years ago

The only difference between v0.17.11 and v0.17.12 is that the progressive mode of hls.js was enabled. But hls.js is used only on browsers that don't support natively HLS, therefore the change doesn't influence Safari and iPhone.

Tabarane commented 2 years ago

@aler9 i have created network traffic dump between RTSP Simple Server "10.10.101.109" and my iPhone 13 Pro Max "10.10.203.162" , maybe this dump can show us something that we can't see from normal log HLS.zip

i will continue testing with different parameter, below current HLS config

###############################################
# HLS parameters

# disable support for the HLS protocol.
hlsDisable: no
# address of the HLS listener.
hlsAddress: :8888
# by default, HLS is generated only when requested by a user.
# this option allows to generate it always, avoiding the delay between request and generation.
hlsAlwaysRemux: no
# number of HLS segments to generate.
# increasing segments allows more buffering,
# decreasing segments decreases latency.
hlsSegmentCount: 3
# minimum duration of each segment.
# the final segment duration is also influenced by the interval between IDR frames,
# since the server changes the segment duration to include at least a IDR frame in each one.
hlsSegmentDuration: 1s
# Maximum size of each segment.
# This prevents RAM exhaustion.     
hlsSegmentMaxSize: 50M
# value of the Access-Control-Allow-Origin header provided in every HTTP response.
# This allows to play the HLS stream from an external website.
hlsAllowOrigin: '*'
############################################### 

Video00 Config

  video00:
   runOnDemand: ffmpeg -hide_banner -re -stream_loop -1 -i video0.webm -f lavfi -i testsrc=duration=1000:size=1280x720:rate=30 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024 -f rtsp rtsp://127.0.0.1:$RTSP_PORT/$RTSP_PATH
   runOnDemandRestart: yes
akunz commented 2 years ago

From my understanding since some time an EXT-X-PROGRAM-DATE-TIME tag has been required in every live/linear media playlist. Please check point 8.4 in the specification. I guess this will solve the problem on newer devices.

aler9 commented 2 years ago

@akunz thank you very much for the tip, i'll produce a nightly release ASAP.

aler9 commented 2 years ago

I added the EXT-X-PROGRAM-DATE-TIME tag (thanks @akunz, i just needed that for a project in my job that needs syncing between video and metadata, i thought i needed to implement timed metadata and spend hours on the issue, this solved everything in less than 5 mins), please test this nightly release and let me know if there's any difference: [link removed]

Tabarane commented 2 years ago

@aler9 testing right now, same setting as mentioned above

Tabarane commented 2 years ago

@aler9 my first test on IOS has same results as before , w will test different devices and give feedback, do you need network dump? and debug log?

Tabarane commented 2 years ago

Ok, now this is very strange behavior , i requested video from rtsp server, safari keep showing the loading progress and black screen, while i stopped the server and started it again, the video in safari started directly after the restart

i can record phone screen and share video if this will help you or let me know how i can show you which ever data you need, i apologies if i seems like spamming but i highly appreciate your help with this app, it just an amazing project mate

aler9 commented 2 years ago

@Tabarane are you sure you tried with testsrc, before trying with video0.webm?

Tabarane commented 2 years ago

@aler9 100% , in windows browser it works , but with mobile phone same behavior image

aler9 commented 2 years ago

here's another nightly release, this time with progressive mode disabled and hls.js downgraded to v1.0.0 (this was the only change between v0.17.11 and v0.17.12) [link removed]

Tabarane commented 2 years ago

on windows still , same when i shutdown server and start it again then video loads up, i think i need to gather network dump and test in linux before you can take more approach , i want to give you as much details as needed specially if you revert hls support to 17.11 this what i can think of :(

Curid commented 2 years ago

@Tabarane You could find the exact commit that introduced the bug. https://www.git-tower.com/learn/git/faq/git-bisect/

Tabarane commented 2 years ago

@aler9 after a lot of testing, i have downloaded every release from 0.17.11 till 0.17.14 and HLS over Phones was working perfectly, its when i downloaded 0.17.15 where HLS over phones has stopped working and introduced the issue.

the behavior is same, when HLS url requested , it shows black screen loading with no video, BUT if i closed the server and start it again, it takes around 5 second and the HLS video will start playing in Safari

Do you need traffic dump and debug log from this attempt?

akunz commented 2 years ago

I can confirm the described problem as well. My first thouth was about the EXT-X-PROGRAM-DATE-TIME tag when I read this issue. I still think the tag is needed and useful, even it is not the solution to fix the current problem. Thank you so much for adding this additional tag. I did some research on the segments generated by rtsp-simple-server and there is a difference in the generation of audio between version 0.17.14 and the nightly release 0.17.17-15. FFmpeg also shows some warnings about timestamps, but I guess the problem is caused by the audio. The sample configuration using testsrc does not generate audio and it looks like rtsp-simple-server handles audio differently in this situation. When we add audio to the testsrc command, it works fine for me, even in newer Safari browser and some other players.

Tabarane commented 2 years ago

@akunz can you advice how to test with audio using ffmpeg testsrc? below is my config im testing with, if you can add the audio part it would be great so i can test also

  video00:
   runOnDemand: ffmpeg -hide_banner -re -stream_loop -1 -f lavfi -i testsrc=duration=1000:size=1280x720:rate=30 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024 -f rtsp rtsp://127.0.0.1:$RTSP_PORT/$RTSP_PATH
   runOnDemandRestart: yes
akunz commented 2 years ago

You can add audio (sine wave) by the following option:

-f lavfi -i sine=frequency=1000:sample_rate=48000

Your config should look like this:

  video00:
   runOnDemand: ffmpeg -hide_banner -re -stream_loop -1 -f lavfi -i testsrc=duration=1000:size=1280x720:rate=30 -f lavfi -i sine=frequency=1000:sample_rate=48000 -pix_fmt yuv420p -c:v libx264 -preset ultrafast -b:v 500k -max_muxing_queue_size 1024 -f rtsp rtsp://127.0.0.1:$RTSP_PORT/$RTSP_PATH
   runOnDemandRestart: yes
Tabarane commented 2 years ago

@akunz @aler9 i can confirm, when i added -f lavfi -i sine=frequency=1000:sample_rate=48000 video started to play normally over HLS, even if it was my own video files, just added the audio feed made the server response to IOS safari and it was working , test was made on 0.17.17

noelhibbard commented 2 years ago

I have an RTSP stream that also doesn't have audio and I can confirm it will not playback via HLS on iOS. I am going to try adding a dummy audio track and see if that solves my issue.

aler9 commented 2 years ago

This issue has been solved.... it was caused by this terrible Golang behavior:

package main

import "fmt"

type Track interface{}
type trackImpl struct{}

func testFunc(tr Track) {
    if tr != nil {
        fmt.Println("track is not nil")
    } else {
        fmt.Println("track is nil")
    }
}

func main() {
    var tr *trackImpl = nil
    testFunc(tr)
}

even though tr is nil, this code prints "track is not nil" :man_facepalming:

aler9 commented 2 years ago

Please try this nightly release and let me know if it works: [link removed]

Tabarane commented 2 years ago

Tested on Windows , and working fine on IOS without audio track, now working as expected as before

Tabarane commented 2 years ago

Tested on Debian Based, issue still exist unless we add fake sound parameter

aler9 commented 2 years ago

The fix has been added in v0.18.0. Regarding the Debian bug, please open a new issue and provide details.

jamieduk commented 1 year ago

I have no sound it is disabled (muted) in all browsers on load by default how do i fix this bug? im using linux pre compiled binary?

aler9 commented 1 year ago

@jamieduk audio must be disabled in order for the video to play automatically, it's a restriction imposed by browsers. You can read more here https://developer.chrome.com/blog/autoplay/

github-actions[bot] commented 1 year ago

This issue is being locked automatically because it has been closed for more than 6 months. Please open a new issue in case you encounter a similar problem.