Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle PI recordings with broken video #2077

Merged
merged 9 commits into from
Jan 11, 2021
Prev Previous commit
Handle non-video streams when fixing broken frame issue
  • Loading branch information
romanroibu committed Jan 5, 2021
commit 23826a4e70b8b2af281318e9b3cd2ee7e9902ee2
26 changes: 19 additions & 7 deletions pupil_src/shared_modules/pupil_recording/update/invisible.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,26 @@ def patch_recording_if_affected(cls, recording: PupilRecording):

# Save video, dropping first frame, to temp file
in_container = av.open(str(v_path))
in_video_stream = in_container.streams.video[0]
out_container = av.open(str(temp_v_path), "w")
out_container.add_stream(template=in_video_stream)
out_video_stream = out_container.streams.video[0]
packets = in_container.demux(video=0)
_ = next(packets) # Drop first
for packet in packets:
packet.stream = out_video_stream

# input -> output stream mapping
stream_mapping = {
in_stream: out_container.add_stream(template=in_stream)
for in_stream in in_container.streams
}

# Keep track of streams that should skip frame
stream_should_skip_frame = {
in_stream: in_stream.codec_context.type == "video"
for in_stream in stream_mapping.keys()
}

for packet in in_container.demux():
if stream_should_skip_frame[packet.stream]:
# Once the stream skipped the first frame, don't skip anymore
stream_should_skip_frame[packet.stream] = False
continue
packet.stream = stream_mapping[packet.stream]
out_container.mux(packet)
out_container.close()

Expand Down