Skip to main content

P2PCam

Class to retrieve camera images from cameras using the p2p protocol

First of all i just wrote it to work as a class, the original connection and retrieval process has been made by Jheyman in his videosurveillance script. I rewrote it to run as a class instead of an application.

So i had this chinese camera laying around, it had this feature that you could access it from outside your home without the need for port forwarding. However after a couple of years this brand dissappeared and with it their services so i couldn't connect to it outside of my own network using this app.

Which made owning this camera quite useless. But i had since gotten into Home Asssistant and got the idea to get it working in there since my instance ran locally so it should be able to access the camera.

Usage

import p2pcam
import cv2
import numpy as np

def saveFile(cam, jpeg):
    RGBImage = cv2.imdecode(np.fromstring(jpeg, dtype=np.uint8), cv2.IMREAD_COLOR)
    cv2.imwrite('image.jpg', RGBImage)

camera = p2pcam.P2PCam(<own ip>, <camera ip>)
saveFile(camera, camera.retrieveImage())

Methods and Variables

Methods

Any methods that may be useful.

camera.initialize() Set some variables and attempt to connect to the camera for the first time.

camera.retrieveImage() Retrieve a jpeg string from the camera.

camera.start() Start a while true loop staying connected, this will not do anything if onJpegReceived isn't set.

camera.loop() Start a while loop doing retrieveImage() until a socket error occurs.

Variables

Some variables you may want to set.

camera.horizontal_flip Flip camera horizontally. (if true requires numpy and cv2)

camera.vertical_flip Flip camera vertically. (if true requires numpy and cv2)

camera.addTimeStamp Add a timestamp to the image. (if true requires numpy and cv2)

camera.debug If true prints out some debugging information.

The port information will have to be set before initialisation.

camera.UDP_PORT_HOST Host udp port default: 5123

camera.UDP_PORT_TARGET Target udp port default: 5000

camera.SOCKET_TIMEOUT Sets the socket timeout in seconds.

camera.NB_FRAGMENTS_TO_ACCUMULATE How many packets to get a full image. If you put this number high you will get a higher quality image but it will take longer to retrieve. Default: 80

camera.onJpegReceived Callback that will be executed if a jpeg image is retrieved. first argument will be the camera class, the second argument will be the jpeg image string.

Metadata

Release files for p2pcam 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for p2pcam 0.0.3
File Size Uploaded Provenance Actions
p2pcam-0.0.3.tar.gz 7.6 kB Without provenance Details for p2pcam-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for p2pcam 0.0.3
File Interpreter ABI Platform Actions
p2pcam-0.0.3-py3-none-any.whl Python 3 none any Details for p2pcam-0.0.3-py3-none-any.whl

Total release size: 16.4 kB

Release files / p2pcam-0.0.3.tar.gz

Download URL p2pcam-0.0.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
41dc6f0f7bc00dd759e5b3585fe090e31e76895e2b3a9a39463a6ddfcaecc1f7
BLAKE2b-256 checksum
How to use checksums
7f5ca868e72cfc476ef765231926e65c3663f9a9661400824ae95e543cc22d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Release files / p2pcam-0.0.3-py3-none-any.whl

Download URL p2pcam-0.0.3-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a216bef163fd2607c3d48fa96b5399328c23dd2cc05f91465b3e9f1963715ed
BLAKE2b-256 checksum
How to use checksums
e2d41b87310db96052ea71b1f4c539066d60d9db4eaa1b567c904f16e8a2f58d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Security for p2pcam 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page