Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: eumagga0x2a on October 18, 2016, 11:53:05 PM

Title: [Editor] Fix for pasting from clipboard to the beginning of a video etc.
Post by: eumagga0x2a on October 18, 2016, 11:53:05 PM
The issue with pasting from clipboard to the the beginning of a video mentioned in http://avidemux.org/smif/index.php/topic,17221.0.html (http://avidemux.org/smif/index.php/topic,17221.0.html) turned out to be a bug in ADM_EditorSegment::updateStartTime.

    uint64_t t=0;
    t=segments[0]._startTimeUs;
    for(int i=0;i<n;i++)
    {
        segments[i]._startTimeUs=t;
        t+=segments[i]._durationUs;
    }


in updateStartTime at ADM_segment.cpp:350 would allow a non-zero linear time at the beginning of the first segment. This led to

            // insert clipboard
            // Do we need to split it ?
            if(currentTime==s._startTimeUs)
            {
                // nope
                for(int j=0;j<clipboard.size();j++) newSegs.push_back(clipboard[j]);
            }else


at ADM_segment.cpp:909 producing a first segment with _startTimeUs equal the linear time of the start of the clipboard copy, resulting in an invalid segment layout.

The second chunk of the following patch enforces that the first segment starts at zero, thus fixing paste from clipboard.

The first chunk removes the call to clipboard.clear() from ADM_EditorSegment::undo. I failed to figure out in which circumstances clearing clipboard on undo might be necessary, didn't find any issues while testing and hope that it is safe to keep clipboard contents on undo.

The last chunk adds debug info to ADM_EditorSegment::pasteFromClipBoard which is present in all other functions related to copy and delete operations and proved immensly helpful while troubleshooting this issue.

diff --git a/avidemux/common/ADM_editor/src/ADM_segment.cpp b/avidemux/common/ADM_editor/src/ADM_segment.cpp
index 122a00d..eda4d62 100644
--- a/avidemux/common/ADM_editor/src/ADM_segment.cpp
+++ b/avidemux/common/ADM_editor/src/ADM_segment.cpp
@@ -264,7 +264,6 @@ bool ADM_EditorSegment::deleteAll (void)
bool        ADM_EditorSegment::undo(void)
{
     if(undoSegments.empty()) return false;
-    clipboard.clear();
     segments=undoSegments.back();
     undoSegments.pop_back();
     updateStartTime();
@@ -348,7 +347,6 @@ bool         ADM_EditorSegment::updateStartTime(void)
     if(!n) return true;
     
     uint64_t t=0;
-    t=segments[0]._startTimeUs;
     for(int i=0;i<n;i++)
     {
         segments[i]._startTimeUs=t;
@@ -931,6 +929,7 @@ bool        ADM_EditorSegment::pasteFromClipBoard(uint64_t currentTime)
     segments=newSegs;
     updateStartTime();
     undoSegments.push_back(tmp);
+    dump();
     return true;
}