"vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Moderator: Forum moderators

User avatar
fredx181
Posts: 3037
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 367 times
Been thanked: 1290 times
Contact:

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by fredx181 »

vektor_alian wrote: Wed Jul 24, 2024 2:04 pm

Welp, using greengeek's program, I was not allowed to breach the 59 min 59 sec barrier for both the start and duration inputs. I refuse to attempt the 24 hour thing. Sorry.

Vektor

Perhaps I misunderstand what you mean, anyway it worked ok for me to extract 1 hour and 3 minutes (more than 59 min 59 sec, as you say) from a 1 hour 29 minutes video.

2024-07-24_18-08-43.png
2024-07-24_18-08-43.png (47.68 KiB) Viewed 1007 times
User avatar
mikewalsh
Moderator
Posts: 6136
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 784 times
Been thanked: 1966 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by mikewalsh »

@greengeek :-

Here's my 'take' on it....using a YAD-based GUI, and making use of the command I found over at StackOverflow. I accept what you were saying about short video source-clips; for that use-case, your premise of setting 'duration' for the extracted clip - and doing it in seconds - is perfectly understandable.

Image

Some of the video I'd like to be able to extract chunks out of can be anywhere up to nearly 3 hrs in length.....and I might want to extract 20 or 25 minutes at a go. For me, personally, I find it a lot easier to enter a start-time, a stop-time, and let ffmpeg chop out the section in between.....but that IS just me.

I confess, I've borrowed a few scraps of your code.....specifically in the extraction/trimming routine. Hope you don't mind; they look as though they probably use either 'sed' or 'awk', and I don't know a thing about either of those two....but they helped with naming the cut-out 'copy' correctly.

I've attached 'VideoTrimmer_noarch-portable' to the bottom of this post.....if anybody's feeling daft enough to risk it!

EDIT:- 'TRIM' script re-written to simplify it, and utility re-uploaded.

SEE:- viewtopic.php?t=12269 (25/07/24)

Mike. ;)

Attachments
VideoTrimmer_noarch-portable.tar.gz
Simple 'noarch' video-clip 'trimmer' making use of ffmpeg...
(73.99 KiB) Downloaded 31 times
User avatar
fredx181
Posts: 3037
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 367 times
Been thanked: 1290 times
Contact:

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by fredx181 »

@mikewalsh Wouldn't it be better to open a new thread, instead of here, for your take of the application ?
edit: line 26 in TRIM gives error, should be if [ ! -d "/mnt/sda3/SYSTEM/ffmpeg" ]
And putting double quotes around $FILESELECT will support also filenames with spaces.

User avatar
greengeek
Posts: 1383
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 531 times
Been thanked: 192 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by greengeek »

MochiMoppel wrote: Wed Jul 24, 2024 11:31 am

I assume that more than 86399 seconds are acceptable - at least to a maximum of the current "Epoch" time (seconds since 1970-01-01), i.e. 1721819912 seconds or more than 54 years. Would this be sufficient?

Haha, yes I think so... :D

User avatar
fredx181
Posts: 3037
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 367 times
Been thanked: 1290 times
Contact:

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by fredx181 »

greengeek wrote: Wed Jul 24, 2024 7:02 pm
MochiMoppel wrote: Wed Jul 24, 2024 11:31 am

I assume that more than 86399 seconds are acceptable - at least to a maximum of the current "Epoch" time (seconds since 1970-01-01), i.e. 1721819912 seconds or more than 54 years. Would this be sufficient?

Haha, yes I think so... :D

No. it's a limitation, I demand that the ffmpeg developers should "fix" ;) this terrible bug as soon as possible .
:lol: :lol:

User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by MochiMoppel »

fredx181 wrote: Wed Jul 24, 2024 7:22 pm
greengeek wrote: Wed Jul 24, 2024 7:02 pm
MochiMoppel wrote: Wed Jul 24, 2024 11:31 am

I assume that more than 86399 seconds are acceptable - at least to a maximum of the current "Epoch" time (seconds since 1970-01-01), i.e. 1721819912 seconds or more than 54 years. Would this be sufficient?

Haha, yes I think so... :D

No. it's a limitation, I demand that the ffmpeg developers should "fix" ;) this terrible bug as soon as possible .
:lol: :lol:

Bug? Which bug? I tested with 3153600000 seconds. That's 100 years, and ffmpeg is fine with it. :thumbup2:

User avatar
mikewalsh
Moderator
Posts: 6136
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 784 times
Been thanked: 1966 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by mikewalsh »

@fredx181 :-

I've done a bit of a re-write here. I have a pair of JvS's 'static' ffmpeg binaries residing permanently at that location - one 32-bit, one 64-bit - and originally I'd built the utility to make use of these via a check on 'uname' and a pair of auto-switcher scripts, but.......in all honesty, that's way over-complicated, and doesn't gel with the K.I.S.S principles I try to adhere to..! :o

So; I've decided from now on I'm simply going to link these into every Puppy manually. This simplifies the script greatly, because it only requires the one single command, calling ffmpeg from the usual location.....in the $PATH.

I've also added quotation marks to $FILESELECT in the command itself, a lá Mochi's recommendation. I'd already done this further up the script where the variables were defined, but then forgot to duplicate it in the actual command, so.....good catch!

(*D'ohh..!*) Image

Initially, I didn't envisage releasing this, 'cos I didn't want to "steal Ian's thunder"; I just meant to build it as an exercise. For his use case, using duration and doing it all in seconds makes perfect sense for short vids of just a few minutes in length.......but having mentioned further back in the thread that I, personally, found start AND stop times easier to work with (especially with big videos), I thought I'd have a go at it and see what I could come up with.

With a few 'adjustments', it seems to work okay.

EDIT:- From now on, this will have its own thread, so's it doesn't get "lost" as just a reply in someone else's thread. It can be found here:-

https://www.forum.puppylinux.com/viewtopic.php?t=12269

Mike. ;)

vektor_alian
Posts: 51
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 12 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by vektor_alian »

Welp, I am having too much fun.

Between greengeek and Mike I have mutilated the script even further.

Screenshot_20240725_114110.png
Screenshot_20240725_114110.png (27.32 KiB) Viewed 826 times

and placed vidxtractor-VIC-3.sh in my GDrive folder.

Here is the link again -- https://drive.google.com/drive/folders/ ... drive_link

Thanks to you two for the cool code.

Vektor

User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by MochiMoppel »

greengeek wrote: Sun Jul 21, 2024 6:59 am

3) Non-gui script : ****WARNING **** - this version cannot handle spaces in filenames unless you put quote marks around the filename.
Not for newbies. See MochiMoppels comments here

  • Place "vidextract" in your PATH (eg /usr/local/bin ) and run as follows:
  • in terminal type the following:
    vidextract /root/test.mp4 x y
    or (example with space in filename):
    vidextract "/root/test video.mp4" x y
    (where x= startseconds and y=durationseconds)

😱@greengeek You really try hard to scare people away :lol:
I don't know any command line tool where you don't have to quote filenames when they contain spaces, so why should your tool be an exception?
OK then, I played with your script and created a version that allows filenames with as many spaces, tabs or even newlines as you like. No quotation marks required. However this doesn't mean that you can forget about them. Even if the filename contains no spaces, it might contain characters that bash wants to interpret, e.g. a dollar sign or a semicolon. In such case it's still necessary to enclose the filename in single quotation marks.
The order of the arguments should now be x y filename, which makes the code easier and is also more common to have the filename as last argument.

I also share @mikewalsh 's concern about the duration syntax. My changes are intended to make both of you happy because now the user can input a duration in seconds or a stop value hh:mm:ss. The seconds and hh:mm:ss syntax can now be mixed in any possible way:

Code: Select all

vidextract 10 70 /root/foo bar.mp4              #skip 10sec and extract the following 70sec
vidextract 10 00:01:20 /root/foo bar.mp4        #skip 10sec and extract up to position 00:01:20
vidextract 00:00:10 00:01:20 /root/foo bar.mp4  #start at 00:00:10 and extract up to position 00:01:20

I made some other changes to your code and commented out your original code (comments preceded with #~) so that you can easily spot the changes. Mainly I

  • removed gxmessage dialogs. GUI dialogs have no place in a "Non-gui script", which should be functional even when X is not running. There is also no need for messages like "Extraction has begun" when ffmpg fills the user's screen with entertaining live coverage of the extraction.
  • Simplified some of your code. You seem to like the echo command. Not always needed, but don't worry, I recycled all of the ones I took away and gave them back to you the end of the script ;)

Code: Select all

#!/bin/sh

#vidextract : grab portion from video. greengeek 2024Jul21 Mochi:QuoteFilename
#Place in PATH to allow cli direct cropping of video file
## Forum: https://forum.puppylinux.com/viewtopic.php?t=12215

## Usage examples:
## vidextract 10 70 /root/foo bar.mp4				#skip 10sec and extract the following 70sec
## vidextract 10 00:01:20 /root/foo bar.mp4			#skip 10sec and extract up to position 00:01:20
## vidextract 00:00:10 00:01:20 /root/foo bar.mp4	#start at 00:00:10 and extract up to position 00:01:20

export TEXTDOMAIN=vidextract
export OUTPUT_CHARSET=UTF-8
#~ TMP="/tmp"
#~ STARTTIME=$(echo `date +%H-%M-%S`)
STARTTIME=$(date +%H-%M-%S)

#~ gxmessage "   Extraction has begun.
#~    For large files - wait patiently till the FINISHED message appears" &
#~ SOURCEVIDEO=$1
#~ STARTSECONDS=$2
#~ DURATIONSECONDS=$3
STARTSECONDS=$1
shift
DURATIONSECONDS=$1
shift
SOURCEVIDEO="$@"

# convert h:m:s format to seconds. Though ffmpeg accepts this format we may need seconds to calculate DURATIONSECONDS
[[ $STARTSECONDS    = *:* ]] && STARTSECONDS=$(date -d "70-1-1 $STARTSECONDS UTC" +%s)	#ex: 00:01:15 => 175
# when duration is passed in h:m:s format, convert to seconds. Assuming that in this case h:m:s means video position, subtract STARTSECONDS to produce duration in seconds
[[ $DURATIONSECONDS = *:* ]] && DURATIONSECONDS=$(( $(date -d "70-1-1 $DURATIONSECONDS UTC" +%s) - STARTSECONDS ))

#~ FILE="$SOURCEVIDEO"
#~ BASE=$(echo "${FILE%.*}")
#~ SUFFIX=$(echo "${FILE##*\.}")
BASE=${SOURCEVIDEO%.*}
SUFFIX=${SOURCEVIDEO##*.}

#Extraction syntax:
ffmpeg -ss $STARTSECONDS -i "$SOURCEVIDEO" -t $DURATIONSECONDS -vcodec copy -acodec copy "$BASE"_"$STARTTIME"."$SUFFIX"

RET=$?
#~ gxmessage "   Video cropping FINISHED. Look in same directory as source file.
#~    Please click OK to close."
echo ---------------------------------------------------
if ((RET)) ;then
	echo "Extraction failed"
else
	echo "Extracted video saved as ${BASE}_$STARTTIME.$SUFFIX"
fi
User avatar
greengeek
Posts: 1383
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 531 times
Been thanked: 192 times

Re: "vidxtractor" utility to save portion of mp4, mov, avi or flv video.

Post by greengeek »

MochiMoppel wrote: Fri Jul 26, 2024 6:45 am

I made some other changes to your code and commented out your original code (comments preceded with #~) so that you can easily spot the changes. Mainly I

  • removed gxmessage dialogs. GUI dialogs have no place in a "Non-gui script", which should be functional even when X is not running. There is also no need for messages like "Extraction has begun" when ffmpg fills the user's screen with entertaining live coverage of the extraction.
  • Simplified some of your code.

The order of the arguments should now be x y filename, which makes the code easier and is also more common to have the filename as last argument.

Many thanks MochiMoppel!
So much better than my first attempts.
So here is the new "cli only" version:
(Please note the different syntax order)

  • Place "vidextract" in your PATH (eg /usr/local/bin ) and run as follows:
  • in terminal type the following:
    vidextract x y /root/test.mp4
    or (example with space in filename):
    vidextract x y "/root/test video.mp4"
    (where x= start time and y=duration time)
    (see MochiMoppel's comments in post above mine re time format)

NOTE : This version replaces the "cli non-gui" script. Has no menu entry.

vidextract.false.gz
Remove .false.gz suffix, place in PATH, set exec permissions.
(1.61 KiB) Downloaded 26 times
Post Reply

Return to “Multimedia”