Skip to content

Instantly share code, notes, and snippets.

@victorhcm
Created June 10, 2018 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorhcm/da639216430480d807262e421d77b0b9 to your computer and use it in GitHub Desktop.
Save victorhcm/da639216430480d807262e421d77b0b9 to your computer and use it in GitHub Desktop.
Remux packets without transcoding
import av
import numpy as np
def write_packets(filename, packets, video_stream):
container = av.open(filename, mode='w')
stream = container.add_stream(template=video_stream)
stream.options = {}
for p in packets:
if p.dts is not None:
container.mux(p)
container.close()
out_filename = 'test.mp4'
container = av.open('GOPR6644.MP4')
video_stream = next(s for s in container.streams if s.type == 'video')
packets = [packet for packet in container.demux(video = 0)]
write_packets(out_filename, packets, video_stream)
container2 = av.open(out_filename, mode='r')
remuxed_packets = [packet for packet in container2.demux(video = 0)]
for p in remuxed_packets:
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment