![]() |
|
Where to hook in to automate video thumbnail generation - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: Where to hook in to automate video thumbnail generation (/thread-12927.html) |
Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-24 I am using ffmpeg to generate thumbnails for the videos. Currently, I have a shell script which checks all the video files in a given directory, and creates a similarly named jpg image for the thumbnail. And, of course, I run this manually to get the job done. I'd like to automate the task to be done at the same time normal image thumbnails are generated, but I can't figure out where that is done in the code. I'm a C/C++ guy, so I have the general chops, but lack the familiarity with PHP/JS/etc. Thanks for any help. Where to hook in to automate video thumbnail generation - acrylian - 2017-06-24
Actually Zenphoto will create those images when needed itself if needed. Some info about caching: Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-28 After fiduddling with things for a bit, I've settled on a solution with some changes to class-video.php. Using the existing feature where putting an image (myvideo.jpg) with the same name as the video (myvideo.mp4) in the appropriate album 'does the right thing', I've modified getThumbImageFile to check for the image file, and run ffmpeg if it does not exist. I'm currently extracting a frame at an offset 3 seconds, and this seems to work perfectly. The website that I am doing this for will never (famous last words) have short videos on it, so the hardcoded time won't be an issue. Assuming I can resize the image in the same operation as grabbing the frame, I will probably do that too. Two questions, 1) Does this seem correct, in the spirit of how ZenPhoto works, and 2) should I put more time into this to make it a publicly usable feature? With configuration to enable it, and configuration options that might apply, such as the mentioned frame grab offset. Where to hook in to automate video thumbnail generation - acrylian - 2017-06-29 We appreaciate your efforts. General rules though: If some core plugin does not fit your needs, best create your own custom version with another name and set it up for working from Actually I would not recommend to hook into class-video as that will not be future save. Instead I suggest you create a plugin that hooks into the Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-29 Thanks for the help! And I totally understand, so I will rework within the best practices guidelines. I actually had started down the path of using a hook, but I can't recall why I moved away from it. Probably just me being lazy and wanting to get things working. I have updated the sidecar image generation, to both grab a keyframe and resize it, so it feels like a complete feature proof of concept now. I'm heading out of town for an interview, but will post when I have a working version of my plugin. Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-29 Two questions, 1) Can I leverage another part of ZenPhoto to know this image is a video file? ie. I don't want to re-do work that is already available. And 2) while class-video.php is a core plugin, doesn't this task seem very appropriate for that plugin? And can't I submit a pull request for changes I make to it? Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-29 An implementation question, the path I chose verifies the sidecar image exists whenever the thumbnail is being displayed, which is the same way the thumbnail cache is maintained. I'm concerned that there is an edge case that won't work by hooking new_image. ie. if the sidecar image gets deleted, then it won't get regenerated unless the video is removed and re-added, yes? I could see the use case where someone has used my plugin, has sidecar images created from it, and they decide they want to change the config of my plugin, ie. the frame grab time, or the resize param. To have this work, you would want to get rid of the previous sidecar images, and have new ones created. Or, maybe the user deletes some sidecar images by hand. I assume this is similar to why the thumbnails are not generated using new_image either, but instead do so at the time the thumbnail is being displayed. Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-29 Just thinking out-loud here, what about a new thumbnail_requested event? And have all code relating to thumbnail generation hook this? Where to hook in to automate video thumbnail generation - acrylian - 2017-06-29 First to above two questions:
Also behind the scenes we are aworking on an major version (no not in public in case you wanted to ask, sorry) and that restructures a few things internally and that involves the video-class, too. So in 1.4.x we will not make such probably significant changes anymore unless it would be a bug (which this is sureyl not). To the other question: Cached images will be re-created on size changes etc. as long as the image to create from still exists. Can't your plugin just delete the existing sidecar image if it is decided to use something else? If it also clears the cache on that occasion it should be regenerated as normal. Where to hook in to automate video thumbnail generation - cpr2323 - 2017-06-29 Thanks for the quick reply. And again, I understand regarding me submitting code, and the new version. Regarding my concern about edge cases, yes, I could have my plugin delete all of the sidecar images if a parameter is changed, but this feels very brute force. As well, that doesn't handle the other edge case of the sidecar file being deleted behind the scenes. Which I suppose I could handle by putting an option in the plugin to iterate over the entire gallery and create any missing sidecar images. But, doing it at thumbnail request time is the perfect solution, just as it is for maintaining the thumbnail cache. Based on this discussion, I am going to keep my hacked version of class-video, since this is working exactly as I want it. And if the new version of ZP offers a more elegant solution, then I will proceed with a proper plugin. Also, if you are interested, here is my background: http://www.musetrap.com/cpr/resume Where to hook in to automate video thumbnail generation - acrylian - 2017-06-29 Regarding the edge case deleting on the file system. Generally zp then just assumes it is gone. Actually you should be able to test if there is a sidecar image using the Okay, best keep your modified version or even provide it as a plugin for others to use for the time being. The filters will remain even if some other internal stuff changes. Thanks for your background ;-) Please be assured we welcome any kind of contribution and plugins for specific tasks are as well. |