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

WIP: Adds mediainfo sniffing and auto-thumbnailing with ffmpeg. #23

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tomatohater
Copy link

@tomatohater tomatohater commented Dec 29, 2017

Don't merge this. Tests are not written yet and error handling needs to be improved, but I'd like to get some eyes on this before going much further. Thoughts?


Per issue #5 , this merge adds support for metadata extraction (duration, height, width) and thumbnailing if ffmpeg is installed and a path specified in settings.

A few notes:

  • Currently, only works with local file storage (but that was already the case since os.path is used). We can improve the whole thing to be storage independent in the future.
  • I had some ideas about making the sniffer/thumbnailer backends swappable. Like maybe use lighter alternative to ffmpeg for audio file.
  • I might actually decouple metadata sniffing from thumbnailing... making them completely independent from eachother.
  • The sniffed mediainfo is stored in the model, but not exposed in the UI. It's json data stored in a TextField for max compatibility. It would be nicer if is was a JSONField.
  • I might make the new Django settings more robust.
  • I'd like to do some testing with LARGE media files to see performance implications. It may make sense to do this work asynchronously, but that may complicate things.

Copy link
Collaborator

@nimasmi nimasmi left a comment

Choose a reason for hiding this comment

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

Thanks, @tomatohater, this initially looks good.

I haven't gone so far as testing it, though I think that some exception handling should be introduced (in media_sniff() perhaps?) in case the return from ffmpeg isn't as expected.


# Try to scrape a thumbnail from video
if hasattr(settings, 'WAGTAILMEDIA_FFMPEG_CMD')\
and not instance.thumbnail:
Copy link
Collaborator

Choose a reason for hiding this comment

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

NB this leaves no way to leave a thumbnail blank. I'm happy with this, but just pointing it out for discussion if anyone has an opinion.

Copy link
Author

Choose a reason for hiding this comment

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

I agree with you here. I think I'll add a "No thumbnail" checkbox to the Media admin UI.

data = sniff_media_data(instance.file.path)
if data:
duration = int(float(data['format']['duration']))
Media.objects.filter(pk=instance.pk).update(duration=duration, mediainfo=data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with your comment that just dumping this data dictionary into a text field feels wasteful.

Copy link
Author

Choose a reason for hiding this comment

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

I felt compelled to store the results of the media info extraction alongside the Media object. Maybe it should be called "raw_mediainfo" or something. I'm not sure how wasteful it is. Probably less wasteful than re-extracting via ffmpeg each time.

I don't love that it's a Textfield.... I'd prefer a JSONField but wanted to maximize compatibility.

@tomatohater
Copy link
Author

Thanks for your comments, @nimasmi. I wanted to get feedback on the direction before going too far. I'll add the tests and exception handling to this PR (as well as the other tweaks already mentioned).

@thibaudcolas thibaudcolas changed the title Adds mediainfo sniffing and auto-thumbnailing with ffmpeg. WIP: Adds mediainfo sniffing and auto-thumbnailing with ffmpeg. May 22, 2020
@thibaudcolas thibaudcolas marked this pull request as draft May 22, 2020 06:22
@thibaudcolas
Copy link
Member

thibaudcolas commented May 22, 2020

Marking this PR as draft since it’s missing a lot to be considered for merging.

I see @thenewguy closed #5 on the basis that this was outside of the scope of this project (#5 (comment)) – won’t close this PR for now but we should discuss this before anyone spends more time on this.

Base automatically changed from master to main March 3, 2021 17:33
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.

3 participants