VideoHelp Forum
+ Reply to Thread
Results 1 to 14 of 14
Thread
  1. I have lots (1000+) of videos (with audio) placed on a timeline without edits (new project) in Vegas pro and need to cut (trim from start) all but last 30 seconds of each video event without moving (joining) them or re-rendering. Any simple way to do it?
    Quote Quote  
  2. Member budwzr's Avatar
    Join Date
    Apr 2007
    Location
    City Of Angels
    Search Comp PM
    No, you cannot do that without rerender.
    Quote Quote  
  3. Ok, any suggestions with re-rendering?
    Quote Quote  
  4. You're probably going to need to learn scripting in Vegas Pro, which falls outside of your requirement that this is simple.
    Quote Quote  
  5. Vegas scripting indeed looks rather complicated, Avisynth turns out to be simple but its "Trim" function works only from start of video file while I need it to work from end.
    Quote Quote  
  6. avisynth requires re-encoding too, because it frameserves uncompressed audio & video

    keeping the last 30 seconds of clips with varying durations is actually very difficult to script. If they were the same duration it's much easier (because you set a start time from the beginning), or if it's "x" duration long from the start instead of from the end
    Quote Quote  
  7. Originally Posted by Mavrodi View Post
    Avisynth turns out to be simple but its "Trim" function works only from start of video file while I need it to work from end.
    But it is possible with avisynth scripting wise (if you didn't want to lose quality, you can use a lossless intermediate), just not with the original format because avisynth decompresses the audio & video

    You can use clip properties such as framerate, framecount to define the trim points

    e.g it will look something like this . The "30" is hardcoded because you wanted 30 seconds, but if you wanted 45 seconds you would change it to 45

    Code:
    a=last
    .
    .
    .
    t=round(framerate*30)
    
    a
    trim(framecount-t-1, framecount)
    I meant it's difficult to script with non re-encoding tools such as mp4box, mkvmerge, ffmpeg etc... or at least I don't know of an easy way that does it from the end
    Quote Quote  
  8. In your example two clips merge together and the start point of the second one is used to calculate -30 seconds for the first one and so on?

    With some help I got this vegas script:

    Code:
    using System;
    using Sony.Vegas;
    
    public class EntryPoint
    {
        public void FromVegas(Vegas myVegas)
        {
            Timecode cursorPosition = myVegas.Transport.CursorPosition;
    
            foreach (Track track in myVegas.Project.Tracks)
            {
    			track.Selected=true;
                if (track.Events.Count > 1)
                {
                    for (int index = 1; index < track.Events.Count; index++)
                    {
    					cursorPosition = track.Events[index - 1].End;
    					//cursorPosition-=30;
    					track.Events.Split (cursorPosition - 30);
                    }
                }
            }
        }
    }
    but it gives errors:

    "Sony.Vegas.TrackEvents" has no definition of "Split"
    Operator "-" cannot be applied to operand types "Sony.Vegas.Timecode" and "int"
    Quote Quote  
  9. Originally Posted by Mavrodi View Post
    In your example two clips merge together and the start point of the second one is used to calculate -30 seconds for the first one and so on?

    I don't know how to script this in vegas. But even if you could get it to work, it will leave gaps in the timeline unless there was a ripple edit scripted in (maybe gaps are what you wanted). And if your goal was only to cut the clip (not do additional editing in vegas), vegas will re-encode most formats as well with the exception of a few like HDV, DV, XDCAM



    The avisynth example is just returning the last 30 seconds of any given clip. It's just simple math, but it works for sure, at least for typical CFR videos . (VFR is another ballgame and requires other handling and discussion)

    Any given video has a certain number of frames. The frame numbering starts at frame zero. Trim() take on the arguments Trim(start frame, end frame) , and returns the video with those frame numbers inclusively.

    Since avisynth gives you access to clip properties such as FPS, total framecount, it's easy to script the solution. The endframe is just the total framecount, the startframe is your framecount - (30 seconds * FPS) - 1 ; the -1 is because frame numbering starts at "zero"

    But avisynth requires you to create an .avs per file. So you would use a batch scripter then batch encode if your goal was to import into vegas

    As I said earlier, cutting and retaining the end automatically or in a scripted fashion is difficult with most commonly used tools like ffmpeg
    Quote Quote  
  10. Originally Posted by poisondeathray View Post

    As I said earlier, cutting and retaining the end automatically or in a scripted fashion is difficult with most commonly used tools like ffmpeg


    Well I'll eat my words

    ffmpeg has a -sseof parameter now, which means seek from the end of file. I just tested and works with "stream copy" ie. no re-encoding. But it won't always be completely accurate (might be off a few frames) because it can only cut at keyframes (this is due to the compression format used, most typical videos will use long GOP, not intraframe) . So it would be fairly easy to batch process


    But if you figure the equivalent or similar in vegas, please post the answer
    Quote Quote  
  11. You can do it in Vegas Pro with Vegasaur (use free 30 days trial)
    You need to use 3 tools/steps:
    1. Markers tool: create 30 sec regions at the end of each event
    2. Markers tool: run "keep inside regions" command to delete everything but parts inside regions
    3. Smart Trim tool to trim your footage without re-encoding (it depends on your clips' format, read here)
    Quote Quote  
  12. Used Vegasaur, everything works, thank everyone for help
    Last edited by Mavrodi; 19th Jun 2016 at 06:15.
    Quote Quote  
  13. I've written several hundred scripts in Vegas, including many designed to trim the beginning and ending of selected events on the timeline. I'd post one, but I can't quite tell what you are trying to do. Here's one that does something a little similar to what you want. I wrote it a long time ago, but it should still work with the current Vegas version (13).

    I also suggest you visit Ed Toxel's site: www.jetdv.com. He posted hundreds of small scripts to do things like this.


    Code:
    /** 
    * PURPOSE OF THIS SCRIPT:
    *
    * Delete frames from cursor to end of event, and then move all events to the left by n frames.
    *
    *
    * A video track must be selected. If an audio track is selected, nothing happens.
    * The video event on the track that lies beneath the cursor 
    * will be shortened from the cursor to the start of the event.
    * If the track beneath the video track contains audio, the audio event in that track 
    * that lies beneath the cursor will also be shortened by the same number of frames.
    *
    * Copyright © John Meyer 2004
    * Written: June 4, 2003
    * Updated: September 23, 2004
    * Updated to work with Vegas 6.0d on February 4, 2006
    * Updated: October 23, 2011       // Changed to delete from cursor to event end
    *
    **/ 
    
    import System; 
    import System.IO; 
    import System.Windows.Forms; 
    import Sony.Vegas; 
    
    try { 
    
        //Global declarations
        var dStart : Double;
        var dEnd   : Double;
        var dLength : Double;
        var dCursor : Double;
        var trackEnum : Enumerator; 
        var evnt : TrackEvent;
        var delevnt : TrackEvent;
      
        var EventBegin : Timecode = Vegas.Cursor;    // Use this to move cursor position.
        var track = FindSelectedTrack();             // Use this function to find the first selected track.  
        var eventEnum = new Enumerator(track.Events);
        var BeyondCursor : boolean = false;          // This flag used to notify if event is to right of cursor.
    
        if (track.IsVideo()) {                       // Proceed only if selected track is video track.
    
          if ( TrimEventAtCursor() ) {               // Function that trims event and moves all remaining events on track left.
    
            // Get set to look at track directly below the video track.
            BeyondCursor = false;
            trackEnum.moveNext();                    // Go to next track.
    
            if (!trackEnum.atEnd()) {                   // Only proceed if there is a track below the video track.
              track = Track(trackEnum.item());          // When doing the first track (above), these two lines were executed
              eventEnum = new Enumerator(track.Events); // in the FindSelectedTrack() function.
              if (track.IsAudio()) {                    // Only trim the event if this is an audio track.
                TrimEventAtCursor();
              }    
            }
          }
        }
        Vegas.UpdateUI();  
    
    // Move cursor to start of selected event (cursor stays at same media location).
    Vegas.Cursor = EventBegin; // Remove this line to keep cursor in same location.
    
    } catch (e) { 
      MessageBox.Show(e); 
    } 
    
    // End of main program
    
    
    
    // Beginning of functions
    
    function FindSelectedTrack() : Track {
      trackEnum = new Enumerator(Vegas.Project.Tracks);
      while (!trackEnum.atEnd()) {
        var track : Track = Track(trackEnum.item());
    
        if (track.Selected) {
          return track;
        }
        trackEnum.moveNext();
      }
      return null;
    }
    
    
    /** 
    *
    * The following function finds the event on the selected track 
    * that lies under the cursor. It also deselects all other events. 
    *
    **/
    
    function TrimEventAtCursor() {
    
      var EventFound : boolean = false;  // Function returns false if no video media under cursor.
      var DeleteFrames : Timecode  = new Timecode("00:00:00:01");
      var DeleteTime : Double = DeleteFrames.ToMilliseconds(); 
    
      dCursor = Vegas.Cursor.ToMilliseconds(); // Remember the cursor position.
    
      //Go through each event on the track.
    
      while (!eventEnum.atEnd()) {
        evnt = TrackEvent(eventEnum.item());
        evnt.Selected = false;  // De-select the event
    
        // Get the event's start and length timecode, in milliseconds.
        dStart =  evnt.Start.ToMilliseconds();
        dLength = evnt.Length.ToMilliseconds();
    
        if (BeyondCursor) {                       // Move, but don't truncate events to the right of the event under the cursor.
            evnt.AdjustStartLength(evnt.Start-DeleteFrames, evnt.Length, false); // Use this line with 4.0d and beyond.
        }
    
    /**
    *     If the cursor timecode is between the beginning and end of the 
    *     event timecodes, then select the event, and trim end by n frames.
    *     Move selected event and all events to right of cursor to left by n frames.
    **/ 
    
        if ( (dCursor >= dStart) && ( dCursor < (dLength + dStart) ) ) {
          evnt.Selected = true;                 // Select this event.
          EventFound = true;
          BeyondCursor = true;                  // Remaining events are to right of cursor.
          DeleteFrames = Timecode(evnt.End) - Vegas.Cursor;
    
    
          DeleteTime = DeleteFrames.ToMilliseconds();
          EventBegin = evnt.Start;
          dLength = dLength - DeleteTime ;
          // Next two lines truncate end of event
          evnt.AdjustStartLength(new Timecode(dStart), new Timecode(dLength), true);
        }
    
        eventEnum.moveNext();                   // Go to next event on this timeline.
    //Vegas.UpdateUI();
    //MessageBox.Show("stop");
        } 
    return EventFound;
    }
    Quote Quote  
  14. Member racer-x's Avatar
    Join Date
    Mar 2003
    Location
    3rd Rock from the Sun
    Search Comp PM
    Since Vegasaur uses ffmpeg to make cuts on key-frames, why not just do it with an ffmpeg batch script instead and save time?

    Just create a new folder named "CUT" in the folder of your clips. Then use this batch script to trim and keep the last 30 sec of all clips and put them in the "CUT" folder.

    Code:
    SET PATH="C:\FFMpeg\64-bit"
    for %%a in ("*.mp4") do ffmpeg -sseof -30 -i "%%a" -c copy "CUT\%%a_Cut.mp4"
    
    pause
    Just edit path to ffmpeg and extension desired.
    Got my retirement plans all set. Looks like I only have to work another 5 years after I die........
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!