1

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

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.

  • 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. – digit Nov 2 '17 at 12:20
  • Just learn any scripting language. .bat files is very hard or even now usable with complex processing. I prefer to use Perl for this. – bukkojot Nov 2 '17 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.