Open quiniouben opened 7 years ago
I have a similar request, I'd like to compress videos after upload.
Multiple qualities would be bonus, but allowing compression for storage reduction / faster loading would be great. How can this be implemented? My request:
To implement, one crude solution I can think of is:
/tmp
Will this work? Specifically:
I have a crude implementation using inotifywait
. Feedback or incorporation into the plugin would be appreciated :)
inotifywait
watcher script that converts when files are moved into
upload dir. Note that files initially are uploaded to a upload/buffer/
dir, and
from there moved into the repository named by year. By watching only the repository, we will
not trigger on moves being uploaded to upload/buffer/
. We only watch the current year as not
to overflow inotifywait
, hence this requires a reboot on January first :)
#!/bin/bash
WATCHDIR=/var/www/photos/upload/$(date +%Y)/
inotifywait --quiet -e MOVED_TO --monitor --recursive "${WATCHDIR}" | while read line do
echo "triggered " $line
params=($line)
thisfilepath="${params[0]}${params[2]}"
mime=$(file --brief --mime-type "${thisfilepath}")
# For any video, try to compress using ffmpeg. This might misfire in case of
# low-quality videos which are upscaled, but that's unlikely/impossible in my use case
if [[ "${mime}" =~ ^video/ ]]; then
echo "video triggered " $mime
# For this video, we need to:
# 1. Compress it: $file to ${thisfilepath}-x264_aac.mp4
# 2. Replace it without moving: cp ${thisfilepath}-x264_aac.mp4 $file && rm ${thisfilepath}-x264_aac.mp4
# which shouldn't trigger ourself
nice ffmpeg -hide_banner -nostdin -nostats -loglevel error -i "${thisfilepath}" -profile:v high -level 4.0 -pix_fmt yuv420p -c:v libx264 -preset slower -movflags use_metadata_tags -crf 28 -vf "scale='iw*min(1,sqrt(1280*720/ih/iw)):-2" -c:a aac -vbr 3 -threads 0 -y "${thisfilepath}-x264_aac.mp4"
cp "${thisfilepath}-x264_aac.mp4" "${thisfilepath}" && rm "${thisfilepath}-x264_aac.mp4"
echo "video conversion done"
fi
done
2. Start script on reboot using e.g. cron
```bash
sudo crontab -u www-data -e
@reboot /var/www/photos/videowatcher.sh
sudo su - www-data -s /bin/bash -c '/var/www/photos/videowatcher.sh'
sudo killall videowatcher.sh
Hello, thank you for your work. I use the web interface to upload videos (actually, I use a modified version of ReGalAndroid, allowing for video upload). This is an enhancement request: it would be perfect that lower quality versions of videos I upload are automatically generated (like piwigo does for still pictures). Some features of your plugin already require ffmpeg, with which it is quite easy to generate whatever format. I can understand that proposing fixed formats may not be acceptable or useful for all. Providing a hook possibility would be an useful option too. Thank you in advance for any feedback on this idea / request.