-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Videos: Improve preview image generation depending on duration #1241
Comments
Related discussion: #1235 |
@electricisfun has funded $5.00 to this issue.
|
Get video full length: Get video black bars and remove them. Useful if someone has.. black bars encoded into the video. (python running a bash script 10 times and averaging it, so in Go you'd just do the same thing): croplist = []
for x in range(10):
times = str(random.randint(3,59))
cropcheckcmd = "ffmpeg -ss 00:" + times + ":00 -i \"" + filename + "\" -t 1 -vf cropdetect=17:4:3000 -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1"
cropcheck = subprocess.run([cropcheckcmd], stdout=subprocess.PIPE, shell=True).stdout.decode('utf-8').rstrip()
print (cropcheck)
croplist.append(cropcheck)
print (croplist)
cropmode = mode(croplist) This "croplist" should work directly into ffmpeg as Last all that is needed is to pick a random time from 0 to the end of the original "duration" of the video. Looks like what @graciousgrey guy linked they were already looking at a thumbnailer program though. That is a good project it's used in almost all of the linux file managers. I know he said he was trying to not use C++ stuff though so my above implementations you can cut out black bars + get full duration + pick a random timestamp to make a thumbnail out of while only calling FFMPEG. you can replace AWK with something in Go to parse the output instead. |
Actually ignore that crap above you can extract ACTION frames (frames that have pixel movement, thus not black!) purely in ffmpeg
This is all you need for every video: the magic is here:
or something like that, this is what I'd personally do. However that is the only command you need. You can copy paste the above command and replace your thumbnail right now and it'll already work better! |
@G2G2G2G Any idea what the performance impact might be, if any? |
@lastzero how fast is it now? I tested on a "hollywood movie" the 0.1 and 0.2 are almost instant From my test I think yours (for me) would be around "902.35 millis" and vs the 0.2 which is "1.02 secs" I think that's well worth it.
For me, personally, 0.8 is worth it taking 4 seconds to process the frame it finds is only like 20 seconds into the video.. So if you have like a long video and it never finds one with a lot of pixels changing then it's gonna take a LONG time since it'd go through the whole video and fail.. and then try a lower number. |
Technically there's no guarantee that even a 0.1 threshold would work if your video is extremely dark / black almost the entire thing. Somewhere I have videos of us exploring a cave that are terrible videos, if I can find them I'll test it but I guess we need a fallback to just grab the first frame as you do now, in the very worst case? |
Bottom line is that a fallback must be implemented and tested, so it's a bit more complicated than just replacing the current ffmpeg command? |
Since someone can upload a video that is just all 1 color and never changes, yes. If we guaranteed people would upload actual videos then we can guarantee 0.1 would get a thumbnail. But we can't guarantee what people upload. |
What needs to be done to add this? @lastzero I feel bad for @StianOby and @axllent #648 lol I can write this in like 15 minutes. Where is a video thumb created which function? https://github.com/photoprism/photoprism/tree/develop/internal/thumb I cannot find it I've tested scene,0.8 on thousands of random videos on imgur.com and none failed. My fear is a lightning video like: https://www.youtube.com/watch?v=Q8j5T3Qn5G0 will only work on 0.6: However terrible videos (like the one I uploaded that is entirely white the entire duration) won't find any movement.. obviously test.mp4Videos like this also don't really trigger any thumbnails due to how slow they move |
Hello, my 2c as I just stumbled accross the black thumbnail (black screen in 1st second) problem: Customization of the thumbnail generation is hardly worth the effort. Either the thumbnail is custom, where the user can select a specific frame of the video in the GUI or upload a specific picture, Did it with a 2x2 layout to have big enough pictures even on a mobile. I'm happy with the result though. Unless you happen to have a lot of collage pictures in your library, this change makes videos also more distinguishable from pictures aside from the little arrow icon. |
We need the full, first frame so it can be used as still image for Live Photos. Otherwise, the UI would have to load the entire video just to display the first frame. Note that Live Photos will only play when you hover over them with the mouse, for example in search results. |
Excuse my way to write the same content in a new reply again, but I as orignally answered via E-Mail github does not allow to use markdown in reply. I see, is this still limited to videos up to 3 seconds or intended to be used for all kind of videos in the Future?
-edit- Desktop.2022.02.05.-.18.45.52.04.mp4 |
The type is determined automatically based on the duration (and possibly other properties like the codec, see public source code), but it is possible to change it manually. So to avoid unnecessary complexity, it would be best to always have the same behavior - at least until we can pay an armada of developers to implement bells and whistles. |
This way, still images of live photos remain unchanged, while other videos might get better preview images, especially if the first few frames are only black or white. Signed-off-by: Michael Mayer <michael@photoprism.app>
With this commit, still images from live photos remain unchanged, while other videos may get better thumbnails, especially if the first few frames are just black or white. It's still not perfect, but hopefully an improvement. |
Signed-off-by: Michael Mayer <michael@photoprism.app>
Commit 78151a7 is a great improvement overall, but for videos with longer intros this can be problematic. Could you make this value configurable within the convert command? |
Generally yes, but I don't have time to add a config for it. What delay would be good instead of the 9 seconds? Note that this is dynamic and depends on the length of the video. |
I think going for something like 30 seconds to a few minutes would be a good idea |
Signed-off-by: Michael Mayer <michael@photoprism.app>
How about this? |
Thanks, looks good, will test when it is in the preview branch 👍 |
Signed-off-by: Michael Mayer <michael@photoprism.app>
Video thumbnails are currently created from the first frame hardcoded with the code
-ss 00:00:00.001 -vframes 1.
Any video that has a black first frame or anything not meaningful is not useful for previews.Suggest defaulting to the first frame or having a parameter to customize how many seconds into the video a preview is created.
IssueHunt Summary
Backers (Total: $5.00)
Become a backer now!
Or submit a pull request to get the deposits!
Tips
The text was updated successfully, but these errors were encountered: