I'm looking for a Python video processing library, similar to PIL, where I can iterate through all the frames of a source video, access the pixel data for each frame, draw onto each frame and save the result as a new video file.
I've found a couple of similar questions, but they are pretty old now:
They recommend PyMedia and PyFFMPEG. PyMedia seems rather out of date (but may still work?) and PyFFMPEG, while more recent, has almost no documentation.
I've had no luck installing either these on Ubuntu 10.10, before I press on, is there:
a) A better library I should look at?
b) Good instructions on how to get either of these up and running?
Tkinter is one of Python's standard and easy-to-use Graphical User Interface (GUI) libraries that normally comes bundled with Python. There are many others with additional capabilities, platform support, and additional modern widgets.
Python is a language that can be use for everything, generating multimedia content like a video is a good and fun way to get started in Python.
PyBrain: The name “PyBrain” stands for Python Based Reinforcement Learning, Artificial Intelligence, and Neural Networks library. It is an open-source library built for beginners in the field of Machine Learning. It provides fast and easy-to-use algorithms for machine learning tasks.
I recommend scikit-video for you which is the most straightforward python video processing library I have ever met.
This is the official introduction to scikit-video from its project website:
Scikit-video is designed for easy video processing using Python. It is modeled in the spirit of other successful scikits such as scikit-learn and scikit-image. The developers of scikit-video know libraries exist for manipulating videos, such as PyFFmpeg, MoviePy, PyAV, imageIO, and opencv. However, no libraries have been found to provide an all-in-one solution for research-level video processing tools.
You can use my VidGear video-processing python library's WriteGear API that allows us to exploit almost all available parameters supported by FFmpeg (framerate, bitrate, codecs, format, and size,mux, demux etc.) in Compression Mode, effortlessly and flexibly and while doing that it robustly handles errors/warnings all along very quietly.
For example, To use H.264 for producing a high-quality video using the encoder x264, we can tweak its parameters as following to produce lossless output video:
output_params = {"-vcodec":"libx264", "-crf": 0, "-preset": "fast", "tune": "zerolatency"}
and then pass this dictionary to WriteGear as the example given below
# import libraries
from vidgear.gears import WriteGear
import cv2
output_params = {"-vcodec":"libx264", "-crf": 0, "-preset": "fast"} #define (Codec,CRF,preset) FFmpeg tweak parameters for writer
stream = cv2.VideoCapture(0) #Open live webcam video stream on first index(i.e. 0) device
writer = WriteGear(output_filename = 'Output.mp4', compression_mode = True, logging = True, **output_params) #Define writer with output filename 'Output.mp4'
# infinite loop
while True:
(grabbed, frame) = stream.read()
# read frames
# check if frame empty
if not grabbed:
#if True break the infinite loop
break
# {do something with frame here}
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# write a modified frame to writer
writer.write(gray)
# Show output window
cv2.imshow("Output Frame", frame)
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
cv2.destroyAllWindows()
# close output window
stream.release()
# safely close video stream
writer.close()
# safely close writer
Checkout more advance usage details here and complete docs here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With