Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket streaming relay & quality loose #389

Open
gregklka opened this issue Dec 31, 2021 · 2 comments
Open

WebSocket streaming relay & quality loose #389

gregklka opened this issue Dec 31, 2021 · 2 comments

Comments

@gregklka
Copy link

Hi guys,
I've 3 IP cameras connected to my WebSocket server and I wanna display only 1 camera live preview at the time via WebSockets.
To get a live camera preview I run the following command as a background thread:
ffmpeg -rtsp_transport tcp -i rtsp://mylogin:[email protected]:554/Streaming/Channels/102 -f mpegts -codec:v mpeg1video -s 640x480 -b:v 1000k -bf 0 http://localhost:4000/feed

front-end:

function renderLivePreview() {   
  canvasMain = document.getElementById('live-preview');        
  mainPlayer = new JSMpeg.Player(url, { 
    canvas: canvasMain, 
    preserveDrawingBuffer: true,
  });  
}

<canvas id="live-preview" className="LivePreview"></canvas>

Basically, live preview works fine until I start changing the source by terminating ffmpeg background process and running a new one. When I terminate and run these background threads a couple of times (it happens randomly) then some weird pixels are being displayed. Please see the two screens attached to the post.

Incorrect:
Zrzut ekranu z 2021-12-31 00-49-34

Correct:
If I refresh HTML page (F5) everything gets back normal.
Zrzut ekranu z 2021-12-31 00-49-46

I suspect:
a) memory is not properly cleaned
b) jsmpeg lib can't recover from a state when is a gap with data when I turn off and on another thread.
c) there is something wrong with my code.

Does anyone have an idea how to fix it?

@zhang22113
Copy link

Hi guys, I've 3 IP cameras connected to my WebSocket server and I wanna display only 1 camera live preview at the time via WebSockets. To get a live camera preview I run the following command as a background thread: ffmpeg -rtsp_transport tcp -i rtsp://mylogin:[email protected]:554/Streaming/Channels/102 -f mpegts -codec:v mpeg1video -s 640x480 -b:v 1000k -bf 0 http://localhost:4000/feed

front-end:

function renderLivePreview() {   
  canvasMain = document.getElementById('live-preview');        
  mainPlayer = new JSMpeg.Player(url, { 
    canvas: canvasMain, 
    preserveDrawingBuffer: true,
  });  
}

<canvas id="live-preview" className="LivePreview"></canvas>

Basically, live preview works fine until I start changing the source by terminating ffmpeg background process and running a new one. When I terminate and run these background threads a couple of times (it happens randomly) then some weird pixels are being displayed. Please see the two screens attached to the post.

Incorrect: Zrzut ekranu z 2021-12-31 00-49-34

Correct: If I refresh HTML page (F5) everything gets back normal. Zrzut ekranu z 2021-12-31 00-49-46

I suspect: a) memory is not properly cleaned b) jsmpeg lib can't recover from a state when is a gap with data when I turn off and on another thread. c) there is something wrong with my code.

Does anyone have an idea how to fix it?

How is your WebSocket connection switched? How was the last websocket closed?

@phoboslab
Copy link
Owner

How is your WebSocket connection switched? How was the last websocket closed?

See here for an example on how to switch between streams: #424 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants