How cut videos into clips using ffmpeg
Вставка
- Опубліковано 21 кві 2020
- 🎨 Artist/Thumbnail Creator: jawhaj.art
📝 Blog: donaldfeury.xyz/topics
👥Memberships: vod.strms.net/j/UCTHij3Ac5Giz...
In this video I show you how to cut sections of video and audio out into separate files for use in your projects by only using ffmpeg. This is part of a series about automating video editing.
THANK YOU ###
Newest Channel Member -
Newest Subscriber - Phillip Lineburg
WANT TO SUPPORT THE CHANNEL? ###
💰 Support Links: donaldfeury.xyz/donate
WANT TO ASK ME A QUESTION? ###
💬 Contact Me: donaldfeury.xyz/contact
SOCIAL PLATFORMS ###
🗣 Matrix: donaldfeury.xyz/matrix
💬 Pleroma: donaldfeury.xyz/pleroma
🗨️ Discord: donaldfeury.xyz/discord
🐦 Twitter: donaldfeury.xyz/twitter
VIDEO PLATFORMS ###
🎦 Twitch: donaldfeury.xyz/twitch
🎥 Odysee: donaldfeury.xyz/odysee
OTHER THINGS ###
📁 GitLab: donaldfeury.xyz/gitlab
🎥 My Gear: kit.co/dfeury
SOFTWARE I USE ###
🌐 Brave Browser - brave.com/
🎞 ffmpeg: ffmpeg.org/
📽️ Open Broadcaster Software: obsproject.com/
🎨 GIMP: www.gimp.org/
📙 Neovim: neovim.io/
Thank ya'll for your time and support!
#ffmpeg #cutvideo #videoediting - Наука та технологія
Fun Fact - I edited this entire video without an editor, only used ffmpeg
You know your stuff...legend!
Nah, I'm just teaching things as I figure them out
@11Lips You can get the full duration of your video using ffprobe, which you probably already have if you have ffmpeg installed, try something like this in your script somewhere:
ffprobe -i %%a -show_entries format=duration -v quiet -of csv="p=0"
Store that in a variable and subtract 5 and bam you have your new video duration, then just do:
-to (VIDEO_DURATION_VARIABLE_HERE), instead of -ss 15
@11Lips Thats probably not going to run since I doubt you have the "bc" program installed. I would advise you look up a basic batch scripting tutorial, otherwise, most of what I show or tell you isn't going to make sense.
@@plowe6751 Premier Pro is definitely not free from what I remember. Other than DaVinci I think there is kdenlive and olive I remember seeing www.youtube.com/@BrodieRobertson make a video or two on
@12:28 You can actually use the `-to` option to specify a direct timestamp to stop at in combination with the preemptive `-ss` option acting upon the input file; but it takes some extra options to make it work.
ffmpeg -ss 00:16:00 -i ow-beanie.mp4 -to 00:16:15 -copyts -avoid_negative_ts make_zero -c copy ow-beanie-outro-fast.mp4
The `-copyts` option will copy the timestamps over from the input so that the `-to` option targets correctly. But you also need the `-avoid_negative_ts make_zero` option so that your output video will then start at 00:00 - otherwise you'll see the video start playing with a 16:00 timestamp at the beginning, having been copied over from the input without being adjusted.
I do wanted to add that I was also able to parse a 30 minute video in small chunks using ffmpeg which tool maybe 5 seconds and this is a thank you to Donald for clearly showing the power of ffmpeg:
ffmpeg -i hybrid_setup-2021-02-19_12.11.06.mkv -ss 00:00:00 -to 00:15 -c copy hybrid1.into.mkv -ss 00:00:50 -to 00:01:57 -c copy hybrid-sync.mkv -ss 00:2:33 -to 00:05:14 -c copy hybrid-cloud-ui.mkv -ss 00:25:05 -to 00:25:35 -c copy hybrid-pac.mkv
[rpatros@patros-pc Videos]$ ls -lh hybrid*.mkv
-rw-r--r-- 1 rpatros rpatros 378K Nov 14 10:32 hybrid1.into.mkv
-rw-r--r-- 1 rpatros rpatros 7.3M Nov 14 10:32 hybrid-cloud-ui.mkv
-rw-r--r-- 1 rpatros rpatros 1.5M Nov 14 10:32 hybrid-pac.mkv
-rw-r--r-- 1 rpatros rpatros 76M Feb 19 2021 hybrid_setup-2021-02-19_12.11.06.mkv
-rw-r--r-- 1 rpatros rpatros 3.3M Nov 14 10:32 hybrid-sync.mkv
You can see the sizes for each file output vs, the original being at 76mb. This is really nice since we don't have to re-encode the video as we kept the file format the same. With the video editor, it would have taken much much longer.
Very nice, well done
Thank you so much! This is an absolute godsend lol; I've spent the past three days trying to album split with ffmpeg and can finally do it.
THANKS!! Been searching for this exact solution as I need so segment 100s of videos of various talks that are not of similar length. I have the timestamps and was hoping I could break the one video into its various segments with a single function.
Just to be sure, though, the time after the "-to" represents a duration after the "-ss (timestamp)" or is it a second timestamp? Meaning for the "hybrid-pac.mkv" the file size looks like it's a 30s video, not a 25m35s video. I had read a moment ago (and thought he explained in the video 13:00) that the time value after the "-to" was read as a duration after the "-ss (timestamp)".
Thanks for taking the time out to do this. Great job bro. Very helpful.
Glad it helped ya man
i just use this for cutting video or audio ( ffmpeg -ss 00:00:00.000 -i "input.mp4" -to 00:00:10.000 -c copy "output.mp4" )
These videos are so incredibly helpful! 🙏
Thank ya Victor
Wildly helpful, thanks!
Glad I could help ya man
Thank you! Very useful!
for python users: import os then use os.system() function to put that command and run it off of your editor. I had to learn this since your mostly a linux programmer. I appreciate the video!
Thank's mate, these vids are really helpful! And of course, have subscribed and hit the like button, :)
Thanky, I'm glad they helped
A very good video about this item. Thanks.
Glad it was helpful!
thanks. it's very helpful video
Glad it helped man
'olly 'ell nice to meet you man
hey, that's freakin awesome.
Did you already make a vertically scrolling of an image until the end , so to make it like a video ?Thanks
Never had a need to so I did not
What shell do you use?
Hi
I'm a video editor an i really like ffmpeg and what you are doing. I think in this times when video is a very important part of our lives this kind of approach to video editing is really useful for many reasons.
I want to say thank you for let us see how you are doing your video editing, seeing the process is so much helpful than seeing a man page or a written tutorial.
Do you think is there a way to generate a list of in points and out points for a group of video files in a directory, then pass the list file to ffmpeg to do the trimming?
I know is not easy, I try myself but couldn't achieve the list file.
If there were a way to generate this list you could review all the video files in the order you want those in your final video, set the in and out points for each video file, the run something like your script that takes the list with the in and out point for each file and bam! In theory you have a workflow for get your editing done just after reviewing your shots for your video.
Thanks again and see you around.
In theory it sounds possible, you would have to clarify on what basis the in and out points are being generated.
As for how to generate them in a way that could be passed into ffmpeg, you could maybe do something like a CSV file? Where you do each row has (FILE_PATH,IN,OUT), then in the language of your choosing, iterate over the CSV file, and for each entry, generate a ffmpeg command to write only that section out to a seperate file using the -ss flag to set the IN timestamp and the -to flag to set the OUT timestamp. Since you would just be writing a section of the stream out, you can use -c copy to avoid re-encoding and it should be pretty quick.
@@DonaldFeury Oh! maybe a cvs file, I don't have any experience programming so I really don't know. I'm thinking in learning python just for this because is really useful, for example to generate a selects reel or put together a quick edit, or generate an edl/xml file to bring specific materials to your NLE.
As an editor I really spend a lot of time in the file manager, namely windows explorer or apple finder, always thought my edits start right there, reviewing and organizing the material, to then put that in the NLE. But if there where a layer in the file manager that allows you with this kind of workflows it will be invaluable.
Question. Do you think python is adequate for this purpose?
I guess i will keep looking for something like I want. Cheers!!!
@@hernandoramos python would be great for it. Check a python library someone on reddit made me aware of called moviepy, i'm messing with it to do auto trimming based on silence
liked and subscribed! trick request: trying to figure out a similar "preview" feature that a video editor has using streams
You got a subscriber here for the way you show ffmpeg usage.
One question is, can you splice the input video into multiple output files using different timestamp in a command.
edited: I did manage to create multiple video outputs and included it in the next comment.
This is probably close but it's splitting into even segments rather than at specific timestamps
medium.com/@taylorjdawson/splitting-a-video-with-ffmpeg-the-great-mystical-magical-video-tool-%EF%B8%8F-1b31385221bd
suggestion for video. take a long album track and cut it up into single tracks going by the short silences inbetween tracks. I dont know how to do that. Guess you would need to make a timestamp file first?
Hmm that's not a bad idea, ye you would need to generate timestamps using something like the detectsilence filter.
OVERWATCH 😍😍😍😍😍😍
yall come back now ya hear.
Ya darn tootin
Hello sir,
I want to remove last 5 second of video. Help me please
Do you maybe know if it is possible to do an B-roll insert edit,L-cut or J-cut using ffmpeg using losseless copy techniques?thx
Possibly, actually there is a good tool for that exact thing built on top of ffmpeg called editly, you should check it out - github.com/mifi/editly
@@DonaldFeury thx i will check it out
Np, let me know how it goes
@@DonaldFeury i will.thx
hi. should i care about TS while cut video?
timestamps? I haven't really run into an issue with timestamps before when cutting clips out like this.
Now, if you go to concat them back together with re-encoding you may have weird issues. If that happens just let the re-encode happen.
how to clip multiple clips with one command?
What kind of command prompt are you using? Where can I get one?
starship.rs/
it keeps saying no such file or directory
I keep using -acodec copy -vcodec copy, so there is no need for that? I can just use
ffmpeg -ss 32 -i input.mov -c copy output.mov
Ye, *-c* is just a shorthand to tell ffmpeg to copy both video and audio codecs. *-c copy* is the same as *-vcodec copy -acodec copy*
ffmpeg -i 1raw.mp3 -t 15 -c copy output.mp3
[mp3 @ 0x558ad1bb4740] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Getting this error. What's wrong here?
donaldfeury.xyz/contact/ contact me through any of these methods and I'll be glad to help
I'm trying to remove green screen, can you help me?
"-vcodec": "libx264",
"-r": 25,
"-filter_complex":"[1:v]colorkey=color=00FF00:similarity=0.85:blend=0.0[ckout];[0:v][ckout]overlay[out]",
"-map": "[out]"
I'm afraid I've never removed a green screen with ffmpeg, so I would know as much or less about it as you.
If I happen to need to figure it out, I will let you know. If YOU figure it out, it would be awesome if you told ME how to do it. 😂
i have two commands to run one after one sepratly.
"ffmpeg -i input.mp4 -ss 00:01:30 -to 00:09:45 -c:v copy -c:a copy output.mp4"
& "ffmpeg -i output.mp4 -vf scale=320:240,setsar=1:1 final.mp4"
can do both function at once means
Can i do complete action ( input.mp4. To final.mp4) once
Please write these two commands into one . Without losing source file . {input.mp4---to-- final.mp4 } once Thank you...
You certainly can, also keep in mind you can't copy codecs if you're running them through a filter. You could copy the audio stream over since you're only running a filter on the video stream.
It would look something like this:
*ffmpeg -i input.mp4 -ss **00:01:30** -to **00:09:45** -vf scale=320:240,setsar=1:1 -c:a copy final.mp4*
thankyou for the tip boss, i will reciprocate with a little tip of my own - cut out the nose candy, it will lead to no good for you ok
Nice job, but can you write code to how to take for example an hour long video and cut it in 10 min increments, no encoding?
Thank You