Author Topic: Avidemux crashes on second edit  (Read 900 times)

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5593
Re: Avidemux crashes on second edit
« Reply #30 on: September 04, 2017, 05:30:21 AM »
Is this logic possible?
When copy mode
-  if no keyframe on (selected) [ A] or begin of video
-- set 1st upcoming keyframe if begin of video
-- set 1st previous keyframe if set [ A], if none,  set 1st upcoming keyframe

If no copy mode, this is no issue, my understanding.

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1462
Re: Avidemux crashes on second edit
« Reply #31 on: September 04, 2017, 09:28:19 AM »
This has nothing to do with transcoding vs. copy mode. When deleting a chunk of video, we have a function which performs cleanup: removes empty (zero-duration) segments. This function also deletes very short segments with a non-zero duration but no video frames from the start of a reference video to its first frame. This is all fine, except if this tiny segment is the first one. It got purged, but the linear start time of the following segment was not adjusted afterwards.

This way we got a video with a non-zero linear start time. In the subsequent delete action, this start time got finally adjusted to zero, but not the duration of following segments, resulting in segments boundaries being shifted to the left and thus not matching video frames they had been at anymore. This broke seeking which in turn could lead to a crash in samePicture().

The solution was to swap the order of purging empty segments and recalculating their start points: now instead of "adjust first, then purge" we purge first, then adjust.

Obviously, this results in a comparably harmless seek error in the first delete action if the marker A was at the first frame with a non-zero PTS. The error could only be avoided by seeking to zero instead of to A, never deleting the first empty segment or adjusting the start time in reference and duration of the second segment.