Answers.Body: <p>You almost invented EDL files. It can be rendered with almost any NLE editor.</p>
  
  <p>If you want cut out part of file, you can use ffmpeg:</p>
  
  <pre><code>     ffmpeg -ss 3:00 -i file.mp4 -t 1:01 -c copy file_00300_00401.mp4
  </code></pre>
  
  <p>As you can see, here <code>-copy</code> option, so cut points will be only on keyframes. No quality loss. If you want more precise, you must reencode whole video (and possible move <code>-ss</code> option after <code>-i</code>)</p>
  
  <p>To achieve your text format/file naming style, you must write script in any language. Just parse input data and paste it as ffmpeg's options.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-02T12:20:44.073Z
Answers.Text: Thank you. That solves part of my problem I guess, still have to test it, but how can I batch cut pieces from the a larger video based on seconds. I will update my question to explain this.
Answers.UserDisplayName: digit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-02T18:32:06.060Z
Answers.Text: Just learn any scripting language. `.bat` files is very hard or even now usable with complex processing. I prefer to use Perl for this.
Answers.UserDisplayName: bukkojot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-30T17:21:53.837Z
Answers.LastActivityDate: 2017-10-30T17:21:53.837Z
Answers.UserDisplayName: bukkojot
Body: <p>What I would like to achieve is that a script runs through a folder of video files e.g.</p>
  <pre><code>001.mp4
  002.mp4
  003.mp4
  </code></pre>
  <p>and cuts these video according to a .csv or .xls or .txt with the timestamp e.g:</p>
  <pre><code>001.mp4, 00:00:00 - 00:00:03, 00:05:01 - 00:09:56, 
  002.mp4, 00:03:00 - 00:04:01, 00:06:01 - 00:08:00,
  </code></pre>
  <p>I would also like this to be as accurate as possible and wonder what the best approach is to get frame accuracy. I don't fully understand this, but some research suggests that the best would be to force keyframes at the edit points before cutting it.</p>
  <p>The output should be named according to the video file name and cut times.</p>
  <pre><code>New folder: 
  
  001_000000_000003.mp4
  001_000501_000956.mp4
  </code></pre>
  <p>so in pseudo code I would think the following:</p>
  <pre><code>for i in *.mov; do 
     ffmpeg -i &quot;$i&quot; - force_key_frames-at-all-cut-points-according-to-csv file outputfile.mov (same as start file ?)
     ffmpeg -i &quot;$i&quot; - cut-video-according-to-cut-points &quot;$i&quot;+startpoint+endpoint.mov
  </code></pre>
  <p>In a next step it would be great to create these timestamps (with any software, ideally ffmpeg) by clicking and creating markers for in and out.</p>
  <p>Any idea how I could achieve the first step would be great.
  Also if there is already a ready script/software(open source) that can do this it would be great.</p>
  <p>Thank you for your help.</p>
  <p><strong>Update:</strong></p>
  <p>I now have a .txt file with timestamps that I can extract automatically (every line a value in second like this):</p>
  <pre><code>timestamp0 (00:00)
  timestamp1 (3.3 seconds)
  timestamp2 (10.2 seconds)
  timestamp3 (16.7 seconds)
  </code></pre>
  <p>Now I would like to parse always two pairs (e.g. timestamp0, timestamp1; timestamp2, timestamp3 ) and cut them from the larger video file and save them in a file with the seconds like this:</p>
  <pre><code>ffmpeg -ss timestamp0 -i inputfile.mp4 -t timestamp1 -c copy inputfile_time0_time1.mp4
  </code></pre>
  <p>How can I iterate over all the files in the directory, apply the cuts and save them to file ? Or if that is too difficult, how can I do this for one video ?</p>
  <p>Thanks again</p>
  
Tags: <ffmpeg>
Title: How to batch cut a folder of videos with a list of timestamps
UserDisplayName: digit
ThreadText: # How to batch cut a folder of videos with a list of timestamps
  
  (Asked by: username_0 on 2017-10-30)
  
  What I would like to achieve is that a script runs through a folder of video files e.g.
  
  ```
  001.mp4
  002.mp4
  003.mp4
  
  ```
  
  and cuts these video according to a .csv or .xls or .txt with the timestamp e.g:
  
  ```
  001.mp4, 00:00:00 - 00:00:03, 00:05:01 - 00:09:56, 
  002.mp4, 00:03:00 - 00:04:01, 00:06:01 - 00:08:00,
  
  ```
  
  I would also like this to be as accurate as possible and wonder what the best approach is to get frame accuracy. I don't fully understand this, but some research suggests that the best would be to force keyframes at the edit points before cutting it.
  
  The output should be named according to the video file name and cut times.
  
  ```
  New folder: 
  
  001_000000_000003.mp4
  001_000501_000956.mp4
  
  ```
  
  so in pseudo code I would think the following:
  
  ```
  for i in *.mov; do 
     ffmpeg -i "$i" - force_key_frames-at-all-cut-points-according-to-csv file outputfile.mov (same as start file ?)
     ffmpeg -i "$i" - cut-video-according-to-cut-points "$i"+startpoint+endpoint.mov
  
  ```
  
  In a next step it would be great to create these timestamps (with any software, ideally ffmpeg) by clicking and creating markers for in and out.
  
  Any idea how I could achieve the first step would be great.
  Also if there is already a ready script/software(open source) that can do this it would be great.
  
  Thank you for your help.
  
  **Update:**
  
  I now have a .txt file with timestamps that I can extract automatically (every line a value in second like this):
  
  ```
  timestamp0 (00:00)
  timestamp1 (3.3 seconds)
  timestamp2 (10.2 seconds)
  timestamp3 (16.7 seconds)
  
  ```
  
  Now I would like to parse always two pairs (e.g. timestamp0, timestamp1; timestamp2, timestamp3 ) and cut them from the larger video file and save them in a file with the seconds like this:
  
  ```
  ffmpeg -ss timestamp0 -i inputfile.mp4 -t timestamp1 -c copy inputfile_time0_time1.mp4
  
  ```
  
  How can I iterate over all the files in the directory, apply the cuts and save them to file ? Or if that is too difficult, how can I do this for one video ?
  
  Thanks again
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-30. Score: 1
  
  You almost invented EDL files. It can be rendered with almost any NLE editor.
  
  If you want cut out part of file, you can use ffmpeg:
  
  ```
       ffmpeg -ss 3:00 -i file.mp4 -t 1:01 -c copy file_00300_00401.mp4
  
  ```
  
  As you can see, here `-copy` option, so cut points will be only on keyframes. No quality loss. If you want more precise, you must reencode whole video (and possible move `-ss` option after `-i`)
  
  To achieve your text format/file naming style, you must write script in any language. Just parse input data and paste it as ffmpeg's options.
  
  > **Comments:**
  > **username_0**: Thank you. That solves part of my problem I guess, still have to test it, but how can I batch cut pieces from the a larger video based on seconds. I will update my question to explain this.  
  > **username_1**: Just learn any scripting language. `.bat` files is very hard or even now usable with complex processing. I prefer to use Perl for this.  
  
  ---
  
  