{"library":"ntgcalls","title":"ntgcalls - Native Telegram Calls Streaming","description":"ntgcalls is a Python library that provides a native implementation for handling real-time audio and video streams within Telegram calls. It acts as the low-level backend for `pytgcalls`, enabling seamless streaming of media directly into Telegram voice chats. The library currently supports Python 3.10+ and releases new versions to maintain compatibility with `pytgcalls` and `pyrogram`, typically following their release cycles, with the current version being 2.1.0.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install ntgcalls"],"cli":null},"imports":["from ntgcalls import VideoStream","from ntgcalls import AudioStream","from ntgcalls.types import VideoFrame","from ntgcalls.types import AudioFrame"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import asyncio\nfrom ntgcalls import VideoStream\nimport os\n\nasync def main():\n    # To run this quickstart, you MUST have ffmpeg installed and available in your system's PATH.\n    # You also need a video file for input. Replace 'your_video.mp4' with an actual path.\n    # For quick testing, you can set an environment variable: export VIDEO_PATH=\"/path/to/your_video.mp4\"\n    video_input_path = os.environ.get('VIDEO_PATH', 'test_video.mp4') # Use an actual video file path\n\n    if not os.path.exists(video_input_path):\n        print(f\"Warning: Video file '{video_input_path}' not found.\")\n        print(\"Please ensure you have a video file for input and ffmpeg is installed.\")\n        print(\"You can set the VIDEO_PATH environment variable to point to your video file.\")\n        print(\"Example: `export VIDEO_PATH=~/Videos/my_test.mp4` then run the script.\")\n        return\n\n    print(f\"Attempting to process video stream from: {video_input_path}\")\n    try:\n        # Create a VideoStream instance from a file path\n        # ntgcalls uses ffmpeg internally to process this file\n        video_stream = VideoStream(video_input_path)\n\n        # Start the video stream. This initializes the underlying ffmpeg process.\n        await video_stream.start()\n        print(\"Video stream started. Reading a few frames...\")\n\n        frame_count = 0\n        # Iterate over the stream to get video frames\n        async for frame in video_stream:\n            if frame:\n                print(f\"Got video frame {frame_count}: {frame.data_length} bytes, {frame.width}x{frame.height}\")\n                frame_count += 1\n                if frame_count >= 3: # Read a few frames then stop for demonstration\n                    print(\"Read 3 frames, stopping for quickstart demonstration.\")\n                    break\n            else:\n                # This might happen if stream ends or no frames are ready yet\n                print(\"No video frame available yet or stream ended.\")\n                break\n\n        if frame_count == 0:\n            print(\"No frames were successfully read. Check ffmpeg installation and video input path.\")\n\n        # Stop the video stream and release resources\n        await video_stream.stop()\n        print(\"Video stream stopped.\")\n\n    except FileNotFoundError as e:\n        print(f\"Error: {e}. This often means ffmpeg is not found or the video file is incorrect.\")\n        print(\"Please ensure ffmpeg is installed and accessible in your system's PATH.\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n        print(\"Ensure your video file is valid and ffmpeg can process it.\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to initialize an `ntgcalls.VideoStream` from a local video file and read a few frames. Note that `ntgcalls` relies on `ffmpeg` being installed on your system and an actual video file as input to function correctly. This example will not play audio/video; it merely processes frames from the stream.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}