Log in

View Full Version : Cut first 51 seconds from different avi-files as batch-process?


D.IKE.E
25th April 2011, 17:41
I have many (~ 65) videos (.avi) where I want to cut a specific length from the beginning. For example the first 51 seconds.
I know how to cut with VirtualDub, but it would be too much work for every single video. Is there any batch-process that allows me to add all files, specify the seconds I want to cut (once) and start the process?

Zarxrax
25th April 2011, 17:57
Check out avspmod. Open the macro titled '[1] Batch example.py' and you should be able to do it. You can use the Trim() command to trim parts from each file. But you need to specify the amount to trim in frames rather than seconds.

D.IKE.E
25th April 2011, 18:28
Hm, I don't know what to write in the AvsPmod-Window. When I write trim(0,1502) in line 1 (want to cut 1502 frames from the beginning), then open the macro and choose the folder with the videos, I get a .avs-file for each video with this text in it (first one):
AVISource("M:\01.avi")
Sharpen(1.0)
Info()
Obviously the trim-code wasn't included and there's no ouput-folder, or is the source-folder used?

Zarxrax
25th April 2011, 18:42
You need to open batch example.py file in a text editor and modify it.
It doesn't use anything from the actual program window, its all contained in the script.
You will just need to find the Sharpen and Info lines, and replace that with the trim.
And yes, i believe it outputs to the same folder.

txporter
25th April 2011, 19:49
You can make a simple batch file that can be run in windows. Something like this:
FOR %%A IN (*.avi) DO (
ECHO avisource("%%A"^)
ECHO Trim(0,1501^)
)> %%~nA.avs

Just copy that into a text file and called it trim.bat (or whatever_you_want.bat). It will create an avs file for each avi in the directory. Then you can batch process the avs files through virtualdub (or you could use xvid_encraw or many other encoders that take avisynth input).

D.IKE.E
26th April 2011, 07:23
Okay, now my .avs-files have
avisource("01. avi")
Trim(0,1502)
(with the correct filename for each video) But unfortunately I'm an AutoGK-user so never handled with .avs-files ;) I see that I can open them in VirtualDub(Mod) but how can I process all 65 .avs-files automatically?

-TiLT-
26th April 2011, 07:38
Maybe you should just use ffmpeg or mplayer/mencoder for this task.
There is no need to reencode then.

txporter
26th April 2011, 17:22
Good point, -TiLT-.


setlocal
set ffmpeg="PathTo\ffmpeg.exe"

mkdir output

FOR %%A IN (*.avi) DO (
%ffmpeg% -i %%A -t 51 -vcodec copy -acodec copy "%%~dpA\output\%%~nA.avi"

)

D.IKE.E
27th April 2011, 13:02
Okay first (not so big) problem: When the video has spaces in the filename, I get an error. Is it fixable? If not I can rename easily with Renamer but perhaps there's a workaround for the .bat?
Second problem: As a result I get a video file with the first 51 seconds, but I want them to be cut from the video ;)

Emulgator
28th April 2011, 15:27
The second problem: Think of Trim (x,y) as Keep (x,y)
This function actually keeps the frames specified, so to trim off the first 51 seconds for a given framerate I would suggest

startcutoff=51 # Input your startcutoff in seconds here
Trim(int(startcutoff*Framerate), 0)

D.IKE.E
28th April 2011, 16:05
That's for AviSynth, aye? I used txporters code in a batch-file because I still don't know how to load and process all .avs-files automatically instead of opening every single one...

StainlessS
28th April 2011, 18:47
Using '-ss 51' instead of '-t 51' seems to do the trick.

D.IKE.E
28th April 2011, 20:12
Yes, that's it!
Just needed to correct the time a bit because of the keyframes. And even nicer is, the second (unwanted) audio stream in the videos gets lost ;)

/Edit: Hm okay thanks for your help, but perhaps you can help me with the next thing :o How to cut the last 33 seconds from the same files, too ??? :)

StainlessS
28th April 2011, 23:15
How to cut the last 33 seconds from the same files, too ???

There does not seem to be an "end time" switch, if the clips
are all of fixed length of say 1000 seconds then could
use (1000-51-33) ie 916 after the '-t' swich.


EDIT:-

`-y' Overwrite output files.

`-t duration'
Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.

`-ss position'
Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.

Also, -ve durations dont work relative the end, I tried it.

txporter
29th April 2011, 17:14
According to this blog post (http://blog.nguyenvq.com/2011/02/26/split-cut-or-sample-a-video-file-on-the-command-line/), you should be able to do it with mencoder.

mencoder -ss 00:00:51 -endpos XX:XX:XX -ovc copy -oac copy in.avi

You still need to get the duration for each video. Perhaps there is some way to code this with python or something to grab the duration for each file and perform the subtraction for you to get the endpos. I am not a coder myself, so that is totally beyond me. :)