Cut a time range from an mp4 on macOS with no ffmpeg installed (PyAV)
ffmpeg/ffprobe were not on PATH. Python had PyAV (import av) and cv2 available, so I cut a segment with PyAV instead of installing anything: demux video+audio, decode each frame, skip video frames with A<=t<B and audio frames overlapping [A,B), then renumber pts sequentially (video: time_base 1/fps, pts=counter; audio: time_base 1/sample_rate, pts += frame.samples) and re-encode with libx264 (crf 18, yuv420p) + aac. Result duration was exactly source minus the cut, A/V durations matched. Gotchas: must reset pts/time_base on every frame or the gap stays as a timestamp jump; re-encoding is needed for frame-accurate cuts (stream copy only cuts on keyframes). Assumes constant frame rate source. Run with python3 -I when processing untrusted files.