Skip to content

Instantly share code, notes, and snippets.

@L0rdCha0s
Last active July 12, 2024 13:04
Show Gist options
  • Save L0rdCha0s/2a3ad183ede4b5477149322cca907841 to your computer and use it in GitHub Desktop.
Save L0rdCha0s/2a3ad183ede4b5477149322cca907841 to your computer and use it in GitHub Desktop.
IFS=$'\n'
myUser=`whoami`
echo Local user is $myUser
SYNO_USER=`psql synofoto -t -c "select id from user_info where name='$myUser'"`
echo SYNO_USER is $SYNO_USER
echo Scanning for video files..
for i in `find . -iname \*.mov -type f | grep -v eaDir | grep -v "_3"`; do
#echo i is $i
fname=$(dirname ${i})/@eaDir/$(basename ${i})/SYNOPHOTO_FILM_H.mp4;
#echo Fname: $fname
foldername=$(dirname $i)
trimmedFolderName="${foldername#?}"
#echo Foldername: $foldername
filename=$(basename $i)
#echo Filename: $filename
#echo psql synofoto -t -c "select video.id from video join unit on unit.id = video.id where unit.id_folder = (select id from folder where name='$trimmedFolderName' and id_user=$SYNO_USER) and unit.filename='$filename'"
video_id=`psql synofoto -t -c "select video.id from video join unit on unit.id = video.id where unit.id_folder = (select id from folder where name='$trimmedFolderName' and id_user=$SYNO_USER) and unit.filename='$filename'"`
#echo Video ID: $video_id
video_convert_present=`psql synofoto -t -c "select id_unit from video_convert where id_unit=$video_id"`
if [ -z "$video_convert_present" ]; then
if [ -f $fname ]; then
echo \*\*\*\*\*\* Preview already exists \($fname\);
else
echo $fname does not exist, making video at $fname
/volume1/@appstore/CodecPack/bin/ffmpeg41 -i $i -c:v libx264 -b:v 12M -bufsize 1M -maxrate 12M -crf 18 -vf format=yuv420p -c:a copy $fname &> /dev/null
CONV_RES=$?
fi;
fileSize=`wc -c $fname | awk '{ print $1 }'`
if [ $fileSize -gt 0 ]; then
#Get duration
duration=`ffmpeg -i $fname 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'`
duration=$(( 1000*duration ))
echo Duration is $duration
#Get width and height...
dimensions=`ffmpeg -i $fname 2>&1 | grep Stream | grep Video | awk -F"," '{ print $3 }'`
width=`echo $dimensions | awk -F "x" '{ print $1 }'`
height=`echo $dimensions | awk -F "x" '{ print $2 }'`
echo Width: $width, Height: $height
#Now make psql entry...
echo Video ID in DB is: $video_id , inserting recording into database...
if [ -z $video_convert_present ]; then
echo "insert into video_convert(id_unit, duration, quality,video_info,audio_info) select $video_id, $duration, 'high', '{\"container_type\":\"mp4\",\"frame_bitrate\":7832773,\"frame_rate_den\":1,\"frame_rate_num\":30,\"orientation\":1,\"resolution_x\":$width,\"resolution_y\":$height,\"video_bitrate\":7726253,\"video_codec\":\"h264\",\"video_level\":31,\"video_profile\":3}', '{\"audio_bitrate\":126398,\"audio_codec\":\"aac_lc\",\"channel\":2,\"frequency\":44100}'" | psql synofoto
else
echo "Video convert record already exists.."
fi;
else
echo Could not convert video, bailing out for $filename ..
fi
else
echo Video already converted: $filename
fi
done
@isLaLa
Copy link

isLaLa commented Nov 6, 2022

Can you write a detailed operation tutorial, I won't use it, thank you

@alirz1
Copy link

alirz1 commented Nov 24, 2022

Does this still work on DSM 7.1.x ? I have quite a few copied over HEVC videos that dont show thumbnails in the Photos app. I think this is what i might need.
Question, does this convert the videos to another format or just helps the photos app process and create the thumbnails for HEVC files? Thanks

EDIT: should have read the code first before posting i guess. So looks like it is converting the vidos. Anyway of simply triggering photos to create thumbnails for hevc files instead?

@alirz1
Copy link

alirz1 commented Nov 28, 2022

Well ive done everything, even though the script runs, it doesnt seem to be doing anything, HEVC thumbnails are still not visible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment