Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 30 Aug 2015, 20:56
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Multimedia
GTK_Clipper and GTK_ClipAndCropper Video Tools
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
svanya

Joined: 29 Sep 2014
Posts: 13

PostPosted: Sat 22 Aug 2015, 04:11    Post subject:  GTK_Clipper and GTK_ClipAndCropper Video Tools
Subject description: Enabling the right-click on any video file and clip a/o cropping of it (via gtkdialog and ffmpeg)
 

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. Smile 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:

#! /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:

#! /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, 10:02; edited 1 time in total
Back to top
View user's profile Send private message 
jplt


Joined: 12 Nov 2010
Posts: 237
Location: Terre

PostPosted: Sat 22 Aug 2015, 06:30    Post subject:  

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

Code:
rxvt: unable to exec child.

_________________
Acer Aspire 5020ZG 2go RAM > Frugal Install Puppy Precise 5.7.1
Packard Bell 1go RAM > Triton 5.7.3,TahrPup 6.0
Back to top
View user's profile Send private message 
Semme

Joined: 07 Aug 2011
Posts: 5470
Location: World_Hub

PostPosted: Sat 22 Aug 2015, 07:03    Post subject:    

Looks like line 71:
Quote:
<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:
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..
Back to top
View user's profile Send private message 
jplt


Joined: 12 Nov 2010
Posts: 237
Location: Terre

PostPosted: Sat 22 Aug 2015, 07:39    Post subject:  

Great Semme it works

Code:
ffmeg -ss


work better.

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

_________________
Acer Aspire 5020ZG 2go RAM > Frugal Install Puppy Precise 5.7.1
Packard Bell 1go RAM > Triton 5.7.3,TahrPup 6.0
Back to top
View user's profile Send private message 
Semme

Joined: 07 Aug 2011
Posts: 5470
Location: World_Hub

PostPosted: Sat 22 Aug 2015, 07:52    Post subject:  

I'm outta time.. Destroy, return, exit(0).. Howdaya close this baby out?
Back to top
View user's profile Send private message 
svanya

Joined: 29 Sep 2014
Posts: 13

PostPosted: Sat 22 Aug 2015, 10:08    Post subject: Some corrections  

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, 10:29; edited 2 times in total
Back to top
View user's profile Send private message 
svanya

Joined: 29 Sep 2014
Posts: 13

PostPosted: Sat 22 Aug 2015, 10:20    Post subject: Getting time signatures  

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.
Back to top
View user's profile Send private message 
jplt


Joined: 12 Nov 2010
Posts: 237
Location: Terre

PostPosted: Sat 22 Aug 2015, 13:06    Post subject:  

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 !

_________________
Acer Aspire 5020ZG 2go RAM > Frugal Install Puppy Precise 5.7.1
Packard Bell 1go RAM > Triton 5.7.3,TahrPup 6.0
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Multimedia
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1160s ][ Queries: 11 (0.0164s) ][ GZIP on ]