Skip to content

feat: add dual straming #763

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

Merged
merged 20 commits into from
Jun 9, 2025
Merged

feat: add dual straming #763

merged 20 commits into from
Jun 9, 2025

Conversation

junhyr
Copy link
Collaborator

@junhyr junhyr commented Jun 4, 2025

PR Type

Enhancement


Description

  • Combine Livepeer and AI streams in one ffmpeg

  • Remove HLS-based AI streaming logic

  • Simplify startup by removing health checks

  • Update environment var checks and logs


Changes walkthrough 📝

Relevant files
Enhancement
entrypoint.sh
Implement dual RTMP streaming                                                       

apps/restreamers/entrypoint.sh

  • Removed HLS_SOURCE_URL and related checks
  • Replaced stream_to_livepeer and stream_to_ai functions
  • Consolidated ffmpeg to send both streams
  • Removed health_check and startup logic
  • +23/-147

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    vercel bot commented Jun 4, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    pipelines-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2025 2:59pm

    Copy link

    github-actions bot commented Jun 4, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Shell Compatibility

    The use of local and PIPESTATUS relies on Bash-specific behavior. Ensure the script has a Bash shebang (e.g., #!/usr/bin/env bash) and is run with Bash, not a POSIX shell.

    stream_dual_to_rtmp() {
        echo "=== Starting dual stream to both RTMP endpoints ==="
        local retry_count=0
        local retry_delay=$INITIAL_RETRY_DELAY
    
        while true; do
            echo "[DUAL] Streaming to both endpoints (attempt $((retry_count + 1)))"
    FFmpeg Command Flags

    The duplicated -c:v copy, -c:a copy, -bufsize, and -maxrate flags may not apply correctly to each output. Verify that each RTMP endpoint receives the intended codec and rate-control settings.

    -c:v copy \
    -c:a copy \
    -bufsize 3000k \
    -maxrate 1500k \
    -f flv "$RTMP_TARGET_LP" \
    -c:v copy \
    -c:a copy \
    -bufsize 3000k \
    -maxrate 1500k \
    -f flv "$RTMP_TARGET_AI" \
    -loglevel info \
    Loop Exit Logic

    A normal FFmpeg exit (exit code 0) resets retry counters but never breaks the infinite loop. Consider adding a condition to exit or pause on clean termination to avoid unintended restarts.

    if [ $exit_code -eq 0 ]; then
        echo "[DUAL] Stream ended normally"
        retry_count=0
        retry_delay=$INITIAL_RETRY_DELAY
    else
        echo "[DUAL] Stream failed with exit code: $exit_code"
        retry_count=$((retry_count + 1))

    Copy link

    github-actions bot commented Jun 4, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Temporarily disable exit-on-error around ffmpeg

    Disable set -e around the ffmpeg pipeline so failures don’t abort the script
    prematurely. Wrap the ffmpeg invocation with set +e/set -e so you can capture and
    handle non-zero exit codes for retries.

    apps/restreamers/entrypoint.sh [132-134]

    -2>&1 | while IFS= read -r line; do echo "[DUAL] $line"; done
    +set +e
    +ffmpeg -re \
    +    -stream_loop -1 \
    +    -i "$STREAMING_VIDEO_FILE" \
    +    ... \
    +    -f flv "$RTMP_TARGET_AI" \
    +    -loglevel info \
    +    2>&1 | while IFS= read -r line; do echo "[DUAL] $line"; done
    +local exit_code=${PIPESTATUS[0]}
    +set -e
     
    -local exit_code=${PIPESTATUS[0]}
    -
    Suggestion importance[1-10]: 8

    __

    Why: Without set +e, the pipeline would trigger set -e on ffmpeg failure and abort the script, so disabling and re-enabling exit-on-error is crucial to handle retries correctly.

    Medium
    Explicitly map input streams for both outputs

    Ensure both audio and video streams are explicitly mapped to each RTMP output to
    avoid missing streams. Add -map 0 before each output block so ffmpeg will include
    all streams from the input for both targets.

    apps/restreamers/entrypoint.sh [118-132]

     ffmpeg -re \
         -stream_loop -1 \
         -i "$STREAMING_VIDEO_FILE" \
    +    -map 0 \
         -c:v copy \
         -c:a copy \
         -bufsize 3000k \
         -maxrate 1500k \
         -f flv "$RTMP_TARGET_LP" \
    +    -map 0 \
         -c:v copy \
         -c:a copy \
         -bufsize 3000k \
         -maxrate 1500k \
         -f flv "$RTMP_TARGET_AI" \
         -loglevel info \
         2>&1 | while IFS= read -r line; do echo "[DUAL] $line"; done
    Suggestion importance[1-10]: 6

    __

    Why: Adding -map 0 ensures ffmpeg includes all audio and video streams for each RTMP output, preventing missing streams in the dual-stream setup.

    Low
    General
    Quote retry_delay in sleep call

    Quote the retry delay variable in sleep to avoid issues if it’s empty or contains
    spaces. This makes sure the shell interprets it as a single argument.

    apps/restreamers/entrypoint.sh [154]

    -sleep $retry_delay
    +sleep "$retry_delay"
    Suggestion importance[1-10]: 4

    __

    Why: Quoting "$retry_delay" prevents word splitting or empty-argument issues when invoking sleep, improving script robustness.

    Low

    @junhyr junhyr temporarily deployed to Preview - e2e June 4, 2025 04:14 — with GitHub Actions Inactive
    @junhyr junhyr temporarily deployed to Preview - e2e June 4, 2025 04:35 — with GitHub Actions Inactive
    @junhyr junhyr temporarily deployed to Preview - e2e June 4, 2025 10:18 — with GitHub Actions Inactive
    @junhyr junhyr temporarily deployed to Preview - e2e June 4, 2025 14:10 — with GitHub Actions Inactive
    @junhyr junhyr merged commit e43e5c5 into main Jun 9, 2025
    5 of 6 checks passed
    @junhyr junhyr deleted the jun/rtmp branch June 9, 2025 15:02
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant