Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

November 24, 2017

Basic Commandline Video Processing In Linux

video edit icon
Prerequisite: Install packages for MP4Box and ffpmpeg commands:
sudo apt install gpac ffmpeg

 

Three Methods to Trim Video:

  1. MP4Box -splitx ss:ss input.mp4 -out output.mp4 , where ss:ss are numerical values for start-seconds and stop-seconds. (Fastest, does not transcode)
  2. ffmpeg -i input.mp4 -ss hh:mm:ss -t hh:mm:ss -async 1 output.mp4, where hh:mm:ss are numerical values for hours, minutes, seconds.
  3. ffmpeg -i input.mp4 -vf trim=ss:ss output.mp4, where ss is a numerical value for seconds.
Annoyed with converting hours, minutes, seconds into total seconds? Use this bash function:
function to_sec() { echo "$1" | awk -F':' '{if (NF == 2) {print $1 * 60 + $2} else {print $1 * 60 * 60 + $2 * 60 + $3}}'; }
Usage examples: to_sec 2:47 or to_sec 1:2:47 or $(to_sec 2:47) or MP4Box -splitx $(to_sec 2:47):$(to_sec 7:33) input.mp4 -out output.mp4


 

Overlay a Logo onto Video:

    1. Static graphic logo:
ffmpeg -i input.mp4 \
-i logo.png \
-filter_complex "X:Y" \  # set logo position
-codec:a copy \  # just copy audio
output.mp4
where X:Y is the horizontal and vertical pixel positioning.
    2. Animated graphic logo:
ffmpeg -i input.mp4 \
-ignore_loop 0 -i animated-logo.gif \  # do not ignore looping
-filter_complex "X:Y:shortest=1" \  # limit to input video length
-codec:a copy \
output.mp4
where :shortest=1 is required, and where X:Y is the horizontal and vertical pixel positioning. Without shortest, the video transcoding will not end.
X and Y may be static numerical values, or ffmpeg built-in variables and equations. Examples:
  • Top right with 10 pixel margin : main_w-overlay_w-10:10
  • Top left with 10 pixel margin : 10:10
  • Bottom left with 10 pixel margin : 10:main_h-overlay_h-10
  • Bottom right with 10 pixel margin : main_w-overlay_w-10:main_h-overlay_h-10

 

 

Trim First x Seconds off Audio File:

ffmpeg -ss x -i input.mp3 -codec:a copy output.mp3 , where x is a numerical value for seconds.

 

Add Audio to Video and Trim to Shortest Source:

ffmpeg -i input.mp4 -i audio.mp3 -codec copy -shortest output.mp4

 

Overlay Logo and Add Audio with One Command:

ffmpeg -i input.mov \
 -i logo.png \
 -filter_complex "overlay=main_w-overlay_w-10:10" \
 -i music.mp3 -codec:a copy \
 -shortest output.mov
As always, good luck!
~~~
  

October 07, 2016

OpenShot 2.1 crashing on export in Debian 8 Jessie | ShotCut 16.10 for the Win

film-icon

edit: OpenShot 2.4.x works now, but i'm still a ShotCut fan using v18.x

EPIC FAIL | Story time…
 
OpenShot v2.1 is an opensource video editor that everyone is raving about. It was super easy to get a project going and i really liked the ease of use. But I’ll be damned if i could export any video without a crash.

All my research suggested i needed newer version of ffmpeg and mlt. However, every time i tried installing newer packages from jessie-backports, it just did not work with any useful explanation.
 
$ sudo aptitude -t jessie-backports install ffmpeg libmlt6
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.

It turns out there are commands that could help. Essentially you need to find package dependencies. Enter aptitude why <package-name> or alternatively apt-cache --installed rdepends <package-name> .

aptitude why ffmpeg ; aptitude why libmlt6 reported their dependencies. After a few runs and a few un-installs (sudo aptitude remove flowblade openshot kdelive) I was able to install newer ffmpeg and libmlt6 from jessie-backports. Afterward I was able to re-install the above-mentioned removed packages.

It was s good learning session, but as it turned out OpenShot still crashed for exports – each and every time. I’ve also installed every possible codec to no avail.

So I was back to re-testing alternatives:
- Lightworks was too confusing; I really wanted this to work, but i don’t have that kind of time for the learning-curve right now, although I hope to graduate to it.
- Blender was far beyond overkill. This is primarily for animation, but also does simpler video edits. I want something normal people can use. (Not that I’m claiming to be normal)
- I didn’t get very far with Kdenlive either. I think I didnt give it a real good go, but none-the-less I moved on.
- Avidemux was way too simple for this project, but is super good for quick chops.
- FlowBlade v1.8 almost did it, so close, but i never had enough frames for successful crossfades (disolves).
- ShotCut v16.10 won! It just worked, every time! – Crossfade and export worked for my first project without complaints nor crashes. Thank you ShotCut Team!

Please consider crypto tipping: