Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I know how to use getopts to get input to my bash script, and I know how to write a loop.
What I want to do is to prompt for a start and end points to cut from a video file, and then to build up an ffmpeg command to process the file (I know how to do that).
So it will prompt for
file name - just once - no problem here
then it should prompt for
Start
End
repeat this till it gets an E for Execute
Then I know how to write loop using a count on the number of start /end pairs read.
Quedtion how do I store the start/end pairs, in an array or a list, or some other way?
Basically what ever is easiest for you. Can you build up the command as you prompt for start/end? Then if necessary just concatenate the strings together.
If so then the added complexity of using an array is not required.
I should add that the script does not do any validation other than the existance of the input file. It should check the start point is less than the end point, it should check it's not overwriting a file on output, and maybe it should let you input the start and end points in hh:mm:ss.s format, at the moment it expects seconds - I think.
On modern ffmpeg versions I think one should use the '-ss' and '-t' options, along with '-c:a copy -c:v copy' to avoid re-encoding.
I do that when I just want one clip, I'll try it doing multiple clips. And yes I know I could clip the pieces I want to keep in a nuber if ffmpeg runs and then joining them with another ffmpeg command, followed by deleting the clips.
I really want to do this with a single ffmpeg command.
And in some instances my input file is a .mts file (video recorded on a cheap chinese set top box) and I do want to re-encoe it to .mp4.
I really want to do this with a single ffmpeg command.
I understand.
But avoiding re-encoding is the more important thing here IMO. Snipping together bits from one video file should not require that.
I do not know whether your command does that or not; I suspect your "filter_complex" option does re-encode. Quick test: How long does it take (on a fairly recent consumer device), for a few minutes of video?
I understand.
But avoiding re-encoding is the more important thing here IMO. Snipping together bits from one video file should not require that.
I do not know whether your command does that or not; I suspect your "filter_complex" option does re-encode. Quick test: How long does it take (on a fairly recent consumer device), for a few minutes of video?
I need to re-encode from .mts to .mp4, and yes it does in fact re-encode
I'll do a test of .mp4 to .mp4 and report back - cheers
This is the problem - the - gets dropped from -s 512x288 on the ffmpeg command but you can see it's there when I echo it before executing the ffmpeg command
Terminal output:
Code:
charlie@charlie-machine:~/000TEST/Cutting$ ./CutOutBits.sh
Movie To cut up: beach.mp4
Output filename example.mp4: rtyu.mp4
start cut (h:mm:ss) - (e to finish) : 0:0:10
end cut (h:mm:ss): 0:0:50
1 10 50
start cut (h:mm:ss) - (e to finish) : e
Now get on with the script again
SIZE: -s 512x288
==========
ffmpeg messages follow and removed
Unrecognized option 's 512x288'.
Error splitting the argument list: Option not found
charlie@charlie-machine:~/000TEST/Cutting$
And you can see in the script I save the command to a file which is this and you can see $SIZE has been expanded correctly i.e. -s 512x288
I can paste the above code into a terminal and works just fine, no reason why it shouldn't.
Whats causing the SIZE variable to expand incorrectly? How can i preserve the minus sign?
Breaking news - a workround - of sorts
I removed the -s from the variable so SIZE only has WxH, and the -s is in command line now -s $SIZE
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.