I can never get ptQa's solution to work, mostly because I can never figure out what the errors from the filters mean or how to fix them. My solution seems a little clunkier because it can leave behind a mess, but if you're throwing it into a script, the clean up can be automated. I also like this approach because if something goes wrong on step 4, you end up with completed steps 1-3 so recovering from errors is a little more efficient.
The basic strategy is using -t
and -ss
to get videos of each segment you want, then join together all the parts for your final version.
Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:
ffmpeg -i abcdef.tvshow -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow
or
ffmpeg -i abcdef.tvshow -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow
That will make files a.tvshow, c.tvshow and e.tvshow. The -t
says how long each clip is, so if c is 30 seconds long you could pass in 30 or 0:00:30. The -ss
option says how far to skip into the source video, so it's always relative to the start of the file.
Then once you have a bunch of video files I make a file ace-files.txt
like this:
file 'a.tvshow'
file 'c.tvshow'
file 'e.tvshow'
Note the "file" at the beginning and the escaped file name after that.
Then the command:
ffmpeg -f concat -i ace-files.txt -c copy ace.tvshow
That concats all the files in abe-files.txt
together, copying their audio and video codecs and makes a file ace.tvshow
which should just be sections a, c and e. Then just remember to delete ace-files.txt
, a.tvshow
, c.tvshow
and e.tvshow
.
Disclaimer: I have no idea how (in)efficient this is compared to the other approaches in terms of ffmpeg
but for my purposes it works better. Hope it helps someone.
possible duplicate of Splitting video in multiple episodes with ffmpeg, also perhaps check out Using FFMpeg to cut a video into 2 minute clips
– Ƭᴇcʜιᴇ007 – 2013-11-28T20:18:08.7032That is not what I am asking, I would like to get it all in one "episode", but this would have different sections from the original video. – Matias – 2013-11-29T15:21:56.717
@Matias, if you were asking how to cut a few clips out of the video and leave the rest as is, that would be one thing, but you want to take a few clips from it and combine them with clips from other videos which makes this not a separate, unique question. You have to do what the other questions asked to get the separate segments, then combine them. – Synetech – 2013-11-29T16:47:01.627
1@Synetech thanks for your answers. I do not want to combine them with clips from other videos. I just want to remove some parts from the videos. For example, if my video could be represented by ABCDEFG, I would like to create a new one that would consist of ACDFG. – Matias – 2013-11-29T17:10:03.010
@Synetech That wasn't me, it was Tog who must have missunderstood. – Matias – 2013-11-29T17:47:01.890
Okay then, that makes sense now. I’ve edited the question to clarify what you want to do, and it is indeed a good question. It’s easy to do that with a GUI editor, but doing it with FFmpeg will probably be a challenge (if possible at all). You may end up having to do what I said and cut each section to a separate file then combine them.
:-(
– Synetech – 2013-11-29T17:56:03.010@Synetech I cannot use a GUI editor because I am using FFmpeg in order to execute in a C# application. I have already tried creating various cuts and the joining them, but I had sync problems. Thanks! – Matias – 2013-11-29T18:08:34.200
I’ve had that problem even with a GUI editor. Maybe someone who knows FFmpeg well will know of a way. I tried finding one, but all I can find are people asking how to extract a clip to a new file, not delete it. This is really odd because removing part of a video is a perfectly normal, common task—it must not be possible. All I could find were two pages where this was asked, but they ended up cutting and joining.
– Synetech – 2013-11-29T18:51:28.580:-(
Also, it was suggested to try mencoder.ffmpeg is essentially an encoder. You can choose to not re-encode, but that still does not make it
cutting
as in a NLE. For what you wish to achieve, I believe the only way is to have a temporary storage(s) which will again be joined (concatenated). In other words, no directdelete portion
. – Rajib – 2013-11-30T07:42:31.793