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

[Bug]: WriteGear: -input_framerate less than 5 does not get used ? #306

Closed
3 tasks done
freol35241 opened this issue May 12, 2022 · 6 comments · Fixed by #307 or #321
Closed
3 tasks done

[Bug]: WriteGear: -input_framerate less than 5 does not get used ? #306

freol35241 opened this issue May 12, 2022 · 6 comments · Fixed by #307 or #321
Assignees
Labels
BUG 🐛 Vidgear api's error, flaw or fault SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!
Milestone

Comments

@freol35241
Copy link
Contributor

Brief Description

I am trying to to use WriteGear to output a (semi) live stream to an rtsp server (as already detailed in #228)(yes, I have an rtsp server running). The input (using Camgear) is also an rtsp live stream and I am doing quite som heavy processing in between. This means:

  • I am not using Threaded Queue Mode on the input (CamGear) since I will not be able to process all frames and its fine to drop any frames I dont manage to process
  • I manage to process frames at about 1 fps
  • I want to output the processed frames to an rtsp stream with fps 15, in effect duplicating the frames (or 25 or 30, this doesnt matter much but has to be larger than 1 since this does not work nicely with other rtsp clients such as VLC or another ffmpeg instance)

My attempt was this:

sink = WriteGear(
    output_filename="rtsp://localhost:8554/cam/processed",
    logging=True,
    **{
        "-f": "rtsp",
        "-rtsp_transport": "tcp",
        "-tune": "zerolatency",
        "-preset": "ultrafast",
        "-stimeout": "1000000",
        "-input_framerate": 1,
        "-r": 15,
    }

But WriteGear does not use the "-input_framerate": 1 and the resulting rtsp stream becomes unusable it seems.

Acknowledgment

Environment

  • VidGear version: 0.2.5
  • Branch: PyPi
  • Python version: 3.8.5
  • PiP version: 20.0.2
  • Operating System and version: WSL2 (Ubuntu 20.04) on Windows 10

Expected Behavior

WriteGear honors "-input_framerate": 1 so that the output stream behaves as expected.

Actual Behavior

WriteGear disregards "-input_framerate": 1 making the rtsp stream unusable by other rtsp clients

Possible Fix

Change https://github.com/abhiTronix/vidgear/blob/master/vidgear/gears/writegear.py#L414

if self.__inputframerate > 5:
    ...

to:

if self.__inputframerate > 0:
    ...

This seems to fix the issue as far as I can tell. What is the reason for this threshold anyway?

Steps to reproduce

(Write your steps here:)

  1. docker run --rm -it -e RTSP_PROTOCOLS=tcp -p 8554:8554 aler9/rtsp-simple-server
  2. Generate a fake 1 fps stream and output via WriteGear
import time
import numpy as np
from vidgear.gears import WriteGear


sink = WriteGear(
    output_filename="rtsp://localhost:8554/fake",
    logging=True,
    **{
        "-f": "rtsp",
        "-rtsp_transport": "tcp",
        "-tune": "zerolatency",
        "-preset": "ultrafast",
        "-stimeout": "1000000",
        "-input_framerate": 1,
        "-r": 15,
    }
)

while True:
    # Generate fake frame
    frame = np.random.randint(0, 255, size=(1080, 1920, 3))

    # Write to sink
    sink.write(frame)

    # Emulate fps 1
    time.sleep(1)
  1. Try to record this rtsp using another ffmpeg instance
ffmpeg -rtsp_transport tcp -i rtsp://localhost:8554/fake fake_output.mp4

@welcome
Copy link

welcome bot commented May 12, 2022

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

  • Read our Issue Guidelines, and update your issue accordingly. Please note that your issue will be fixed much faster if you spend about half an hour preparing it, including the exact reproduction steps and a demo.
  • Go comprehensively through our dedicated FAQ & Troubleshooting section.
  • For any quick questions and typos, please refrain from opening an issue, as you can reach us on Gitter community channel.

@abhiTronix
Copy link
Owner

@freol35241 nice catch. This piece of code ia not supposed to be there at all. This should've removed long ago as I did in Streamgear API. Could you send PR for the same to our testing branch? I'll merge it.

⚠ Make sure you push all commits against testing branch only.

@abhiTronix abhiTronix added BUG 🐛 Vidgear api's error, flaw or fault BUG CONFIRMED ✅ Bug is confirmed! WORK IN PROGRESS 🚧 currently been worked on. PR WELCOMED 📬 Related Pull Requests are welcomed for this issue! labels May 12, 2022
@abhiTronix abhiTronix added this to the 0.2.6 milestone May 12, 2022
@abhiTronix abhiTronix added this to To do in VidGear v0.2.6 via automation May 12, 2022
@freol35241
Copy link
Contributor Author

The threshold seems to be identical in the StreamGear API?
https://github.com/abhiTronix/vidgear/blob/master/vidgear/gears/streamgear.py#L484-L490

@freol35241 freol35241 mentioned this issue May 12, 2022
6 tasks
@abhiTronix abhiTronix linked a pull request May 12, 2022 that will close this issue
6 tasks
@abhiTronix
Copy link
Owner

The threshold seems to be identical in the StreamGear API?
https://github.com/abhiTronix/vidgear/blob/master/vidgear/gears/streamgear.py#L484-L490

@freol35241 wow, I thought I removed it. Could you change that too?, would be really helpful.

@abhiTronix abhiTronix removed the PR WELCOMED 📬 Related Pull Requests are welcomed for this issue! label May 12, 2022
@abhiTronix abhiTronix moved this from To do to In progress in VidGear v0.2.6 May 12, 2022
@abhiTronix abhiTronix removed the BUG CONFIRMED ✅ Bug is confirmed! label May 12, 2022
@abhiTronix
Copy link
Owner

abhiTronix commented May 13, 2022

@freol35241 Thank you again. But you've changed pytest.xfail in wrong line(i.e. line-229). Kindly revert commit 1378332 change and make the same change at correct line(i.e. line-232).

pytest.fail("Test failed to play any URL!")

abhiTronix added a commit that referenced this issue May 16, 2022
… [PR by @freol35241]

- 🔧 Removed 5 second threshold in WriteGear and StreamGear APIs.
- 👷 Xfailed RSTP CamGear CI test.
@abhiTronix
Copy link
Owner

@freol35241 Thank you and apologies for the delay. I've merged the fix successfully and will prepare the next release soon. Stay tuned.

VidGear v0.2.6 automation moved this from In progress to Done May 16, 2022
@abhiTronix abhiTronix added SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! and removed WORK IN PROGRESS 🚧 currently been worked on. labels May 16, 2022
@abhiTronix abhiTronix linked a pull request Jul 5, 2022 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG 🐛 Vidgear api's error, flaw or fault SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants