Welcome, Guest
Username Password: Remember me
  • Page:
  • 1

TOPIC: Lightworks stabilization using FFMEG script [HOW TO]

Lightworks stabilization using FFMEG script [HOW TO] 5 years ago #100707

  • variavision
  • Pro User
  • OFFLINE
  • Junior Boarder
  • Posts: 26
  • 5 years ago
BIG UPDATE: After few months I am finally able to upload the new scripts and the software to make them work directly from Lightworks.

Take a look here:
www.variavision.com/variavision/lightworks-linux-scripts/
variavision.crabdance.com/lightworks-linux-scripts/ (secondary link)


Hi guys, finnally I realized a script for Linux (all the distribution they can hanlde at least the latest FFMPEG).

PLEASE, KEEP IN MIND THAT:
- I tested on Ubuntu 14.04 (maybe it work well even on different version/distro, but it need some arrangement)
- Please, Please, Please and Please; always a good idea to make a backup of your files. I cannot take responsability of corruption/delete/something else about this script.
- This script is absolutely free and you can improve if you want, just remember to share it

BEFORE CONTINUE, VISIT THIS PAGE BE SURE THIS SCRIPT COULD WORK WELL AND THE NAME OF IT is video-stabilize LOCATED ON YOUR /usr/local/bin/

UPDATE NOTE 10th February 2016: Few bug fixes and added few preview steps. I also added an end script to create the final stab files into the original directory (where the original files is), in Prores HQ. Unfortunately I noticed few problems with LW12.6 when I am trying to "Replace media...". It crash in any case, even if I put it in again the same file. I will work on it, a workaround is to import and replace the clip in a new Track. Sorry about that.

UPDATE NOTE 18th November 2015: Now you can start multiple session of this script at the same time.

UPDATE NOTE 16th November 2015: I updated the script. Now it's able to work with multiple clips/tracks

UPDATE NOTE 11th November 2015: The whole script was made again from new, the new version use a graphical stabilizer made by Nicolas Barnaerts (see link above).

Keep in mind that:
- Before continue, please, check that the other script made by Nicolas work correctly, otherwise you could not use this one.
- The script was made completely on Ubuntu 14.04, so I cannot guarantee it can also work with different version/distros.
- I wrote a check at the start of the script that helps you to install the software needed for the extractions/stabilization.
- Any advice will be very welcome!

FIRST STEP

Copy the code below.

#!/bin/bash

# check Softwares
command -v HandBrakeCLI >/dev/null 2>&1 || { zenity --error --text="Please install Handbrake CLI"; exit 1; }
command -v cvlc >/dev/null 2>&1 || { zenity --error --text="Please install VLC"; exit 1; }

# check melt (ubuntu) or mlt-melt (fedora)
CMD_MELT="melt"
command -v $CMD_MELT >/dev/null 2>&1 || { CMD_MELT="mlt-melt"; }
command -v $CMD_MELT >/dev/null 2>&1 || { zeniaty --error --text="Please install Melt from MLT framework"; exit 1; }

# check yad, exiftool and x264
command -v yad >/dev/null 2>&1 || { zenity --error --text="Please install Yad"; exit 1; }
command -v exiftool >/dev/null 2>&1 || { zenity --error --text="Please install ExifTool"; exit 1; }
command -v x264 >/dev/null 2>&1 || { zenity --error --text="Please install x264"; exit 1; }

date +"%H-%S" > /tmp/temp_filename
TEMP_FILENAME=`cat /tmp/temp_filename`
cp $HOME/sources-list.txt /tmp/sources-list.txt.$TEMP_FILENAME
SOURCE=/tmp/sources-list.txt.$TEMP_FILENAME
sed '/Track/d' $SOURCE > $SOURCE.new
mv $SOURCE.new $SOURCE
#SOURCE_EXTRACT=`sed -n -s '1p' $SOURCE`

while [[ -s $SOURCE ]] ; do

	# SOURCES-LIST DATA EXTRACTION
	sed -n -s '1p' $SOURCE > /tmp/file-to-stab
	tail -n+2 $SOURCE > $SOURCE.new
	mv $SOURCE.new $SOURCE
	sleep 1s
	echo -n '"' > /tmp/video
	echo -n `egrep -o '^[^(]+' /tmp/file-to-stab` >> /tmp/video
	echo -n '"' >> /tmp/video
#	egrep -o '^[^(]+' /tmp/file-to-stab | sed "s/[[:blank:]]*$//" | awk '{gsub(/ /,"\ ")}8' > /tmp/video
	dirname "`cat /tmp/video`" | cut -c 2- > /tmp/video_location
	basename "`cat /tmp/video`" | sed 's/".*//' > /tmp/video_name
	basename "`cat /tmp/video`" | cut -d"." -f 1 > /tmp/video_basename

	# EXTRACT IN AND OUT
	sed 's/^.*Frames //g' /tmp/file-to-stab | cut -d"-" -f 1 > /tmp/in-frames
	sed 's/^.*-> //g' /tmp/file-to-stab | cut -d" " -f 1 > /tmp/out-frames
	expr `cat /tmp/out-frames` - `cat /tmp/in-frames` + 5 > /tmp/duration-stab
	
	WORKING_DIR=`cat /tmp/video_location`

#-------------------------->>> EXTRA PARAMETERS
WORKING_DIR=`cat /tmp/video_location`
FILENAME=`cat /tmp/video_name`
BASENAME=`cat /tmp/video_basename`
SAMPLE_VID="${BASENAME}".mpeg
IN_FRAME=`cat /tmp/in-frames`
OUT_FRAME=`cat /tmp/duration-stab`
FINAL_FILE="${BASENAME}"-"${IN_FRAME}""${OUT_FRAME}".mov
VIDEO_STABILIZE=/usr/local/bin/video-stabilize
#-------------------------->>>

	# CALCULATE SIZE
	cd "${WORKING_DIR}"
	exiftool "${FILENAME}" > /tmp/video-info
	grep "Image" /tmp/video-info | grep "Size" | sed 's/^.*: //g' | cut -d"x" -f 1 > /tmp/w-size
	grep "Image" /tmp/video-info | grep "Size" | sed 's/^.*x//g' > /tmp/h-size
	sleep 1s
#-------------------------->>> EXTRA PARAMETERS
	H_SIZE=`cat /tmp/w-size`
	W_SIZE=`cat /tmp/h-size`
#-------------------------->>>
	cd "${WORKING_DIR}"
	mkdir Temp

	#EXTRACTION SCRIPT
	zenity --info --timeout=5 --text "The frames extraction procedure begins. Please, wait..." &
	HandBrakeCLI -i "${FILENAME}" -o Temp/"${BASENAME}".mkv -e x264 -a none -q 0 --height $W_SIZE --width $H_SIZE --start-at frame:$IN_FRAME --stop-at frame:$OUT_FRAME -2
	ffmpeg -y -i Temp/"${BASENAME}".mkv -target pal-dvd Temp/"${SAMPLE_VID}"
	cvlc Temp/"${SAMPLE_VID}" 2> /dev/null &

	dialog --title "Extraction done" --clear --yesno "This is the right clip's portion?" 10 30

	case $? in
	  0)
		zenity --info --text "Now the video stabilizer will be opened. Please, in case a choice dialog shows up, select "${BASENAME}".mkv";;
	  1)
		zenity --error --text "Sorry that wasn't your file. Please, retry again. Restart the procedure clicking on LIST SOURCES in Lightworks, then start the script again" \
		&& rm -r Temp ; exit 0;;
	  255)
		zenity --error --text "Operation aborted!"; \
		exit 0 ;;
	esac

	#STABILIZE VIDEO
	cd "${WORKING_DIR}"
	$VIDEO_STABILIZE Temp/"${BASENAME}".mkv
	ffmpeg -y -i Temp/"${BASENAME}"-stab.mp4 -target pal-dvd Temp/"${SAMPLE_VID}" ; \
	cvlc -R --video-on-top Temp/"${SAMPLE_VID}" 2> /dev/null &
	zenity --info --timeout=5 --text "The video will repeat until you will close"

	dialog --title "Stabilization done" --clear --yesno "Do you want to change few settings and redo it?" 10 30

	case $? in
	  0)
		$VIDEO_STABILIZE Temp/"${BASENAME}".mkv ; \
		ffmpeg -y -i Temp/"${BASENAME}"-stab.mp4 -target pal-dvd Temp/"${SAMPLE_VID}" ; \
		cvlc -R --video-on-top "${SAMPLE_VID}" 2> /dev/null ; \
		ffmpeg -y -i Temp/"${BASENAME}"-stab.mp4 -vcodec prores -profile:v 3 -an "${FINAL_FILE}" ; \
		zenity --info --text "In case you need to redo it again, please; restart the procedure clicking on LIST SOURCES in Lightworks, then start the script again"; \
		exit 0 ;;
	  1)
		ffmpeg -y -i Temp/"${BASENAME}"-stab.mp4 -vcodec prores -profile:v 3 -an "${FINAL_FILE}"; \
		exit 0 ;;
	  255)
		zenity --error --text "Operation aborted!"; \
		exit 0 ;;
	esac

	zenity --info --text 	"The stabilized file is located in: "${WORKING_DIR}" "${FINAL_FILE}". Please, come back to Lightworks and REPLACE MEDIA with this one"
	
	#REMOVE TEMP FILES
	cd "${WORKING_DIR}"
	rm -r Temp
	killall vlc cvlv
	

done



This image is hidden for guests. Please log in or register to see it.


SECOND STEP
Open your terminal and copy this code:
sudo gedit /usr/local/bin/lightworks-stabilize
(1)
Paste the text you jost copied from the RED BOX (2)
On SOURCE (3) modify with your local HOME directory. Example: /home/{YOURUSERNAME}/sources-list.txt (this file will come out at step five)
ON OUT_FILE (4) just write whre you actually want the script will create the stabilized file. I advice you to keep it out of your project directory or where actually are your original footage. If you going to loose it, you can actually do it again.


Make the script executable, just copy this command on your terminal:
sudo chmod 775 /usr/local/bin/lightworks-stabilize


PLEASE NOTE: I am actually using "sudo" to give me the right to write as superuser. Ubuntu (and mostly Linux distro) use this system to avoid some dangerous situations and delete/modify system files, so be careful.

This image is hidden for guests. Please log in or register to see it.


THIRD STEP
Finally, open your Lightworks and try to add a clip.
Add an Effect to it (1) and when the dialog windows will come out, in the top of it (2 - the gears symbols to be clear), just click on "Assistant Applications (3)

This image is hidden for guests. Please log in or register to see it.


FOURTH STEP
Click on "Add" (1) and when the other dialog windows (2) will come out, just add these details (or what you actually want) to this new effect.
NAME: Stabilization
EXECUTABLE: gnome-terminal
OUTPUT DIRECTORY: What you wrote on OUT_FILE on the second step


Let's press DO IT.

* I am actually try to understand why Lightworks doesn't seem to recognize the script as executable. I am trying to do a simple software that start the terminal and the scritp at the same time... It could take a while *

This image is hidden for guests. Please log in or register to see it.


FIFTH STEP
Ok, so. Now you just add the EFFECT you just realized to your clip (1).
A windows will come out and just press the "List sources" (2); magically the sources-list.txt will create on your directory.

This image is hidden for guests. Please log in or register to see it.


SIXTH STEP
After it, just check on your Home directory the sources-list.txt fileis really created and it's contain informations about your:
- VIDEO LOCATION
- IN AND OUT FRAMES
These information will be extracted by the script.

if you didn't put the "gnome-terminal" on the executable field (step fourth), just open it and write the name you actually used on the second step; the one I gave you was: lightworks-stabilize, so if your didn't use something else, just execute this one.
If will not work, just be sure is executable. Check the second step

EIGHT STEP
Come back to Lightworks, click with the Right click mouse on the clip and "Replace with media..."

This image is hidden for guests. Please log in or register to see it.


Locate the file the script have just created and, it's DONE.

The software will pop up a dialog message where will be the name and location of the stabilized file.

This image is hidden for guests. Please log in or register to see it.


For any advice or questions please, do not hesitate to contact me!

Cheers
Last Edit: 3 years, 8 months ago by variavision.

Re: Lightworks stabilization using FFMEG script [HOW TO] 5 years ago #100712

  • asilnevs
  • Pro User
  • OFFLINE
  • Gold Boarder
  • Posts: 278
  • 5 years ago
If I have to stabilize a clip then I will use Shotcut (works on Windows, Mac and Linux) for this purpose.
I think the stabilization is done with MLT.
You can find a tutorial over here: www.shotcut.org/bin/view/Shotcut/Tutorials
But I'm looking forward to watch your video tutorial
Laptop: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz / System memory: 16GB / 64 bits / NVIDIA GeForce GTX1600 6GB / Samsung SSD 970 Evo M.2 1TB (PCIe 3.0 x4 NVMe) + Samsung SSD 850 Evo 500GB / OS: Ubuntu 18.04 LTS / Lightworks Pro 2020.1

Desktop: Intel(R) Core(TM) i7-4790K CPU @ 3.60GHz / System memory: 16GB / 64bits / Intel Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller / Intel Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller / Harddisks: SSD 128GB - HD 500GB - HD 2TB / OS: Ubuntu 18.04 / Lightworks Pro 2020.1

Re: Lightworks stabilization using FFMEG script [HOW TO] 5 years ago #100721

  • variavision
  • Pro User
  • OFFLINE
  • Junior Boarder
  • Posts: 26
  • 5 years ago
Thanks @asilnevs. I've used it for a while, even using directly the MLT by terminal. The only thing I wanted to do, was, make a script that use only the portion it's needed in automatically... so you do not have to do replacing things manually...

I will upload a video soon.

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 11 months ago #102539

  • karatedebili
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • 4 years, 11 months ago
so how does one actually use your script please? strangely enough, I can't even find a sources-list.txt file. thanks

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 11 months ago #102554

  • jwrl
  • Moderator
    Pro User
  • OFFLINE
  • Moderator
  • Posts: 12936
  • 4 years, 11 months ago
karatedebili wrote:
I can't even find a sources-list.txt file. thanks

You don't need one. All that you need to do is highlight the text in the code window (the pink window) and copy and paste it to an empty text file. That's it.

[EDIT] User variavision has since updated his tutorial to include a description of how to get it running as well. Ignore what I posted.
Last Edit: 4 years, 11 months ago by jwrl.

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 4 months ago #115553

  • donkpow
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 8993
  • 4 years, 4 months ago
Is this ready to be included in the list of assistant applications?
HP Z600 5570
PNY Quadro K620
SB Audigy SE
Windows 10 Pro
ShuttlePRO v2

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 4 months ago #115554

  • variavision
  • Pro User
  • OFFLINE
  • Junior Boarder
  • Posts: 26
  • 4 years, 4 months ago
I have made a simple C software that start a script selector... I will post it shortly with the updated scripts. Sorry about that...

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 4 months ago #115555

  • donkpow
  • Pro User
  • OFFLINE
  • Platinum Boarder
  • Posts: 8993
  • 4 years, 4 months ago
HP Z600 5570
PNY Quadro K620
SB Audigy SE
Windows 10 Pro
ShuttlePRO v2

Re: Lightworks stabilization using FFMEG script [HOW TO] 4 years, 4 months ago #115563

  • variavision
  • Pro User
  • OFFLINE
  • Junior Boarder
  • Posts: 26
  • 4 years, 4 months ago
Hi, I just made a webpage on my website with the instructions and the package.
www.variavision.com/lightworks-linux-scripts/
variavision.mooo.com/lightworks-linux-scripts/ (secondary link)

P.S. I hope to not break the law of the forum, linking an external website... In the case, admins, let me know how I could do it.
Last Edit: 4 years, 4 months ago by variavision.
  • Page:
  • 1
Time to create page: 0.46 seconds
Scroll To Top