Saturday, January 18, 2014

Sorting videos

Some time ago I posted my picture sorting script. Everything can record videos these days (e.g. the camera, the phone, and the resolution isn't even a joke any more, it's full HD at good frame rates) so sorting images is far from enough. I have been suffering with manual sorting, but the time for that is over.

There is a cool program called "mediainfo" that can decode the media information on everything I have tested it on. This made it quite easy to adapt the earlier program into a video sorter.  This one will sort the files arriving from all our different camera devices. If yours make files with a different name than .mp3 or .mov then change the "find" expression on the 10th line.



cd $ROOT/nye || exit $?
echo "*** Working on"

declare -a DATE

find . -iname '*.mp4' -o -iname '*.mov' | while read f; do
    # Adjust time of the file.
    # This date is in UTC, but touch understands that.
    UTCDATE="$( mediainfo --inform='Video;%Encoded_Date%' $f )"
    touch --date="$UTCDATE" $f

    # Depending on your location in the world the UTC time can be many
    # hours away from the local time and put the video surprisingly
    # into the wrong month.  But "ls" shows the local time.

    DATE=( $(ls --full-time $f | cut -d' ' -f 6 | tr '-' ' ' ) )

    mkdir -p $folder || exit $?
    mv -v "$f" $folder || exit $?

No comments: