Created
June 10, 2018 23:27
-
-
Save victorhcm/da639216430480d807262e421d77b0b9 to your computer and use it in GitHub Desktop.
Remux packets without transcoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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