How to create thumbnail from videos using Python - python

My video formats are jpeg,yuy2 etc.Need to convert into thumbnails. Is there a default size for thumbnail.

You can use ffmpeg to work with videos (converting, thumbnail creation, ...). There is a good package to work with ffpmeg in python named python-video-converter. You can have control over each parameter using ffmpeg. Also using great Pillow package on python, you can manipulate images easily.

Related

How to show PIL Images as a movie?

I get continuously PIL Images, using while True loop, and want to show them as a movie.
I can show an image by img.show(), but this code inside the loop makes multiple windows.
Would you tell me the way to display them as a movie?
I think the easiest way is to use ImageMagick in the command line to great a .gif file with the following command, assuming your image files are named something like image-1.png, image-2.png:
sudo apt-get install imagemagick
convert -delay 20 -loop 0 image-*.png my_movie.gif
This will create a my_movie.gif in the same directory where your images are located.
Another way to create a movie from frames is to use Blender, an open source program based on Python. I don't think Pillow supports creating gifs or movie files directly; every solution I have seen involves some other library, so I think the best way is to go with a simple command line tool.

pygame: full image support images

I want to use .png images in pygame but it requires full image support. How do I do this?
Also, what are some image formats that I can use in pygame that doesn't need full image support?
The Pygame documentation for images explicitly says
The image module is a required dependency of Pygame, but it only optionally supports any extended file formats. By default it can only load uncompressed BMP images.
So, I suppose you should run
pygame.image.get_extended() # returns a bool
to check if you can load images of other extensions. If not, I suppose you will need Python imaging libraries to be installed to get extended file formats to be supported by Pygame.
OR, you could always convert the images to BMP to avoid the hassle.

Convert from qcow2 to raw with Python

How can I use Python to convert a qcow2 image file into a raw image file?
I know of qemu-img, but I'm curious about any Python libraries that might allow me to avoid asking my users to install that tool. It's not packaged with a default Fedora install, and that's what I'm developing for. If there are no other options however, I'll use qemu-img.
It seems that qemu-img is a necessity for converting qcow2 image files to raw images. I did not find a solution that avoided calling on this tool. This isn't a big issue though, because qemu-img is widely available in distros' repositories, and is sometimes packaged with distros. In order to make use of this tool in Python, simply ensure that it's installed to the system and then call it programmatically via the subprocess module, like so:
import subprocess
# Assuming file_path is the path to a local qcow2 file
if file_path.endswith('.qcow2'):
raw_file_path = file_path[:5] + '.raw'
subprocess.call(['qemu-img', 'convert', file_path, raw_file_path])

Combine images as frames to make a video with Python

I'm looking for a Python library that can combine images into a video.
A library that just allows you to create an empty video and feed images into it as frames is ideal.
Preferably with support for MPEG compression of the video file as well.
If you run linux then you can use ffmpeg to do this from the command line there is a python wrapper called pyFFmpeg that you can use - there is also pymedia but it doesn't look to be maintained.
BTW there are a number of projects that provide builds of ffmpeg for windows.
gstreamer is the tool you are looking for. you'll probably need an appsrc or something like that.

Convert mp4 to .wav or mp3 with python

Does anybody have experience with converting mp4 files to .wav or mp3 files? I am able to do this in Linux (bash), but I try to do everything in Python that I do in other languages, call me an enthusiast. I have been looking over the Pymedia library, but have not made progress as of yet.
You can use Python bindings for GStreamer, and create a pipeline to do the conversion:
More info here:
http://pygstdocs.berlios.de/pygst-tutorial/pipeline.html
Example of pipeline in another SO question:
converting wav to mp3 (and vice versa) using GStreamer
You might find the python audio tools of some use. They are designed to work from command line, but being python code you can simply import the modules and integrate it in another program. This is the API documentation. From the "About" page:
Python Audio Tools are a collection of audio handling programs which work from the command line. These include programs for CD extraction, track conversion from one audio format to another, track renaming and retagging, track identification, CD burning from tracks, and more. Supports internationalized track filenames and metadata using Unicode. Works with high-definition, multi-channel audio as well as CD-quality. Track conversion uses multiple CPUs or CPU cores if available to greatly speed the transcoding process. Track metadata can be retrieved from FreeDB, MusicBrainz or compatible servers.

Categories