Command Line Video Editing Tools

Command line video editing tools

Avisynth under WINE is your best bet. You can use ffmpeg or mencoder to do the actual encoding, and avisynth .avs files for the actual editing. You may have to use mencoder under WINE to access the avs files as well. I haven't tried this myself, but it should work, barring any WINE issues.

If this is part of some production app, if there's any way you can farm the work out to an actual windows computer you'll save yourself a lot of pain.

If you want to get your hands dirty you could try using the gstreamer and Gnonlin to make your own CLI video app. You can actually use a language like Ruby to call gstreamer from, so you don't have to use C.

Command Line Video Tool for mosaic video output

AviSynth can join videos, hence you can change a video source at any time in the script.

For instance, in the following sample, the top left video of the four inputs will change to a different video after 6 seconds:

v11 = AviSource("SomeSampleVideo.avi", false). \
Crop(0, 0, 320, 240).AssumeFPS(25).ConvertToRGB32.Trim(0, 150).FadeOut(25, $FF0000)

v12 = AviSource("AnotherSampleVideo.avi", false). \
Crop(40, 10, 320, 240).AssumeFPS(25).ConvertToRGB32.FadeIn(25, $FF0000)

v1 = v11 + v12

v2 = ImageReader("SomeSampleBitmap.bmp").Crop(20, 10, 320, 240).ConvertToRGB32
v3 = AviSource("YetAnotherVideo.avi", false).Crop(30, 30, 320, 240).ConvertToRGB32
v4 = v1.Subtract(v2)

return StackVertical(StackHorizontal(v1, v2), StackHorizontal(v3, v4))


It is possible that I have misunderstood the requirements though..

Server side video mixing

I finally ended writing my solution from scratch, using ffmpeg library. It's a lot of boiler plate code but in the end the logic in not complicated.

I found the MLT framework which helped me greatly.

Server-side video editing

You can use gstreamer. It has bindings for many languages and easy to experiment with without actually writing code, using gst-launch and friends.
See this page for a few examples.

What is the recommended settings for video editing using ffmpeg?

Use a proxy

4k footage is often edited by using a smaller (1280x720 for example) proxy video. This allows the editor to be more responsive and less slow during the editing process. When the final edited video is exported the editing software will refer to the original 4k footage to create the output, so using a proxy does not reduce the quality of the final output.

Intra-frame H.264:

ffmpeg -i input.mp4 -vf "scale=-2:720,format=yuv420p" -c:v libx264 -crf 18 -preset fast -tune fastdecode -g 1 -c:a copy -movflags +faststart output.mp4

If you prefer ProRes:

ffmpeg -i input.mp4 -vf "scale=-2:720" -c:v prores_ks -profile:v proxy -c:a pcm_s16le output.mov

Refer to the documentation for your editor to see if this is an option for you.

Cutting the videos based on start and end time using ffmpeg

You probably do not have a keyframe at the 3 second mark. Because non-keyframes encode differences from other frames, they require all of the data starting with the previous keyframe.

With the mp4 container it is possible to cut at a non-keyframe without re-encoding using an edit list. In other words, if the closest keyframe before 3s is at 0s then it will copy the video starting at 0s and use an edit list to tell the player to start playing 3 seconds in.

If you are using the latest ffmpeg from git master it will do this using an edit list when invoked using the command that you provided. If this is not working for you then you are probably either using an older version of ffmpeg, or your player does not support edit lists. Some players will ignore the edit list and always play all of the media in the file from beginning to end.

If you want to cut precisely starting at a non-keyframe and want it to play starting at the desired point on a player that does not support edit lists, or want to ensure that the cut portion is not actually in the output file (for example if it contains confidential information), then you can do that by re-encoding so that there will be a keyframe precisely at the desired start time. Re-encoding is the default if you do not specify copy. For example:

ffmpeg -i movie.mp4 -ss 00:00:03 -t 00:00:08 -async 1 cut.mp4

When re-encoding you may also wish to include additional quality-related options or a particular AAC encoder. For details, see ffmpeg's x264 Encoding Guide for video and AAC Encoding Guide for audio.

Also, the -t option specifies a duration, not an end time. The above command will encode 8s of video starting at 3s. To start at 3s and end at 8s use -t 5. If you are using a current version of ffmpeg you can also replace -t with -to in the above command to end at the specified time.



Related Topics



Leave a reply



Submit