Reducing video size with preserving metadata and timestamp


#1

In today, videos taken by smartphones takes too much space.

It is possible to decrease video size to %35 percent without loosing much quality.

To do this, you can use ffmpeg command. But after ffmpeg runs, you will lost metadata in newly created file and timestamps of the file also changed by the current time.

So, to keep metadata in newly created video as original source, we need to provide -map_metadata 0 option to ffmpeg command. After video conversion, an additional touch command must be run with referencing source video file as parameter.

Here is the quick script to convert all the files ending with *.mp4 in current working directory into another directory named CONVERTED while keeping video metadata and file timestamps:

for f in `ls *.mp4`; do 
	ffmpeg -i "$f" -map_metadata 0 -vcodec libx264 -crf 22 "CONVERTED/$f"
	touch -r "$f" "CONVERTED/$f" 
done

You can compare the results for the same video. If you want to decrease video size more, you can use crf value of 23 or 24. The magic crf (Constant Rate Factor) explained here: https://trac.ffmpeg.org/wiki/Encode/H.264