GTK_Clipper and GTK_ClipAndCropper Video Tools

Audio editors, music players, video players, burning software, etc.
Post Reply
Message
Author
svanya
Posts: 15
Joined: Mon 29 Sep 2014, 04:57

GTK_Clipper and GTK_ClipAndCropper Video Tools

#1 Post by svanya »

Update: The previous ("ffmpegS" version has been amended to ffmpeg". Aside: I had been using a static version of ffmpeg, hence writing it like that)

Hi, All.

I do (and have been doing) a lot of video editing (for YT) over the last few years and made some tools that have made my job a Whole lot easier: GTK_Clipper and GTK_ClipAndCropper.

I hope they make your life easier too.

The gist of it is you can right-click on any video file and clip a/o crop it. outputting the file (so named) to the directory of the original file.

note: GTK_Clipper uses the ffmpeg options "-vcodec copy" and "-acodec copy" so is very fast.
GTK_ClipAndCropper uses the ffmpeg "-filter:v 'crop'" option so must re-encode the video and thus does take a while.

Hope they work well for you.

And I normally don't make changes to the things I post. Because they are designed to do 1 or maybe 2 jobs, completely and entirely effectively and Nothing else. No bells, no whistles, and not even any air. :-) But will listen if you want to comment about possible improvements. Other than that, have at the code and hack/add/subtract until your heart's content.

[for those who do not know how to use gtk files: In a window, right-click>New>Shell Script. This will create a new shell script. Open the script in a text editor and copy and paste the code below into the script. Save. it is now a runnable shell script.]

NOTE: you will get an ffmpeg "Invalid duration specification for ss: -i" error if you run the script NOT as a right click. It takes the file parameter from the right-click action. Also, I have not put error handling code in here, leaving that for anyone interested in doing it. So unexpected entries will have unexpected results.

Well, here goes, THE INSTRUCTIONS: The code/gtk files are both at the bottom.

-----------------------------
-----------------------------

GTK_CLIPPER

Author: Scott Vanya
License: GPL3
Purpose: to enable the right-click and then clip of video files
Dependencies: newer version of ffmpeg and (I am using this one so don't know how it works on others) gtkdialog version 0.7.21
Where the options are as follows:
Start in xx:yy:zz.aa time format
End in xx:yy:zz.aa time format
Suffix A suffix (to add to the output filename), ex. "test1", "clip5" etc.
Setup:
Place the shell script (or better yet a link to it) in "Rox SendTo" Folders subfolders at "/root/.config/rox.sourceforge.net/SendTo":
.video_dv
.video_mp4
.video_mpeg
.video_ogg
.video_quicktime
.video_webm
.video_x-flv
.video_x-matroska
.video_x-msvideo
.video_x-ms-wmv
Then for any of those file types you can right click, enter your parameters, click ENTER.
A terminal will open in which ffmpeg will run and begin outputing the file with the following filename pattern:
original_filename from start_time to end_time.$extension

-----------------------------

GTK_ClipAndCropper

Author: Scott Vanya
License: GPL3
Purpose: to enable the right-click and then clip and cropping of video files
Dependencies: newer version of ffmpeg
Where the options are as follows:
Start in xx:yy:zz.aa time format
End in xx:yy:zz.aa time format
OffsetX X coordinate of top left corner as counted from top-left corner of the video
OffsetY Y coordinate of top left corner as counted from top-left corner of the video
Width width in pixels of the output file
Height height in pixels of the output file
Suffix A suffix (to add to the output filename), ex. "test1", "clip5" etc.
Setup:
Place the shell script (or better yet a link to it) in "Rox SendTo" Folders subfolders at "/root/.config/rox.sourceforge.net/SendTo":
.video_dv
.video_mp4
.video_mpeg
.video_ogg
.video_quicktime
.video_webm
.video_x-flv
.video_x-matroska
.video_x-msvideo
.video_x-ms-wmv
Then for any of those file types you can right click, enter your parameters, click ENTER.
A terminal will open in which ffmpeg will run and begin outputing the file with the following filename pattern:
$name $SUFFIX from xx_yy_zz.aa to ii_jj_kk.bb - X=OffsetX,Y=OffsetY,W=Width,H=Height.$extension"

GTK_CLIPPER

Code: Select all

#! /bin/bash
#Title:		GTK_Cipper
#Author: 		Scott Vanya
#License: 		GPL3
#Purpose: 		to enable the right-click and then clip  of video files
#Dependencies: newer version of ffmpeg
#Where the options are as follows:
#Start		in xx:yy:zz.aa time format
#End			in xx:yy:zz.aa time format
#Suffix		A suffix (to add to the output filename), ex. "test1", "clip5" etc.
#Setup:
#Place the shell script (or better yet a link to it) in "Rox SendTo" Folders subfolders at "/root/.config/rox.sourceforge.net/SendTo":
#.video_dv
#.video_mp4
#.video_mpeg
#.video_ogg
#.video_quicktime
#.video_webm
#.video_x-flv
#.video_x-matroska
#.video_x-msvideo
#.video_x-ms-wmv
#Then for any of those file types you can right click, enter your parameters, click ENTER. 
#A terminal will open in which ffmpeg will run and begin outputing the file with the following filename pattern:
#original_filename from start_time to end_time.$extension

export currentfile="$@"
export dir="$PWD"

extension="${@##*.}"
echo "$extension"
fbname=$(basename "$@" .$extension)
name0=$(echo "$fbname" | sed 's/:/ /g')
name=$(echo "$name0" | sed 's/,/ /g')
path=$(echo ${currentfile##*/})

export DIR=$(dirname "$currentfile")
export name="$name"
export extension="$extension"

export MAIN_DIALOG='
 <vbox>
  <frame Player>
  <text>
		<label>Clip this file...</label>
  </text>
	   <hbox>
        <text><label>Enter START time (xx:yy:zz format)</label></text>
      <entry accept="text">
        <variable>START</variable>
      </entry>
    </hbox>
	   <hbox>
        <text><label>Enter END time (xx:yy:zz format)</label></text>
      <entry accept="text">
        <variable>END</variable>
      </entry>
    </hbox>
	 <hbox>
		<text>
			<label>Enter title/suffix:</label>
		</text>
		<entry accept="text">
			<variable>SUFFIX</variable>
		</entry>
	 </hbox>
  </frame>
  <hbox>
		<button use-stock="true" label="gtk-ok">
			<variable>OKBUTTON</variable>
	<action>duration=`date1=$(date -d "$START" +"%s");date2=$(date -d "$END" +"%s"); echo $(($date2-$date1))`;rxvt -hold -e ffmpeg  -ss $START -i "$currentfile" -t "$duration" -vcodec copy -acodec copy "$DIR/$name from `echo $START | sed 's/:/_/g'` to `echo $END | sed 's/:/_/g'`-$SUFFIX.$extension"</action>
		</button>
		<button cancel></button>
  </hbox>
 </vbox>
'

gtkdialog --program=MAIN_DIALOG

GTK_CipAndCropper

Code: Select all

#! /bin/bash
#Title:		GTK_CipAndCropper
#Author: 		Scott Vanya
#License: 		GPL3
#Purpose: 		to enable the right-click and then clip and cropping of video files
#Dependencies: 	newer version of ffmpeg
#Where the options are as follows:
#Start		in xx:yy:zz.aa time format
#End			in xx:yy:zz.aa time format
#OffsetX		X coordinate of top left corner as counted from top-left corner of the video
#OffsetY		Y coordinate of top left corner as counted from top-left corner of the video
#Width		width in pixels of the output file
#Height		height in pixels of the output file
#Suffix		A suffix (to add to the output filename), ex. "test1", "clip5" etc.
#Setup:
#Place the shell script (or better yet a link to it) in "Rox SendTo" Folders subfolders at "/root/.config/rox.sourceforge.net/SendTo":
#.video_dv
#.video_mp4
#.video_mpeg
#.video_ogg
#.video_quicktime
#.video_webm
#.video_x-flv
#.video_x-matroska
#.video_x-msvideo
#.video_x-ms-wmv
#Then for any of those file types you can right click, enter your parameters, click ENTER. 
#A terminal will open in which ffmpeg will run and begin outputing the file with the following filename pattern:
#$name $SUFFIX from xx_yy_zz.aa to ii_jj_kk.bb - X=OffsetX,Y=OffsetY,W=Width,H=Height.$extension"

export currentfile="$@"
export dir="$PWD"

extension="${@##*.}"
echo "$extension"
fbname=$(basename "$@" .$extension)
name0=$(echo "$fbname" | sed 's/:/ /g')
name=$(echo "$name0" | sed 's/,/ /g')
path=$(echo ${currentfile##*/})

export DIR=$(dirname "$currentfile")
export name="$name"
export extension="$extension"

export MAIN_DIALOG='
 <vbox>
  <frame Player>
  <text>
		<label>Clip this file...</label>
  </text>
	   <hbox>
        <text><label>Enter START time (xx:yy:zz format)</label></text>
      <entry accept="text">
        <variable>START</variable>
      </entry>
    </hbox>
	   <hbox>
        <text><label>Enter END time (xx:yy:zz format)</label></text>
      <entry accept="text">
        <variable>END</variable>
      </entry>
    </hbox>
	<hbox>
		<vbox>
			<hbox>
				<text><label>Offset X</label></text>
				<entry accept="text">
					<variable>x</variable>
				</entry>
			</hbox>
		   <hbox>
				<text><label>Offset Y</label></text>
				<entry accept="text">
					<variable>y</variable>
				</entry>
			</hbox>
		</vbox>
		<vbox>
			<hbox>
				<text><label>Width</label></text>
				<entry accept="text">
					<variable>out_w</variable>
				</entry>
			</hbox>
			<hbox>
				<text><label>Height</label></text>
				<entry accept="text">
					<variable>out_h</variable>
				</entry>
			</hbox>
		</vbox>
	</hbox>
	 <hbox>
		<text>
			<label>Enter title/suffix:</label>
		</text>
		<entry accept="text">
			<variable>SUFFIX</variable>
		</entry>
	 </hbox>
  </frame>
  <hbox>
		<button use-stock="true" label="gtk-ok">
			<variable>OKBUTTON</variable>
	<action>duration=`date1=$(date -d "$START" +"%s");date2=$(date -d "$END" +"%s"); echo $(($date2-$date1))`;rxvt -hold -e ffmpeg -ss $START -i "$currentfile" -t "$duration" -crf 0 -filter:v "crop=$out_w:$out_h:$x:$y" -acodec copy "$DIR/$name $SUFFIX from `echo $START | sed 's/:/_/g'` to `echo $END | sed 's/:/_/g'` - X=$x,Y=$y,W=$out_w,H=$out_h.$extension"</action>
		</button>
		<button cancel></button>
  </hbox>
 </vbox>
'

gtkdialog --program=MAIN_DIALOG
Thanks! For checking this out. En/ex- and all around Puppy Joy![/b]
Last edited by svanya on Sat 22 Aug 2015, 14:02, edited 1 time in total.

jplt

#2 Post by jplt »

Hello i tried your first script gtk_clipper but i have this error :

Code: Select all

rxvt: unable to exec child.

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#3 Post by Semme »

Looks like line 71:
<action>duration=`date1=$(date -d "$START" +"%s");date2=$(date -d "$END" +"%s"); echo $(($date2-$date1))`;rxvt -hold -e ffmpeg -ss $START -i "$currentfile" -t "$duration" -vcodec copy -acodec copy "$DIR/$name from `echo $START | sed 's/:/_/g'` to `echo $END | sed 's/:/_/g'`-$SUFFIX.$extension"</action>
Can you see it? Two issues, and maybe three. It doesn't seem to exit after the clip..

Code: Select all

rxvt -hold -e ffmpegS  -ss
Svanya, good stuff! Could we have a simple time example from say, gnome-mplayer's timeline?

I've got a one minute video and want the 30 to 40 second span. How please..

jplt

#4 Post by jplt »

Great Semme it works

Code: Select all

ffmeg -ss
work better.

Another issue : the xterm window never close up but the cippled video is done !

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#5 Post by Semme »

I'm outta time.. Destroy, return, exit(0).. Howdaya close this baby out?

svanya
Posts: 15
Joined: Mon 29 Sep 2014, 04:57

Some corrections

#6 Post by svanya »

Hi, Folks. Thank you, so much for the feedback.

I have corrected the "ffmpegS" mistake and amended it to "ffmpeg" which is in fact the correct version.

As to keeping the terminal open if you do it in the background without running it as "xrvt -hold -e" what happens is you can not see the progress ffmpeg is making and this can be a huge problem. If it runs without the terminal I can't see the process running.

Also for debugging ffmpeg purposes, once it outputs the video and I look at the video if there are any issues I can go back (since there is no "exit 0") and see perhaps what caused the problem. Not so much of the program but perhaps of the values I entered or even some other issue, build parameters, libraries, codecs, etc. etc.

I clip/crop videos that are 3 hours long sometimes, and if the process runs away from me with an error I need to know. So if I close the terminal it will shut done the process.

Also something to note: you can halt and close properly an ffmpeg process by entering CTRL+C. This will Cleanly close the video so you can then view it. If you do not do that and just close the terminal, the video will not work and most likely will just be a gray screen tho it will play.

Hope that does not frustrate people

Those modifications I can see others amending and posting at will. Versions a,b,c etc.
Last edited by svanya on Sat 22 Aug 2015, 14:29, edited 2 times in total.

svanya
Posts: 15
Joined: Mon 29 Sep 2014, 04:57

Getting time signatures

#7 Post by svanya »

In mplayer if enter the character/slash key, literally the "o" key TWICE, it will bring up the OSD (don't know what that stands for) which should show the current time and the total time of the video.

In gnome-mplayer, the time signature is at the (on my set-up) bottom right hand corner of the window.

rem: enter the start and end times in 2-digit hour colon 2 digit minute colon 2 digit second and then decimal seconds if you will.

note: decimal seconds if you know your frame-rate will allow you to end on one particular frame.

One thing to keep in mind is ffmpeg clips on the down-side of a time signature (I am pretty sure). So if the video is 00:00:10.1 seconds long and you enter as the end time 00:00:10 it will lose the last 0.1 seconds. (Little help someone confirming that issue would be great.)

Also, it occurred to me, since the GTK_ClipAndChopper requires entering 00:00:00 and the total time to chop the whole video, folks may want a GTK_Chopper (that Chops the whole video, not just a portion).

If anyone speaks up, it is pretty rudimentary and someone else can go ahead and make it or let me know and I will do so under separate heading.

-peace

Thanks, again for helping with this. Cudos to jplt and Semme for pointing out the problem and solution to the "ffmpegS" bug.

jplt

#8 Post by jplt »

There is a way to close the xterm window when the job (cropping by ffmpeg) is done ?

Or maybe have a status bar with the pourcentage of work (croping job) left ?

Like FFconvert that use ffmpeg !

Post Reply