Created by: markreidvfx
The following pull request adds new Encoder
and Decoder
classes. This allows one to setup a encoder/decoder without a AVFormatContext. Currently its a little verbose to setup, but that can be made easier in future patches.
here is a quick example that generates mpeg4 packets:
import av
# setup encoder
encoder = av.Encoder("mpeg4")
encoder.width = 640
encoder.height = 480
encoder.time_base = "25/1"
encoder.pix_fmt = "yuv420p"
# create a blank frame
frame = av.VideoFrame(640, 480, 'yuv420p')
# encode 10 frame
for x in range(10):
for packet in encoder.encode(frame):
print packet
# flush encoder
for packet in encoder.flush():
print packet
The new classes are also handy for reading and writing image formats. We use could them to add read and write methods on the VideoFrame
object that supports all the formats that libavcodec supports. There are some added tests that show how to do this.
The last patch in the series integrates the new class in the Stream object instead of directly calling libavcodec. As a first step, I tried to do it in a way did that doesn't break anything. There is currently a lot of shared functionality currently between the Stream
object and the CodecContext
object. I like to clean that up a bit more, but again this is just the first step.