Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

How to put elementary video stream into container?

Roman Arzumanyan edited this page Dec 7, 2021 · 2 revisions

Nvenc produces elementary video stream which can be either opened with players like VLC or it can be put into containers like *.avi, *.mkv and such.

Process of putting elementary video stream into container is called muxing.
VPF doesn't support muxing but it can be done with other Python libraries, e. g. with PyAV.

Thanks to @wykvictor for the snippet below:

# 1. init
dstFile = av.open(dstFilePath, 'w')
out_stream = dstFile.add_stream('h264', rate = 25)
out_stream.width = w
out_stream.height = h

# 2. mux
encByteArray = bytearray(encFrame)  # encFrame from EncodeSingleSurface
pkt = av.packet.Packet(encByteArray)
pkt.pts = pts_time
pkt.dts = pts_time
pkt.stream = out_stream  # attach pkt to the stream
dstFile.mux(pkt)
Clone this wiki locally