Skip to content

Instantly share code, notes, and snippets.

@lukereding
Created October 18, 2017 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukereding/32ce36c996988bfafc024fb5f8bda3d1 to your computer and use it in GitHub Desktop.
Save lukereding/32ce36c996988bfafc024fb5f8bda3d1 to your computer and use it in GitHub Desktop.
example shell script
#!/usr/bin/env bash
# this script downloads an example animation from the internet and creates looped version of the animation that you could then use in a mate choice study
# the advantage of the script as opposed to doing this in something like iMovie:
### time. On my computer this script takes <30 seconds to execute. Doing this in iMovie could easily take half an hour.
### repeatability. I can send this script to you and you can make the video yourself.
### easy to remake videos when you make a mistake
### easy to keep track of what you've done. A plain text script like this allows you do _version control_ your work, allowing you to revert to a previous version and always know when you changed parts of your code
# make a directory to keep things tidy
mkdir create_video
cd create_video
# grab the animation from the web, renaming it to original_video.mp4
wget https://ndownloader.figshare.com/files/8804191 -O original_video
# make the video actually about to be viewed
ffmpeg -i original_video -vcodec libx264 original_video_corrected.mp4
# flip the video
ffmpeg -i original_video_corrected.mp4 -vcodec libx264 -vf "hflip,format=yuv420p" original_video_corrected_flipped.mp4
# combine the flipped and unflipped video
## ffmpeg wants a text file, one line for each video that you want concatenated
## it needs to look like this:
### file 'video1.mp4'
### file 'video2.mp4'
### ... [and so on]
echo "file 'original_video_corrected.mp4'" > list # creating text file called 'list'
echo "file 'original_video_corrected_flipped.mp4'" >> list # append another line to the text file
# make the concatenated video
# note that the input (-i) here is the name of the text file, list
ffmpeg -f concat -i list -vcodec copy concatenated.mp4
# get rid of the list
rm list
# loop the 'concatenated.mp4' video a bunch of times, then cut the resulting video file down to the correct length
# to loop the video, we'll concatenate the video to itself a bunch of times!
# here we write a for loop that makes it easy to create a text file that says `file 'concatenated.mp4'` a bunch of times
# this is the general form of a `for` loop in the shell; here we specify that we want 10 loops
for i in {1..20}; do printf "file '%s'\n" "concatenated.mp4" >> list; done
ffmpeg -f concat -i list output_long.mp4
# trim down to 5 min
ffmpeg -ss 00:00:00 -t 00:05:00 -i output_long.mp4 final.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment