diff --git a/Dockerfile b/Dockerfile index f0dde00..eb09337 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM docker # Add bash, needed for our conversion script -RUN apk add --update bash util-linux && rm -rf /var/cache/apk/* +RUN apk add --update bash util-linux jq bc && rm -rf /var/cache/apk/* # Create folders RUN mkdir /var/videos && \ @@ -19,5 +19,6 @@ chmod +x /var/videoconversion/jq 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" +ENV VIDEO_FOLDER=/var/videos + +CMD bash ./var/videoconversion/convert.sh -c /var/videoconversion/config/video_formats.json -p /var/videos -f "docker run -v $VIDEO_FOLDER:/var/videos jrottenberg/ffmpeg:3.4-alpine" -i "docker run -v $VIDEO_FOLDER:/var/videos sjourdan/ffprobe" diff --git a/convert.sh b/convert.sh index afd55ea..7c99a9e 100755 --- a/convert.sh +++ b/convert.sh @@ -189,13 +189,13 @@ while true; do # Get the video width and height # Hack to get the height even if the audio and video stream are in reverse order - codec_type=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | ./jq --raw-output '.streams [0] .codec_type') + codec_type=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | jq --raw-output '.streams [0] .codec_type') if [ "$codec_type" = "video" ]; then - video_height=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | ./jq '.streams [0] .height') - video_width=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | ./jq '.streams [0] .width') + video_height=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | jq '.streams [0] .height') + video_width=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | jq '.streams [0] .width') else - video_height=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | ./jq '.streams [1] .height') - video_width=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | ./jq '.streams [1] .width') + video_height=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | jq '.streams [1] .height') + video_width=$($video_ffprobe_path -v quiet -show_streams -print_format json "$file" | jq '.streams [1] .width') fi # Calculate aspect ratio @@ -214,13 +214,15 @@ while true; do mkdir $file.out # Loop through all videoformats and convert them - for row in $(echo "${video_formats_file}" | ./jq -r '.[] | @base64'); do + for row in $(echo "${video_formats_file}" | jq -r '.[] | @base64'); do _jq() { - echo ${row} | base64 --decode | ./jq -r ${1} + echo ${row} | base64 -d | jq -r ${1} } # Check if the video is larger or as large as the format we want to convert it to - if [ "$(_jq '.height')" -le "$video_height" ] + format_new_height=$(_jq '.height') + + if [ "$format_new_height" -le "$video_height" ] then # Calculate the new width based on aspect ratio