Rotation

With a time lapse video in the winter and in the summer, I could cover the whole northern sky: When it’s getting bright in one of the videos, it starts to get dark in the other one. Probably best to watch fullscreen:

Winter night sky time lapse. For full screen: https://youtu.be/SqYlLvelal8 (unfortunately, dew on the lens made the stars less visible)
Summer night sky time lapse. For full screen: https://youtu.be/qDIjs-YaC5Q

The reason behind is between the two videos, the earth has done half a round around the sun and so at midnight, when looking at Polaris, one looks from opposite directions.

Video modification for time lapse videos

6 Feb 2022 – Ronny Errmann – last modified on 31 March 2022

Some useful bits which helped me to make the time lapse videos I recorded ready to be published on youtube: Youtube Channel Ronny Errmann

Rotate an mp4 video:

For when the phone was upside down during the recording.

ffmpeg -i input.mp4 -c copy -metadata:s:v rotate="180" output.mp4

Crop an mp4 video:

When personal information is in an area of the video.

1. Get the video resolution:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4

2. Modify the video:

ffmpeg -i input.mp4 -filter:v "crop=1280:600:0:120" output.mp4

Cut an mp4 video:

To keep 00:00:00 to 00:01:22, because afterwards only night was recorded as work had to be finished first.

ffmpeg -i input.mp4 -ss 00:00:00 -to 00:01:22 -c copy output.mp4

Merge/concatenate mp4 videos:

When you notice at the end of a time lapse that the sky is still amazing and you recorded a second one.

Version 1 with the concat protocoll (https://trac.ffmpeg.org/wiki/Concatenate)

Several lines of shell script, run with sh:

for f in $(ls input*.mp4); do
ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts
done
CONCAT=$(echo $(ls *.ts) | sed -e "s/ /|/g")
ffmpeg -i "concat:$CONCAT" -c copy -bsf:a aac_adtstoasc output.mp4
rm *.ts

Use Version 2 if this fails with:

Codec 'mpeg4' (12) is not supported by the bitstream filter 'h264_mp4toannexb'

Version 2 with the concat demuxer (https://trac.ffmpeg.org/wiki/Concatenate)

rm -f mylist.txt; for f in input*.mp4; do echo "file '$f'" >> mylist.txt; done
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
rm mylist.txt

Change the speed of mp4 videos:

You took a time lapse, but the viewers are bored, because changes are too small. Time to speed the video up.

ffmpeg -i input.mp4 -r 16 -filter:v "setpts=0.50*PTS" output.mp4

0.5*PTS mean twice the speed, 0.1*PTS would mean ten times the speed, and 2*PTS would mean half the speed; -r 16 means a frame rate of 16 fps (frames per second).

Change of resolution of mp4 videos:

ffmpeg -y -i input.mp4 -vf scale=480:-2,setsar=1:1 -c:v libx264 -c:a copy output.mp4

The 480 gives the horizontal resultion and the heigh is calculated by keeping the same aspect ratio.

Extract images from mp4 videos:

ffmpeg -i input.mp4 out-%05d.jpg

With above settings the output files will be of format out-12345.jpg. To get slightly better image quality png can be used instead of jpg. Images will require much more space than the video (about 10 times). Different commands can also be combined, e.g. to get only frames for a 8 second stretch:

ffmpeg -i input.mp4 -ss 00:00:27 -to 00:00:35 out-%03d.png

(I couldn’t get it to work to only get every x-th frame in the same command line)

Batch convert audio files to mp3

The line below will convert wav audio files to mp3s using 44.1 kHz sampling frequency, 2 audio channels, 192 kilobit per second bitrate. -vn makes sure no video is used

for ffile in *.wav; do ffmpeg -i "$ffile" -vn -ar 44100 -ac 2 -b:a 192k "${ffile%.wav}".mp3; done

Input can be any audio type (wma, mp3,…).