Skip to content

Docker: Filter and stop FFmpeg which started in container only #2818

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 1 commit into from
May 5, 2025

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented May 5, 2025

User description

Thanks for contributing to the Docker-Selenium project!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines, applied for this repository.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Fixes #2775

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix


Description

  • Restricts FFmpeg process management to container-started instances

  • Prevents interference with external FFmpeg processes

  • Updates process filtering logic in video recording scripts


Changes walkthrough 📝

Relevant files
Bug fix
video.sh
Restrict FFmpeg process handling to container-initiated processes

Video/video.sh

  • Changes FFmpeg process detection to match only those started with
    '-hide_banner'
  • Updates all relevant process management commands (pgrep, kill, wait)
    to use the new filter
  • Prevents accidental termination or waiting on unrelated FFmpeg
    processes
  • +3/-3     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
    Copy link

    qodo-merge-pro bot commented May 5, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    2775 - Fully compliant

    Compliant requirements:

    • Fix the issue where the video.sh script is trying to wait for FFmpeg processes that are not children of the shell
    • Modify the stop_ffmpeg function to ensure it only finds and manages FFmpeg processes started by the container itself
    • Prevent interference with external FFmpeg processes (like those used to check video integrity)

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link

    qodo-merge-pro bot commented May 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Wait for all terminated processes

    The current implementation may cause issues if multiple FFmpeg processes are
    running. When multiple PIDs are returned, the wait command will only wait for
    the last PID in the list. Use a loop to properly wait for all terminated
    processes.

    Video/video.sh [145-149]

    -FFMPEG_PID=$(pgrep -f "ffmpeg -hide_banner" | tr '\n' ' ')
    -if [ -n "$FFMPEG_PID" ]; then
    -  kill -SIGTERM $FFMPEG_PID
    -  wait $FFMPEG_PID
    +FFMPEG_PIDS=$(pgrep -f "ffmpeg -hide_banner" | tr '\n' ' ')
    +if [ -n "$FFMPEG_PIDS" ]; then
    +  kill -SIGTERM $FFMPEG_PIDS
    +  for pid in $FFMPEG_PIDS; do
    +    wait $pid 2>/dev/null || true
    +  done
     fi
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that wait $FFMPEG_PID might behave unexpectedly if $FFMPEG_PID contains multiple PIDs. The proposed loop ensures each process ID is waited upon individually, improving the robustness of the shutdown logic when multiple FFmpeg instances might be running.

    Medium
    • More

    @VietND96 VietND96 merged commit 78d8e42 into trunk May 5, 2025
    27 checks passed
    @VietND96 VietND96 deleted the shutdown-recorder branch May 5, 2025 11:48
    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.

    [🐛 Bug]: /opt/bin/video.sh: line 135: wait: pid 48494 is not a child of this shell
    1 participant