You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to traverse a video and after frame 10 - add 10 more frames made from current 10-nth frame onto which I draw an overlay and then resume and remux the rest of the frames.
I don't know how to compute pts for new added frames and the rest
I am using the example provided by @jlaine at #473 with great help to know how to compute pts.
importavimportcv2# open input and find video streaminput_container=av.open('input.mp4', 'r')
input_stream=input_container.streams.get(video=0)[0]
# open output and add a video streamoutput_container=av.open('output.mp4', 'w')
output_stream=output_container.add_stream('h264', rate=input_stream.rate)
frame_current=0forframeininput_container.decode(input_stream):
# perform edge detectionimg=frame.to_ndarray(format='bgr24')
img=cv2.cvtColor(cv2.Canny(img, 100, 200), cv2.COLOR_GRAY2BGR)
ifframe_current>10andframe_current<=20:
# add 10 more framesforiinrange(10):
# compute new ptspts_computed=frame_to_pts(frame_current, frame.time_base, input_stream.average_rate, input_stream.start_time)
# rebuild a VideoFrame, preserving timing informationnew_frame=av.VideoFrame.from_ndarray(img, format='bgr24')
new_frame.pts=pts_computednew_frame.time_base=frame.time_base# encode and muxforpacketinoutput_stream.encode(new_frame):
output_container.mux(packet)
# advance one frameframe_current+=1else:
# compute new ptspts_computed=frame_to_pts(frame_current, frame.time_base, input_stream.average_rate, input_stream.start_time)
# rebuild a VideoFrame, preserving timing informationold_frame=av.VideoFrame.from_ndarray(img, format='bgr24')
old_frame.pts=pts_computedold_frame.time_base=frame.time_base# encode and muxforpacketinoutput_stream.encode(old_frame):
output_container.mux(packet)
# advance one frameframe_current+=1# flush and close outputforpacketinoutput_stream.encode(None):
output_container.mux(packet)
output_container.close()
Expected behavior
The formula above seems to work for h264 codec, but I have no confidence in it -
Actual behavior
Switching to h264_nvenc instead of h264 gets me pts < dts errors.
This discussion was converted from issue #1063 on January 30, 2023 22:53.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Overview
I am using the example provided by @jlaine at #473 with great help to know how to compute
pts
.I've came with this formula hardly digging
then
Expected behavior
The formula above seems to work for h264 codec, but I have no confidence in it -
Actual behavior
Switching to
h264_nvenc
instead ofh264
gets mepts < dts
errors.Investigation
Tried other codecs
hevc_nvenc
- seems to workResearch
I have done the following:
Beta Was this translation helpful? Give feedback.
All reactions