fixed various bugs needed to run the script inside a docker container
This commit is contained in:
parent
e9c5b45fc1
commit
bb68448658
24
Dockerfile
24
Dockerfile
|
@ -1,5 +1,23 @@
|
||||||
FROM docker
|
FROM docker
|
||||||
RUN mkdir /var/videos
|
|
||||||
WORKDIR /var/videos
|
# Add bash, needed for our conversion script
|
||||||
ADD convert.sh
|
RUN apk add --update bash util-linux && rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# Create folders
|
||||||
|
RUN mkdir /var/videos && \
|
||||||
|
mkdir -p /var/videoconversion/config
|
||||||
|
|
||||||
|
# Add the actual script
|
||||||
|
COPY convert.sh /var/videoconversion/
|
||||||
|
COPY jq /var/videoconversion/
|
||||||
|
COPY video_formats.json /var/videoconversion/config/
|
||||||
|
|
||||||
|
RUN chmod +x /var/videoconversion/convert.sh && \
|
||||||
|
chmod +x /var/videoconversion/jq
|
||||||
|
|
||||||
|
# Volumes
|
||||||
VOLUME /var/videos
|
VOLUME /var/videos
|
||||||
|
VOLUME /var/videoconversion/config
|
||||||
|
|
||||||
|
#ENTRYPOINT while true; do sleep 1d; done
|
||||||
|
ENTRYPOINT ./var/videoconversion/convert.sh -c /var/videoconversion/config/video_formats.json -p /var/videos -f "docker run -v /var/videos:/var/videos jrottenberg/ffmpeg:alpine-3.3"
|
||||||
|
|
29
convert.sh
29
convert.sh
|
@ -1,17 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# the function "round()" was taken from
|
|
||||||
# http://stempell.com/2009/08/rechnen-in-bash/
|
|
||||||
|
|
||||||
# the round function:
|
|
||||||
round()
|
|
||||||
{
|
|
||||||
echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
|
|
||||||
};
|
|
||||||
|
|
||||||
calc() { awk "BEGIN{print $*}"; }
|
|
||||||
|
|
||||||
|
|
||||||
########
|
########
|
||||||
# Init Variables
|
# Init Variables
|
||||||
# Available Environment Variables:
|
# Available Environment Variables:
|
||||||
|
@ -54,7 +42,7 @@ fi
|
||||||
# Passed Options, any passed option will overwrite a previously set environment variable
|
# Passed Options, any passed option will overwrite a previously set environment variable
|
||||||
########
|
########
|
||||||
|
|
||||||
while getopts ":c:p:v:p:h" opt; do
|
while getopts ":c:p:v:f:h" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
c)
|
c)
|
||||||
video_formats_location=$OPTARG
|
video_formats_location=$OPTARG
|
||||||
|
@ -123,7 +111,7 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Default ffmpeg path
|
# Default ffmpeg path
|
||||||
if [ -z $video_ffmpeg_path ]
|
if [ -z "$video_ffmpeg_path" ]
|
||||||
then
|
then
|
||||||
video_ffmpeg_path=ffmpeg
|
video_ffmpeg_path=ffmpeg
|
||||||
fi
|
fi
|
||||||
|
@ -156,18 +144,25 @@ video_formats_file=$(<$video_formats_location)
|
||||||
########
|
########
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
# Remove Spaces in filename (because bash doesn't like them and would throw an error)
|
# Remove Spaces in filename (because bash doesn't like them and would throw an error)
|
||||||
rename 's/ /_/g' *
|
for f in $video_location/*; do
|
||||||
|
mv "$f" `echo $f | tr ' ' '_'` 2>/dev/null
|
||||||
|
done
|
||||||
|
|
||||||
# loop through all files
|
# loop through all files
|
||||||
for file in $video_location/*; do
|
for file in $video_location/*; do
|
||||||
|
|
||||||
|
# Remove Spaces in filename (because bash doesn't like them and would throw an error)
|
||||||
|
#mv "$file" `echo $file | tr ' ' '_'` 2>/dev/null
|
||||||
|
|
||||||
# Check if the current file is a video
|
# Check if the current file is a video
|
||||||
file_format=${file: -4}
|
file_format=${file: -4}
|
||||||
if [ "${video_formats_string/$file_format}" != "$video_formats_string" ]
|
if [ "${video_formats_string/$file_format}" != "$video_formats_string" ]
|
||||||
then
|
then
|
||||||
|
|
||||||
# If it is a videofile, if no "locker" already exists, create one and start converting
|
# If it is a videofile, if no "locker" already exists, create one and start converting
|
||||||
if [ ! -f $file.lock ]
|
if [[ ! -f $file.lock ]]
|
||||||
then
|
then
|
||||||
|
|
||||||
# Tell the User what we're doing
|
# Tell the User what we're doing
|
||||||
|
|
Loading…
Reference in New Issue