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 have a great little script that makes a new movie file from chopped up chunks of a list of movies, (thanks to help from this forum) except for two problems.
The problem is the first chopped portion always has a delay before playing, can be anything from 0.5 seconds to 4 or 5 seconds. I think this has something to do with key frames?
The second problem is although I select, say a 10 second length of each chopped out portion of movie, this can vary from chunk to chunk so they could be 4 seconds long or even 20 seconds long.
So I'm getting output for 60 seconds 100seconds into the movie and this is the output:
Code:
-rwxrwxrwx 1 charlie charlie 3.8M Jul 5 18:55 output000.mp4
-rwxrwxrwx 1 charlie charlie 827K Jul 5 18:55 output001.mp4
-rwxrwxrwx 1 charlie charlie 1.4M Jul 5 18:55 output002.mp4
-rwxrwxrwx 1 charlie charlie 1.4M Jul 5 18:55 output003.mp4
-rwxrwxrwx 1 charlie charlie 642K Jul 5 18:55 output004.mp4
-rwxrwxrwx 1 charlie charlie 904K Jul 5 18:55 output005.mp4
All looks good but you can see that the first cut is really large, the fifth cut is even small. And the first file is frozen for 3 seconds before playing.
I think I'm missing a parameter but cannot figure out what it is.
As I suspected this was due to not setting key frame, and after a lot of testing, trial and error and help from google I've come up with an ffmpeg command that can do this all in one.
It cuts, letterboxes, sets a key frame and then chops the cut part up into chunks of equal size and no freezing of the first chunk.
Explanation, I hace a script that prompts for a:
$STARTAT starting point eg 200 seconds
$FF a movie eg XXX.mp4
$CHOPLENGTH eg 15 seconds
$DURATION length of movie to chop into chunks eg 60 seconds
So this would result in 4 chunks of 15 seconds each from 200 seconds into the movie
pretty coll huh!
#1 that's still an improperly chopped and stringed mpeg. what you have now is a damaged mpeg movie. it's not a solution it's a hack.
mark it as solved then?
this forum is not for presenting code "you figured out" that others have not asked for
it is for asking others
Hi Thanks for that, I've marked this as UNSOLVED now because of your comment, so if anyone can solve it please feel free, hacks aren't allowed on this forum :-(
#1 that's still an improperly chopped and stringed mpeg. what you have now is a damaged mpeg movie. it's not a solution it's a hack.
mark it as solved then?
this forum is not for presenting code "you figured out" that others have not asked for
it is for asking others
Just for you X-LFS-2010, I've been doing more hacking and come up with a slightly modified version, this is all in a bash script that prompts for the input parameters, file names to process, like *.mp4, or *.*, the startpoint and duration in seconds, the chop size, the video bit rate and the letterbox size (note running in a letterbox means it can handle any aspect ratio of original, but ourputs a constant size video so they can be joined.
So step 1 is to cut, letter box, and flag the input files to .mp4 container
for movies in CHOPPED-*.ts
do mv -f "$movies" CHOPPED-$(shuf -i 100000-999999 -n 1).ts
done
Step 4 is to join the .ts files and re-encode to .mp4 containers
Code:
for i in {0..9}
do
ls CHOPPED-$i*.ts; ls CHOPPED-$i*.ts | perl -ne 'print "file $_"' | ffmpeg -y -f concat -i - -c copy -bsf:a aac_adtstoasc JOINED-$i.mp4
done
Seems to work, files playback correctly, but I need to do more extensive testing, so it's not solved yet!
Seems to work, files playback correctly, but I need to do more extensive testing, so it's not solved yet!
As I suspected my hack is still not 100% perfect, running 200 movie files through this process causes a few to have a really long duration when it hasn't. Not sure which file causes and why so I'm going to keep the .ts files and find the rogue ones and either delete them of analyse the original movie to see why its wrong and either fix or skip it.
keyframes and groups of pictures. You would probably need to re-encode the whole video with iframes (everyframe is a keyframe), then chunk that out. Or other such trickery. In either case, to break it up mid group-of-pictures will require re-encoding the video. Which is an imperfect copy with compression and artifacts. The file sizes differ because the movement differs, as lots of movement does not compress well.
keyframes and groups of pictures. You would probably need to re-encode the whole video with iframes (everyframe is a keyframe), then chunk that out. Or other such trickery. In either case, to break it up mid group-of-pictures will require re-encoding the video. Which is an imperfect copy with compression and artifacts. The file sizes differ because the movement differs, as lots of movement does not compress well.
Absolutely correct, I've finally figured how to put it all together to letterbox, add keyframes, and set the audio, video and frame rates, cut a segment from the main video and then cop it up into equal length chunks, all in one neat ffmpeg command line and this is it (note all parameters are prompted for and are self explanatory):
This is done in a loop through many videos, where FF is the video name eg zxc.mp4, or zxc.wmv and so on
Then the script renames the videos to a six digit random number so that when joined up again it's a new movie of chunks in random order, like the shuffle effect on a cd-player.
Here is where I just could not get an "ffmpeg concat" script to work, so I resorted to mmcat.sh which can be found here: https://trac.ffmpeg.org/wiki/mmcat
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.