Fast way to automatically cut and export a video into multiple files?
June 5, 2019 8:35 AM
I'm trying to make a music video. I'm taking a TON of different gifs/videos and cutting them up into individual 1 second files. Is there any program out there that can do this automatically, and at a good speed? I'm imagining something where I upload the video/gif, tell it how many clips I want (or how long each clip should be), tell it where to save, and let it do it's thing. I then rinse and repeat.
I tried using Premiere Pro to export each cut clip to its own file, but that takes WAY too long. I'm using Filmora instead. I'm cutting up each gif/video, deleting all other clips except the one I want to save, and then exporting it. This is way faster than Premiere Pro, but still taking a long time.
I tried using Premiere Pro to export each cut clip to its own file, but that takes WAY too long. I'm using Filmora instead. I'm cutting up each gif/video, deleting all other clips except the one I want to save, and then exporting it. This is way faster than Premiere Pro, but still taking a long time.
Are you comfortable using a Unix command line? If you are, here's a good solution using a single command in ffmpeg. If you're not, I would still suggest learning the bare minimum and then using that solution, just because ffmpeg is by far the most efficient tool for this kind of task.
posted by J.K. Seazer at 9:07 AM on June 5, 2019
posted by J.K. Seazer at 9:07 AM on June 5, 2019
Are there videos on how to do this? (For either of the two suggestions so far)
I'd be more comfortable with a tutorial, because I don't know anything about coding. This looks very promising though!
posted by ggp88 at 9:28 AM on June 5, 2019
I'd be more comfortable with a tutorial, because I don't know anything about coding. This looks very promising though!
posted by ggp88 at 9:28 AM on June 5, 2019
What operating system are you using?
posted by flabdablet at 9:37 AM on June 5, 2019
posted by flabdablet at 9:37 AM on June 5, 2019
Thank you all very much! I'll come back if I have any questions.
posted by ggp88 at 10:03 AM on June 5, 2019
posted by ggp88 at 10:03 AM on June 5, 2019
So I have ffmpeg installed. But I'm having trouble. My file is called test.mp4 and it is 31 seconds long. When I type:
ffmpeg -i 'test.mp4' -map 0 -codec copy -f segment -segment_time 0:01 'output%031d.mp4'
I get this:
test.mp4: No such file or directory.
-------------
When I paste the entire file path instead, like this:
ffmpeg -i '/Users/geoffparker/Desktop/Videos/ffmpeg-4.1.3/test.mp4' -map 0 -codec copy -f segment -segment_time 0:01 'output%031d.mp4'
It does some stuff, and I don't get that red error message about no such file or directory, but I don't actually end up with a new file in the folder. Nothing seems to actually happen.
posted by ggp88 at 11:57 AM on June 5, 2019
ffmpeg -i 'test.mp4' -map 0 -codec copy -f segment -segment_time 0:01 'output%031d.mp4'
I get this:
test.mp4: No such file or directory.
-------------
When I paste the entire file path instead, like this:
ffmpeg -i '/Users/geoffparker/Desktop/Videos/ffmpeg-4.1.3/test.mp4' -map 0 -codec copy -f segment -segment_time 0:01 'output%031d.mp4'
It does some stuff, and I don't get that red error message about no such file or directory, but I don't actually end up with a new file in the folder. Nothing seems to actually happen.
posted by ggp88 at 11:57 AM on June 5, 2019
It sounds like you're running the command from a different directory than the one containing the video. If you type 'pwd', it will tell you what directory you're currently working from. Then if you type 'ls' (lowercase L), you can see the files in that directory. I bet you'll see all the segments you created the second time you ran ffmpeg.
If you want to move to a directory, use the 'cd' command. 'cd /Users/geoffparker/Desktop/Videos/ffmpeg-4.1.3' will move you to the directory containing your video. Then you should be able to run the first ffmpeg command above and have it work.
Finally, if you want to clear out all the segments you made the first time, first type 'cd' by itself to move back to the home directory, then type 'rm output*.mp4' to delete the segments (but make sure you don't have any other files matching that description that you want to keep!).
posted by J.K. Seazer at 12:36 PM on June 5, 2019
If you want to move to a directory, use the 'cd' command. 'cd /Users/geoffparker/Desktop/Videos/ffmpeg-4.1.3' will move you to the directory containing your video. Then you should be able to run the first ffmpeg command above and have it work.
Finally, if you want to clear out all the segments you made the first time, first type 'cd' by itself to move back to the home directory, then type 'rm output*.mp4' to delete the segments (but make sure you don't have any other files matching that description that you want to keep!).
posted by J.K. Seazer at 12:36 PM on June 5, 2019
Thank you J.K. Seazer! I'll try that out next, but for now, I was able to find where the files were being saved. And I was able to sussesfully create 4 .mp4 files from one file.
The problem I'm facing now is that the particular .mp4 file I'm trying to break up is 14 seconds long. Instead of 14 files, each being 1 second, I'm getting 4 files... the first 2 are 5 seconds, the third is 3 seconds, and the last is 1 second.
Why is this? By the way, this is what I put in to make this happen.
ffmpeg -i '/Users/geoffparker/Desktop/Videos/51174715_1759725880799446_3599761912121786368_n.mp4' -c copy -map 0 -segment_time 00:00:01 -f segment -reset_timestamps 1 'output%02d.mp4'
I would think that this part -segment_time 00:00:01 would make it to where each segment is 1 second long.
Do you know how I can fix this?
posted by ggp88 at 12:54 PM on June 5, 2019
The problem I'm facing now is that the particular .mp4 file I'm trying to break up is 14 seconds long. Instead of 14 files, each being 1 second, I'm getting 4 files... the first 2 are 5 seconds, the third is 3 seconds, and the last is 1 second.
Why is this? By the way, this is what I put in to make this happen.
ffmpeg -i '/Users/geoffparker/Desktop/Videos/51174715_1759725880799446_3599761912121786368_n.mp4' -c copy -map 0 -segment_time 00:00:01 -f segment -reset_timestamps 1 'output%02d.mp4'
I would think that this part -segment_time 00:00:01 would make it to where each segment is 1 second long.
Do you know how I can fix this?
posted by ggp88 at 12:54 PM on June 5, 2019
According to the ffmpeg documentation, by default, ffmpeg will not split a video exactly at the specified time, but on the next key frame after the specified time. It is possible to force ffmpeg to split on exactly specified frames by using the -force_key_frames option, but it adds some complication because you have to transcode (meaning you can't just use '-c copy'). Unfortunately, this is out of my depth, so I can't help much more, but check out the examples and experiment with different split values.
posted by J.K. Seazer at 3:31 PM on June 5, 2019
posted by J.K. Seazer at 3:31 PM on June 5, 2019
Thanks J.K. I'm not really sure what I did differently, but I was able to figure out how to split each video into 1 frame.
Now that I've got it down, things are moving super fast. I feel like a magician doing this! What took me 2 days I've done five times as much in about 2 hours!
It's really simple: All I'm doing is (I'm on Mac)
1. Create a folder with the title of what the video is.
2. Right click that folder, hit option, and choose Copy "Folder Name" as Pathname
3. Go to terminal, put this in (and then hit enter):
cd 'Paste the folder path name'
So for example,
cd '/Users/geoffparker/Desktop/Videos/untitled folder/001 VIDEO FRAMES/FolderName'
4. Go to the file that you want split up, right click it, hit option, and choose Copy "Video.mp4" as Pathname"
5. Go to terminal (clear it if need be) and put in:
ffmpeg -i 'Paste the file path here' -c copy -map 0 -segment_time 00:00:01 -f segment -reset_timestamps 1 'output%03d.mp4'
Hit enter, and voila! If you check out the folder, you'll see all of the frames, each saved as .mp4s.
posted by ggp88 at 4:02 PM on June 5, 2019
Now that I've got it down, things are moving super fast. I feel like a magician doing this! What took me 2 days I've done five times as much in about 2 hours!
It's really simple: All I'm doing is (I'm on Mac)
1. Create a folder with the title of what the video is.
2. Right click that folder, hit option, and choose Copy "Folder Name" as Pathname
3. Go to terminal, put this in (and then hit enter):
cd 'Paste the folder path name'
So for example,
cd '/Users/geoffparker/Desktop/Videos/untitled folder/001 VIDEO FRAMES/FolderName'
4. Go to the file that you want split up, right click it, hit option, and choose Copy "Video.mp4" as Pathname"
5. Go to terminal (clear it if need be) and put in:
ffmpeg -i 'Paste the file path here' -c copy -map 0 -segment_time 00:00:01 -f segment -reset_timestamps 1 'output%03d.mp4'
Hit enter, and voila! If you check out the folder, you'll see all of the frames, each saved as .mp4s.
posted by ggp88 at 4:02 PM on June 5, 2019
I feel like a magician doing this! What took me 2 days I've done five times as much in about 2 hours!
Welcome to the command line, the literate way to operate a personal computer :-)
It's really simple: All I'm doing is [five steps with lots of copying and pasting]
Pretty slick, but you can make it even slicker if you want.
Any command line, or collection of sequential command lines, can be saved as a script that you can activate directly from the Finder by dragging and dropping stuff onto it.
I don't have a Mac myself (Debian ftw!) so I'm doing this from memory, and I might miss a step or two so let's start slow and make sure we stay on the same page. Try this: open a new TextEdit window. Dive into TextEdit's options and turn off everything "smart" - specifically, you don't want "smart quotes" but nothing else that TextEdit considers "smart" is going to do anything but cause confusion so you might as well turn all of it off.
Copy the following three lines and paste them into that window:
Open a Terminal window and enter the following commands:
If you now find yow.command on your desktop and double-click it, you should see a Terminal window open and display the text Yow! followed by another line with yow.command's full pathname.
If that works, try dragging one of your movie files and dropping it onto yow.command's icon. You should see another Terminal window open. Copy the output from that window, paste it into a comment here and we'll go on with the next step.
posted by flabdablet at 12:24 AM on June 6, 2019
Welcome to the command line, the literate way to operate a personal computer :-)
It's really simple: All I'm doing is [five steps with lots of copying and pasting]
Pretty slick, but you can make it even slicker if you want.
Any command line, or collection of sequential command lines, can be saved as a script that you can activate directly from the Finder by dragging and dropping stuff onto it.
I don't have a Mac myself (Debian ftw!) so I'm doing this from memory, and I might miss a step or two so let's start slow and make sure we stay on the same page. Try this: open a new TextEdit window. Dive into TextEdit's options and turn off everything "smart" - specifically, you don't want "smart quotes" but nothing else that TextEdit considers "smart" is going to do anything but cause confusion so you might as well turn all of it off.
Copy the following three lines and paste them into that window:
#!/bin/sh echo 'Yow!' printf '%s\n' "$0" "$@"Save the result to your desktop as yow.command
Open a Terminal window and enter the following commands:
cd Desktop ls -lThis should get you a listing of every file currently visible on your desktop, and yow.command should be among them. All being well, enter
chmod +x yow.command ls -lYou should see that the first column in the listing line for yow.command, which should have looked like -rw-r--r-- after the first ls -l, has now changed to -rwxr-xr-x instead. What you've done here is change the file permissions on yow.command to let the OS know it's OK to execute it as a command; that, together with the fact that its name ends in .command, is enough to make the Finder treat it as a script.
If you now find yow.command on your desktop and double-click it, you should see a Terminal window open and display the text Yow! followed by another line with yow.command's full pathname.
If that works, try dragging one of your movie files and dropping it onto yow.command's icon. You should see another Terminal window open. Copy the output from that window, paste it into a comment here and we'll go on with the next step.
posted by flabdablet at 12:24 AM on June 6, 2019
This thread is closed to new comments.
Basically, figure out a command line that takes a video filename and writes out a new video with the Nth second. Off the top of my head that might be along the lines of:
mencoder {input filename} -ss {seconds} -endpos 1 -ovc copy -oac copy -o {output filename}
And then wrap that in a script or batch file that goes through all the input filenames, increments the number of seconds, and generates output filenames for each combination.
posted by automatronic at 9:06 AM on June 5, 2019