Skip to content

Fix/improve thumbnail extraction#8

Open
f0rkb0mbZ wants to merge 3 commits into
mainfrom
fix/improve-thumbnail-extraction
Open

Fix/improve thumbnail extraction#8
f0rkb0mbZ wants to merge 3 commits into
mainfrom
fix/improve-thumbnail-extraction

Conversation

@f0rkb0mbZ
Copy link
Copy Markdown
Owner

No description provided.

@top-dog-reviews
Copy link
Copy Markdown

PR Review Summary

This PR improves the thumbnail extraction process by avoiding potential black frames at the start of videos and introduces environment variable support for Celery configuration.

Severity Distribution:

  • 🚧 medium: 1 issue (Potential crash on short videos)
  • good_to_have: 1 issue (Configuration consistency)

Please see the line-by-line feedback for detailed recommendations.

Copy link
Copy Markdown

@top-dog-reviews top-dog-reviews Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the changes. The PR correctly addresses the thumbnail extraction issue and improves configuration via environment variables. However, there are potential crash scenarios for short videos and some remaining hardcoded paths that should be addressed for consistency.

Comment thread api.py
@@ -61,8 +61,8 @@ async def upload_handler(request: Request, file: UploadFile = File(...)):
media_length = mediainfo.get("format").get("duration")
thumbnail_path = os.path.join(STATIC_DIR, f"{os.path.splitext(file.filename)[0]}_thumbnail.jpg")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good_to_have: You've added STATIC_DIR and UPLOAD_DIR to .env.example, but they are still hardcoded at the top of api.py. For consistency with your changes in celery_worker.py, these should be loaded from environment variables.

# At the top of api.py:
UPLOAD_DIR = os.getenv("UPLOAD_DIR", "uploads")
STATIC_DIR = os.getenv("STATIC_DIR", "static")

Comment thread api.py
ffmpeg.input(file_path, ss=random.randint(0, int(float(media_length)))).filter('scale', 1280, -1).output(
# Extract thumbnail from a random timestamp (at least 1 second in to avoid black frames)
ffmpeg.input(file_path, ss=random.randint(1, int(float(media_length)))).filter('scale', 1280, -1).output(
thumbnail_path, vframes=1).overwrite_output().run()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚧 medium: The use of random.randint(1, int(float(media_length))) will raise a ValueError if the video duration is less than 1 second (e.g., a short GIF or clip), as randint(a, b) requires a <= b.

            # Extract thumbnail from a random timestamp (at least 1 second in to avoid black frames, fallback to 0 if short)
            ss_timestamp = random.randint(1, int(float(media_length))) if float(media_length) >= 1 else 0
            ffmpeg.input(file_path, ss=ss_timestamp).filter('scale', 1280, -1).output(
                thumbnail_path, vframes=1).overwrite_output().run()

Copy link
Copy Markdown

@top-dog-reviews top-dog-reviews Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the new changes. A major bug has been introduced where the source video file is deleted before the Celery workers can process it. This will cause all transcoding tasks to fail. I have also kept the previous findings in mind regarding thumbnail extraction and configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant