240

If just need to crop Audio/Video from a longer track, what can I use? I tried OpenShot, but I find the export video slow, perhaps its compling all the "layers" into a new movie? Perhaps I just need a simple "crop" tool for audio/video will surfice?

3

22 Answers 22

251

I was going to mention commands like ffmpeg or avconv (The new one) which can OBVIOUSLY split files into groups. For example:

FFMPEG

ffmpeg -ss 00:00:00 -t 00:30:00 -i input.avi -vcodec copy -acodec copy output1.avi
ffmpeg -ss 00:30:00 -t 00:30:00 -i input.avi -vcodec copy -acodec copy output2.avi  
ffmpeg -ss 01:00:00 -t 00:30:00 -i input.avi -vcodec copy -acodec copy output3.avi

Or

ffmpeg -ss 0 -t 100 -i source.m4v -vcodec copy -acodec copy part1.m4v
ffmpeg -ss 100 -t 100 -i source.m4v -vcodec copy -acodec copy part2.m4v  
ffmpeg -ss 200 -t 100 -i source.m4v -vcodec copy -acodec copy part3.m4v  
ffmpeg -ss 300 -t 100 -i source.m4v -vcodec copy -acodec copy part4.m4v

AVCONV

avconv -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi
avconv -i input.avi -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi  
avconv -i input.avi -vcodec copy -acodec copy -ss 01:00:00 -t 00:30:00 output3.avi

Or

avconv -ss 0 -i source.m4v -t 100 -vcodec copy -acodec copy part1.m4v
avconv -ss 100 -i source.m4v -t 100 -vcodec copy -acodec copy part2.m4v
avconv -ss 200 -i source.m4v -t 100 -vcodec copy -acodec copy part3.m4v  
avconv -ss 300 -i source.m4v -t 100 -vcodec copy -acodec copy part4.m4v

Or do some script like here: http://icephoenix.us/notes-for-myself/auto-splitting-video-file-in-equal-chunks-with-ffmpeg-and-python/

16
  • 7
    Beware: According to the man page [ linux.die.net/man/1/ffmpeg ] this results in unnatural, overlapping cuts. For instance, the second command starts at 00:30:00 but goes on for an hour; i.e., up to 01:30:00, so the third command, which starts at 01:00:00, will yield an overlapping cut. It may be the goal, but it wouldn't be very natural. Sep 24, 2012 at 22:12
  • 1
    I can vouch for what ezequiel mentions. When doing the tests with ffmpeg or avconv the overlapping effect appears if using the times as mentioned above. I will update to a more accurate effect although I should mention that the first second will also overlap. I will fix both and add avconv to the group. Thanks ezequiel. Sep 25, 2012 at 3:00
  • Thanks! But these ppa versions are out-of-date. Are the versions in Precise 12.04 good? Or can someone suggest better ones?
    – nealmcb
    Oct 14, 2013 at 14:47
  • Thanks for notifying me. When I get back home I'll post an updated link. Oct 14, 2013 at 15:03
  • 3
    At least when using avconv you don't need to invoke the video and audio codec separately. You should just go with $ avcon -i input-file -codec copy [any option like -ss -t -fs ... just check on ubuntu.manpages.com for avconv] output-file
    – Antonio
    Jan 3, 2016 at 0:20
41

With new version from ubuntu avconv

avconv -i srcFileName -c:a copy -c:v copy -ss 00:03:40 -t 00:01:12 targetFileName
  • First argument time is from time
  • Second argument is duration (not end time) duration may be either in seconds or in "hh:mm:ss[.xxx]" form.

To specify end time instead, use the option -to [end time].

Please refer to ffmpeg documentation for more informations

8
  • Thanks, an expert. Damn me not to read third-rated answer in the thread before doing anything. Without this examples Ī̲’d fail to turn off video recoding (“-vn” failed to produce this effect, for some reason) and would also have other problems. By the way, does “-c:s copy” make the same thing for subtitles? Aug 22, 2015 at 11:24
  • Also, since my experience, when cutting out only the last part (i.e. when beginning of the new video coincides with beginning of the original video) “-ss 0” is potentially problematical and should be omitted. Ī̲ had a program (namely, Bombono DVD) crashed trying to read a file made with “-ss 0” substituted in place of the original file. Aug 22, 2015 at 12:01
  • Thanks Philippe! This helped me a lot. can I ask what the args -c:a copy -c:v copy mean?
    – Alex
    Jan 3, 2016 at 9:43
  • 3
    @Alex c=codec a=audio v=video Jan 3, 2016 at 20:03
  • 2
    @Alex copy to copy the audio codec and video codec to the target stream. See more @ ffmpeg.org/ffmpeg.html#Main-options and refer to the ffmpeg documentation for more informations Jan 4, 2016 at 10:51
40

kdenlive is (in my experience) the easiest software which will allow you to perform that task in a few steps and without problems. Even so, the OpenShot Video Editor project is also useful but it yet needs lots of hard work to get closer to the kdenlive.

Here are a screenshot of the kdenlive and openshot respectively:

enter image description here

enter image description here

Good luck!

10
  • Kdenlive is my favourite. All other linux editors crashed when using MOV files from my Kodak Zi8 camera. Easy to use and very powerful. Jun 16, 2012 at 6:52
  • 2
    Not sure what's going on with my edit. Looks fine in editing mode but here its messed up.
    – Insperatus
    Sep 5, 2012 at 20:59
  • Sorry, I can't understand. Do you mind giving further details? If you think necessary please open a question about your issues. Thank you! Sep 5, 2012 at 21:17
  • 3
    The easiest software Kdenlive asks a hell of irrelevant questions before even starting a project. But when about to do something, it spawns avconv and whenever it fails, Kdenlive won't offer help tp rectify situation and even doesn't report with which exactly parameters it ran avconv. Definitely a non-choice for one willing simply to trim a video file. Aug 22, 2015 at 11:07
  • 2
    Personally, kdenlive seemed good, but the interface is very unintuitive and unnecessarily complex. Also, there seems to be some bug. After loading a clip, sometimes the clip plays. Sometimes it doesn't. Not recommended.
    – Nav
    Jul 23, 2017 at 19:47
32

LosslessCut is focused entirely on clipping/cutting, is simple to use and does not re-encode, meaning exporting is fast.

Screenshot of LosslessCut

To ensure audio remains synced with image, use the keyframe cut option.

Github repo.

5
  • Available on the Snap Store :) Jun 22, 2020 at 18:13
  • 3
    Oftentimes the initial few frames of the next merged clip would be glitchy in the final exported video
    – Harsha
    Jun 1, 2021 at 16:08
  • 1
    @Harsha, I'm not sure if it's relevant to that issue, but are you using the keyframe cut option? Jun 2, 2021 at 13:56
  • Simple and extremely fast (3h video -> 2h in a ubuntu virtual machine in under 10 seconds!).
    – Pierre
    Jun 17, 2022 at 17:57
  • this is the fastest one because it will not render the video, but it is no accurate Nov 21, 2022 at 22:36
25

I like kdenlive for finishing up as well or clipping out small chunks...but if he wants to split a LARGE lecture into smaller pieces he could try:

ffmpeg -i input.mpg -ss 00:00:10 -t 00:00:30 out1.mpg -ss 00:00:35 -t 00:00:30 out2.mpg

discussion of the command is here: http://ubuntuforums.org/showthread.php?t=480343

1
  • 2
    you can use winff (GUI for ffmpeg) also
    – jahid65
    Aug 6, 2011 at 17:36
10

OpenShot Video Editor looks promising. Have you checked it?. Checkout the features: http://www.openshot.org/features/

The official installation method is via AppImage available at https://www.openshot.org/download/

To install it just open a terminal and run the following commands:

sudo add-apt-repository ppa:jonoomph/openshot-edge
sudo apt-get update
sudo apt-get install openshot openshot-doc

Just give a try. alt text

5
  • If he is using maverick it is in the repository
    – Sabacon
    Nov 11, 2010 at 6:26
  • Openshot FTW! :)
    – OpenNingia
    Nov 11, 2010 at 14:16
  • If the OP only wants to quickly crop video, then AVIDemux is far easier to use than OpenShot. I've just tried them both - OpenShot was surprisingly cumbers at just letting me define the in and out points for one video track. Jan 27, 2016 at 22:40
  • OpenShot is definitely more user friendly than any of the other highly upvoted answers here.
    – Nav
    Jul 23, 2017 at 20:10
  • OpenShot is mentioned in the question as program that failed but for me it was acceptable (export is slow but at least it had working preview of position where I cut and was not crashing - unlike other solutions that I tried). Dec 20, 2018 at 5:39
9

I'm using ffmpeg CLI interface for that. It's very easy and fast:

  • to cut video:

    ffmpeg -i InputFile -vcodec copy -acodec copy -ss 00:00:00 -t 00:01:32 OutPutFile
    
  • to cut audio:

    ffmpeg -i InputFile  -vn -acodec copy -ss 00:00:00 -t 00:01:32 OutPutFile
    

In both of these -ss is the start point, while -t is the duration of the piece.

You can calculate duration e.g. using LibreOffice Calc or python's dateutil package, or you can use the -to option which accepts the end time directly.

1
7

My preference for easy video clipping has always been avidemux. Avudemux logo

Just set the video and audio encoding to Copy and choose the container format you want, within reason.

Installation:

entry at apps.ubuntu.com Install avidemux

sudo apt-get install avidemux
4

There is also WinFF that is avconv graphic interface. It works great. I installed it from Ubuntu Software Center.

Here is the screenshot: WinFF

4

Try Avidemux (Ubuntu 14.04 and earlier).

sudo apt-get install avidemux

or LiVES

sudo apt install lives
1
  • Avidemux freezed several times for my under Ubuntu 13.10, even with a x4 CPU.
    – Lucio
    Mar 1, 2014 at 19:01
2

For cutting, merging, scaling etc one can use … Blender (yes, this 3D editor, but it has also video editing part). You need workout some 20-min tutorial to survive the interface, but then it appears to be unexpectedly pleasant to use.

1

I use Kdenlive, but I wouldn't be surprised if you could even slice video this way in PiTiVi:

  1. Create a new project with your full lecture.
  2. Set your start and end points for the first "manageable chunk" in the clip monitor.
  3. Drag from the video in the clip monitor down to your timeline. It will be just the chunk you chose.
  4. Set new start and end points in the clip monitor and repeat as needed.
1
  • 1
    I've looked around, and I can't find any way to divide a long clip into multiple shorter clips that I can easily manage. There is no "clip monitor"; PiTiVi is very simple (and I mean that in a good way!) Obviously, I could just cut up the video and reorganize the unnamed chunks in the timeline, but I'd like to know if there's a better way. Nov 11, 2010 at 6:05
1

In PiTiVi 0.13.5 (Ubuntu 10.10) I was able to simply select a clip and go to Timeline > Split (or just press "S").

1

For quickly cutting I have used MythTV. I recorded some show, let it automatically search for the commercial breaks and fine-tuned the found markers. After this I started the Myth archiving function and burned all to DVD, without the commercials.

I have to admit, it worked gread from about 2006 or such. Somewhere in 2008 or 2009 some update ruined it all, my markers where somehow shifted.

Right now, I'm in the progress of re-installing this myth stuff, just to see if I can get the trimmer/editor and archiver working.

1

If you want a GUI application you can use dmMediaConverter, a ffmpeg frontend, which has a split function, without reencoding, fast. Just add the split points and press Run. Also, it can do a lot of other stuff. http://dmsimpleapps.blogspot.ro/2014/04/dmmediaconverter.html Split function example

2
  • Sadly not open-source, though.
    – Martin R.
    Apr 28, 2017 at 14:15
  • Yes, but it is free.
    – mdalacu
    May 1, 2017 at 7:18
1

vidcutter is a very useful tool for cutting, trimming and merging videos in ubuntu:

Install vidcutter:

sudo add-apt-repository ppa:ozmartian/apps
sudo apt update
sudo apt install vidcutter

works in ubuntu 17.10

1

Yesterday I just found that I can do it online, With a youtube account:) If you are in a hurry, and do not have enough time to try which ubuntu software works for you, then do it online.

Go to youtube account, upload your video, then select Video Manager, there is a Enhancement option, at the bottom right corner there lies Trim option

Watch this 1 minute tutorial if you still can not find it

Screen Capture of the Trim menu

1
  • Uploading 2 GB video to get 50% back? Is it feasible? Jun 28, 2021 at 15:29
1

To just crop without trans-coding

(copying instead), I suggest a yad script to be run from a desktop file launcher.

I have found the script here.

I have modified it a bit to include video formats and to avoid transcoding.

It looks like this:

#!/bin/bash

INPUT=$(yad --width=600 --height=400 --file-selection --file-filter='*.mp3 *.mp4 *.avi *.m4a *.ogg *.flac *.aac *.opus')

eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.*}-out.${INPUT##*.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT=\"%s\"\n", $1, $2, $3}')
[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1

DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))
OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))

ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy -map 0 "$OUTPUT"

So, install yad, save the script as cut_audio-video.sh and make it executable.

Than create the file ~/.local/share/applications/cut-audio-video.desktop similar to:

[Desktop Entry]
Name=Cut audio & video
Exec=/PATH/TO/cut_audio-video.sh
Icon=/SOME/AUDIO/ICON/Audio-icon.png
Terminal=false
Type=Application
Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;System;

Change Exec and Icon lines.

Then it can be run with an app launcher like Synapse:

enter image description here

Select the file, then enter the time for start and end of the cut/crop

enter image description here

1

Use this

enter image description here

I've written it to cut out ads from recorded TV videos. Using the included remuxer you do not even to have to recode it. There is nothing fancy about it. Just fast.

0

I wrote a helper for ffmpeg that mimics substr() syntax.

Usage

ffslice infile [start [duration [outfile [ffmpeg-args]]]]

Examples

# Get the last 5 minutes of an MP3
ffslice input.mp3 -5:00

# Get the first 30 seconds of a webm
ffslice input.webm 0 30

# Get 5 minutes of video starting at 2 minutes in
ffslice input.mp4 2:00 5:00

Code

#!/bin/bash
# substr() for MPEG-encoded files

infile="$1"; shift
start="$1"; shift
end="$1"; shift
outfile="$1"; shift
args=()

# Convert time to seconds
# https://unix.stackexchange.com/questions/412868/bash-reverse-an-array
timetosec() {
  rev="$(<<< "$1" tr ':' '\n' | sed 's/^0\+\([0-9]+\)/$1/' | tac | tr '\n' ' ')"
  IFS=' ' read -a times <<< "$rev"
  let secs="${times[0]:-0} + (${times[1]:-0} * 60) + (${times[2]:-0} * 3600)"
  printf '%i' "$secs"
}

# Input file requred
if [ -z "$infile" ]; then
  echo "Usage: $(basename -- "$0") infile [start [end [outfile [ffmpeg-args]]]]" >&2
  echo "Example: $(basename -- "$0") input.mp3 -5:00" >&2
  exit 1
fi

# Start (negative starts from the end)
if [ "${start:0:1}" = "-" ]; then args+=('-sseof' "$start")
elif [ -n "$start" ]; then args+=('-ss' "$start")
fi

# Input
args+=('-i' "$infile")

# End (use + or - to specify relative to the starting point)
if [ "${end:0:1}" = "+" ]; then args+=('-to' "$end")
elif [ "${end:0:1}" = "-" ]; then args+=('-sseof' "$end")
elif [ -n "$end" ]; then
  let dur="$(timetosec "$end") - $(timetosec "$start")"
  args+=('-to' "$dur")
fi

# Default output filename
filename=$(basename -- "$infile")
extension="${filename##*.}"
filename="${filename%.*}"
defaultOutfile="${filename}-${start}-${end}.${extension}"
if [ -z "$outfile" ]; then
  outfile="$defaultOutfile"
elif [ -d "$outfile" ]; then
  outfile="${outfile}/${defaultOutfile}"
fi

# Cannot have colon in the filename with ffmpeg
# https://unix.stackexchange.com/questions/412519/ffmpeg-protocol-not-found-for-normal-file-name
outfile="$(printf '%s' "$outfile" | sed 's/:/./g')"

# Slice audio
ffmpeg "${args[@]}" -c copy "$@" "$outfile" 1>&2

# Output the final location
printf '%s' "$(readlink -f "$outfile")"

Caveat

Note that ffmpeg will only split on keyframes. This usually works well enough for most cases, but if you need precise video segments, see How to extract time-accurate video segments with ffmpeg?. You can force all the needed keyframes before segmenting.

-1

I've struggled with this same issue, having a large video file that I want to cut and save as separate scenes. After trying to do this in the usual suspects all listed by others here I ended up using Kino.

You will have to import the file as Kino needs it in dv format (whatever that is) and you can then specify start and end point for each clip on the Edit tab, then export each clip individually on the Export tab. Works great and is fast, the slowest part is the initial import of the video file. You can even add effects like titles to each clip.

I found that it is hard to find the exact spot to cut the scene in Kino and when I play the vid in the built in player there is no sound (there is when exported) and it plays too fast so I play the video in avidemux, find the time or frame number where I want to cut it, then use this info in Kino.

I do find it crashes a fair bit (I use Ubuntu 15.04 Kino v1.3.4) but it will recover where you were upon restart.


Update on the Kino webpage:

Kino is a dead project
( 05.08.2013 14:15 )
Kino has not been actively maintained since 2009. We encourage you to try other Linux video editors such as Shotcut, Kdenlive, Flowblade, OpenShot, PiTiVi, LiVES, and LightWorks.

-1

I always use Kdenlive. Just import the video, drag it onto the timeline, click on the spot where you want to split it, right-click it, and choose cut. Then remove the part you don't need.

2
  • 1
    Thanks for the helpful suggestion, but for what I need they are too complex. Note that I didn't say too difficult to use, just unnecessarily bloated for my purposes. I ended up using openshot
    – jfoucher
    Aug 22, 2011 at 23:06
  • 1
    @jfoucher: you should accept Geppettvs's answer then ;)
    – Takkat
    Aug 23, 2011 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .