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

[Feature Request]: Jellyfin 4K Transcode Killer #400

Open
brettpetch opened this issue Jan 9, 2023 · 5 comments
Open

[Feature Request]: Jellyfin 4K Transcode Killer #400

brettpetch opened this issue Jan 9, 2023 · 5 comments
Labels
enhancement New feature or application improvement integ req Third party integration request question Additional information is requested or needed upstream Requires dependency updates wontfix This will not be worked on

Comments

@brettpetch
Copy link

brettpetch commented Jan 9, 2023

With the recent potential db changes to Jellyfin, the viability of using it as a Plex replacement is becoming real.

Currently, the webhooks provided by jellyfin are not sufficient for notifying of new playback events with the amount of data required to kill a transcode. To circumvent this, I'd like to propose the following running on a 30s-1m interval--

/Sessions?ActiveWithinSeconds=30&apikey=<REDACTED>

From there, you can iterate through current sessions: this may look like

# https://api.jellyfin.org/#tag/Session/operation/GetSessions
#https://api.jellyfin.org/#tag/HlsSegment/operation/StopEncodingProcess
# Responses are in JSON

x.TranscodingInfo.IsVideoDirect = True/False
x.NowPlayingItem.Height >= <Resolution>
x.Id <SessionID>
  
  # Get Active Sessions within last 30 seconds
  /Sessions?ActiveWithinSeconds=30&apikey=<apiKey>

  # Sending Message
  POST '{"Text":"No 4K Transcoding!","TimeoutMs":5000}' /Sessions/<Id>/Message?apikey=<apiKey>

  # Stopping Transcode
  POST /Sessions/<Id>/Playing/Stop?apikey=<apiKey>
@davidnewhall davidnewhall added enhancement New feature or application improvement integ req Third party integration request labels Jan 9, 2023
@davidnewhall
Copy link
Contributor

This application currently has no jellyfin support. I'm the only one who programs this app. (Others welcome!) I've never used jellyfin, so there's a pretty slim chance this feature will make it in.

@davidnewhall
Copy link
Contributor

I've been unable to find a Jellyfin Go library. This is the closest thing I can find, and it doesn't seem to have any session management methods. https://pkg.go.dev/github.com/hrfee/jfa-go/jfapi

@zeroquinc
Copy link

@davidnewhall
Copy link
Contributor

@zeroquinc Doesn't appear that anything has changed since I left my last comment about it.

@brettpetch
Copy link
Author

Python implementation:

#!/usr/bin/env python3
# /usr/local/bin/jellyfin-check.py
import requests
import time

API_BASE_URL = "http://127.0.0.1:8096"  # Replace with your server address
API_KEY = "CHANGEME"

# Retrieve active sessions from the last 30 seconds
def get_active_sessions():
    url = f"{API_BASE_URL}/Sessions?ActiveWithinSeconds=30&apikey={API_KEY}"
    response = requests.get(url)
    if response.status_code == 200:
        return response.json()
    return []

# Send a message to a specific session
def send_message(session_id):
    url = f"{API_BASE_URL}/Sessions/{session_id}/Message?apikey={API_KEY}"
    payload = {
        "Text": "4K Transcoding is not allowed, please try a lower quality version.",
        "TimeoutMs": 5000
    }
    response = requests.post(url, json=payload)
    return response.status_code == 200

# Stop transcoding for a specific session
def stop_transcoding(session_id):
    url = f"{API_BASE_URL}/Sessions/{session_id}/Playing/Stop?apikey={API_KEY}"
    response = requests.post(url)
    return response.status_code == 200

def main():
    while True:  # Infinite loop to keep checking every 30 seconds
        sessions = get_active_sessions()

        for session in sessions:
            # Check conditions
            if (
                not session.get("TranscodingInfo", {}).get("IsVideoDirect", False) and
                session.get("NowPlayingItem", {}).get("Width", 0) >= 3840  # Assuming 4K resolution as 3840 pixels in width
            ):
                session_id = session.get("Id")

                if session_id:
                    send_message(session_id)
                    stop_transcoding(session_id)
                    print(f"Stopped transcoding for session ID: {session_id}")

        time.sleep(30)  # Wait for 30 seconds before checking again

if __name__ == "__main__":
    main()

@davidnewhall davidnewhall added question Additional information is requested or needed wontfix This will not be worked on upstream Requires dependency updates labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or application improvement integ req Third party integration request question Additional information is requested or needed upstream Requires dependency updates wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants