moviepy
moviepy copied to clipboard
Specify a frame that will be used as the video thumbnail
Is there a way to specify a frame that will be used as the video thumbnail after being exported? I am exporting two versions of the same video, one is a shorter version of the same edit, so ideally I wanted them to have a different thumbnail so the user doesn't think that it is the same file duplicated.
I have already looked at the documentation but couldn't find anything related to this subject. Any help will be much appreciated!
I would use save_frame.
image at 1 second and 1 frame at 25fps
time_in_secs = 1.04
output_path:str = "/preview_images"
tempVideo.save_frame(output_path,time_in_secs)
But I don't think thumbnails are embedded in the mp4, if that's what you mean.
That's exactly what I mean. If you export a video using a video editing software, for example, Premiere Pro. You can select what frame will be displayed as the embedded thumbnail. This is also the image the user sees while browsing through videos on a phone.
ah, you are actually correct. That is a function that FFMPEG provides for write_videofile( ). write_videofile has a property called ffmpeg_params. That should be able to take the necessary parameters. I found this solution on stackoverflow, but I haven't tried to implement it yet. Worst case you can use FFMPEG directly.
I'm able to do it directly from FFMPEG like so
ffmpeg -i path-to-video.mp4 -i path-to-thumbnail.png -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mp4
But When I use the same params in moviepy I get this error:
`OSError: [Errno 32] Broken pipe
MoviePy error: FFMPEG encountered the following error while writing file thumbnail_test.mp4:
b"Unknown decoder 'libx264'\n"` Moviepy code:
from moviepy.editor import VideoFileClip
thumbnail_clip = VideoFileClip("Assets/PG_test_video.mp4")
thumbnail_clip.write_videofile( "thumbnail_test.mp4",codec="libx264", ffmpeg_params=["-i","Dev_v0.2.3/Assets/PG_test_video.mp4","-i", "Dev_v0.2.3/sci-fy_1080.png", "-map", "0", "-map", "1", "-c", "copy","-c:v:1","png","-disposition:v:1", "attached_pic"])
Good to know that it can be done directly with FFMPEG but ideally I would like to use MoviePy. I liked your approach adding the FFMPEG to the "write_videofile" function, in fact, I didn't know it was possible. Hopefully, someone else can find a solution to that. Thanks for trying!