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

MJPEG source -> MJPEG output quality degradation #559

Closed
mvdarend opened this issue Aug 3, 2023 · 14 comments
Closed

MJPEG source -> MJPEG output quality degradation #559

mvdarend opened this issue Aug 3, 2023 · 14 comments
Labels
question Further information is requested

Comments

@mvdarend
Copy link

mvdarend commented Aug 3, 2023

Hi there,

Hopefully someone can help with a problem I'm having with 're-streaming' an MJPEG stream, when I do this the quality of the new stream is much worse than the original. I'm probably missing a setting somewhere but my searches haven't resulted in a solution so far. One of the software packeges we're using at the moment can only process MJPEG streams, so we're stuck with that for them time being.

The source is a sub-stream from a Hikvision camera:

image

When streaming this original as an RTSP stream in VLC it looks like this:

image

When streaming through Go2Rtc it ends up looking like this:

image

Here is the relevant part of the config, ffmpeg settings have been left default:

ffmpeg:  
  
streams:
  1234:
    - rtsp://User:Pass@192.168.35.201:554/Streaming/Channels/102 

I've tried playing around with all sorts of settings to no avail, anyone have an idea of what it could be?

If I set the stream from the camera to H.264 instead of MJPEG it is much better but once I try transcoding that stream to MJPEG the quality drops again to a similar level as above.

Relevant info

  • Ubuntu version 23.04 running on a Proxmox VM
  • go2rtc_linux_amd64 - v1.6.2
  • No hardware acceleration

Edit: Spelling mistakes and better screnshot of Go2Rtc stream showing address bar.

@AlexxIT AlexxIT added the question Further information is requested label Aug 23, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented Aug 23, 2023

I have no difference in similar test for my Dahua camera.
If you share you stream - I can check it.
https://github.com/AlexxIT/go2rtc/wiki/Tunnel-RTSP-camera-to-Intenet
My contacts in github profile

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

@AlexxIT I suggest adding -input_format mjpeg parameter to ffmpeg. Because some devices will provide multiple streams, the default may not be mjpeg.

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

[root@localhost ffmpeg]# ./ffmpeg -f v4l2 -video_size 1920x1080 -i /dev/video0 -c:v mjpeg -an -f mjpeg out.mp4 
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 48535.066005, bitrate: 331776 kb/s
  Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 331776 kb/s, 10 fps, 10 tbr, 1000k tbn

↑ Before (Go2RTC default parameters without -hide_banner -v error)
↓ After

[root@localhost ffmpeg]# ./ffmpeg -f v4l2 -input_format mjpeg -video_size 1920x1080 -i /dev/video0 -c:v mjpeg -an -f mjpeg out.mp4
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 48573.005768, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1920x1080, 50 fps, 50 tbr, 1000k tbn

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 12, 2023

@TsLenMo go2rtc not using ffmpeg for transfer rtsp mjpeg to http mjpeg

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

ffmpeg:
  bin: "/opt/ffmpeg/ffmpeg.sh"
  global: "-hide_banner"
  file: "-re -stream_loop -1 -i {input}"
  http: "-fflags nobuffer -flags low_delay -i {input}"
  rtsp: "-fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"
  output: "-user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}"
  # ... different presets for codecs
log:
  format: ""
  level: "info"
streams:
  linux_usbcam:   ffmpeg:device?video=0&video_size=1920x1080#video=mjpeg

this is the config file.
After I ran Go2RTC, I saw that ffmpeg's CPU usage was quite high.
I think there is a transcoding situation.

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

Because my device provides two streams, one is YUY2 and the other is MJPEG. I observed that ffmpeg uses YUY2 by default.

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 12, 2023

I think I understand more about how go2rtc works :)
@mvdarend doesn't used ffmpeg in config. So ffmpeg is not involved.

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

OK, Sorry.

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 12, 2023

@TsLenMo your config wrong. If your USB camera supports MJPEG, of course you should use input mjpeg. Check WebUI

image

@TsLenMo
Copy link

TsLenMo commented Sep 12, 2023

Thanks.

@AlexxIT
Copy link
Owner

AlexxIT commented May 28, 2024

Please let me know if the problem is relevant

@AlexxIT AlexxIT closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
@Fohdeesha
Copy link

I have the exact same issue, with the exact same type of degradation in the image - I also have a hikvision camera, so probably something weird with their mjpeg streams over rtsp? I will open the rtsp feed from the camera so you can check it yourself as requested, I will message you the link.

@Fohdeesha
Copy link

@mvdarend - After giving @AlexxIT access to my hikvision stream, he confirmed hikvision has a weird non-standard mjpeg stream implementation, and quickly implemented a fix for handling it - now my streams look identical. The change is in the master branch, you can get a binary of it here - https://nightly.link/AlexxIT/go2rtc/workflows/build/master

@AlexxIT
Copy link
Owner

AlexxIT commented Oct 28, 2024

dagleaves pushed a commit to EscapeOracle/go2rtc that referenced this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants