]> Frank Brehm's Git Trees - my-stuff/tools.git/commitdiff
Erst mal lauffähig
authorFrank Brehm <frank@brehm-online.com>
Sun, 23 Apr 2017 15:28:13 +0000 (17:28 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 23 Apr 2017 15:28:13 +0000 (17:28 +0200)
bin/convert_movie.sh

index 0e9b52567f12df5881181073c78fd6aef63ef54f..227b3385a68b9aff4c488aed0066f2231924abfd 100755 (executable)
@@ -30,6 +30,8 @@ TMP_MOVIE=""
 START_TIME=""
 END_TIME=""
 
+VIDEO_FILTER=""
+
 detect_color() {
 
     local safe_term="${TERM//[^[:alnum:]]/?}"
@@ -285,20 +287,24 @@ get_cmd_options() {
 
     if [[ -n "${GIVEN_SCALE}" ]] ; then
         GIVEN_SCALE=$(( ${GIVEN_SCALE} + 0 ))
-        if [[ "${GIVEN_SCALE}" -lt 80 ]] ; then
-            error "Die minimale Skalierung beträgt ${RED}80${NORMAL}."
-            echo
-            exit 1
-        fi
-        if [[ "${GIVEN_SCALE}" -gt 4000 ]] ; then
-            error "Die maximale Skalierung beträgt ${RED}4000${NORMAL}."
-            echo
-            exit 1
+        if [[ "${GIVEN_SCALE}" -eq 0 ]] ; then
+            SCALE=""
+        else
+            if [[ "${GIVEN_SCALE}" -lt 80 ]] ; then
+                error "Die minimale Skalierung beträgt ${RED}80${NORMAL}."
+                echo
+                exit 1
+            elif [[ "${GIVEN_SCALE}" -gt 4000 ]] ; then
+                error "Die maximale Skalierung beträgt ${RED}4000${NORMAL}."
+                echo
+                exit 1
+            fi
+            SCALE="${GIVEN_SCALE}:-3"
         fi
     else
         GIVEN_SCALE="800"
+        SCALE="${GIVEN_SCALE}:-3"
     fi
-    SCALE="${GIVEN_SCALE}:-3"
 
     if [[ -n "${BITRATE}" ]] ; then
         BITRATE=$(( ${BITRATE} + 0 ))
@@ -332,7 +338,29 @@ get_cmd_options() {
         fi
     fi
 
+    if [[ -n "${SCALE}" ]] ; then
+        VIDEO_FILTER="scale=${SCALE}"
+    fi
+
+    if [[ -n "${ROTATE}" ]] ; then
+        if [[ -z "${VIDEO_FILTER}" ]] ; then
+            VIDEO_FILTER="rotate=${ROTATE}"
+        else
+            VIDEO_FILTER="${VIDEO_FILTER},rotate=${ROTATE}"
+        fi
+    fi
+
+    if [[ -n "${VIDEO_FILTER}" ]] ; then
+        VIDEO_FILTER="-vf ${VIDEO_FILTER}"
+    fi
 
+    debug "Videofilter: '${VIDEO_FILTER}'"
+
+    if [[ "${SIMULATE}" = "y" ]] ; then
+        echo
+        warn "${YELLOW}Simulationsmodus${NORMAL} - es wird nichts wirklich gemacht."
+        echo
+    fi
 
 }
 
@@ -373,7 +401,99 @@ show_movie_info() {
 }
 
 #------------------------------------------------------------------------------
+cleanup() {
+
+    echo
+    info "Aufräumen ..."
+    trap - EXIT TERM HUP INT
+    remove -f divx2pass.log || true
+    remove -f frameno.avi || true
+    if [[ -n "${TMP_MOVIE}" ]] ; then
+        remove -f "${TMP_MOVIE}" || true
+    fi
+}
+
+#------------------------------------------------------------------------------
+preparing() {
+
+    echo
+    info "Vorbereitungen ..."
+
+    local workdir=$( dirname "${TGT_MOVIE}" )
+    TMP_MOVIE=$( mktemp --tmpdir="${workdir}" tmp.XXXXXXXX.avi )
+    debug "Temporäre Film-Datei: '${TMP_MOVIE}'."
+
+    trap cleanup EXIT TERM HUP INT
+
+}
+
+#------------------------------------------------------------------------------
+audio_converting() {
+
+    echo
+    echo "#-------------------------------------------------------------------"
+    info "Schritt 1: ${GREEN}Audio-Konvertierung${NORMAL}."
+    echo
+    sleep 1
+    local cmd="mencoder \"${SRC_MOVIE}\" -of avi -ovc frameno"
+    cmd+=" -oac mp3lame -lameopts vbr=3 -af volnorm=1"
+    if [[ -n "${VIDEO_FILTER}" ]] ; then
+        cmd+=" ${VIDEO_FILTER}"
+    fi
+    cmd+=" -o frameno.avi"
+
+    do_cmd "${cmd}"
+
+}
+
+#------------------------------------------------------------------------------
+video_converting1() {
+
+    echo
+    echo "#-------------------------------------------------------------------"
+    info "Schritt 2: Konvertiere Video-Stream zu XVID, ${GREEN}Schritt 1${NORMAL}."
+    echo
+    sleep 1
+    local cmd="mencoder \"${SRC_MOVIE}\" -of avi -o /dev/null"
+    cmd+=" -oac mp3lame -lameopts vbr=3 -af volnorm=1"
+    cmd+=" -ovc xvid -xvidencopts pass=1"
+    if [[ -n "${VIDEO_FILTER}" ]] ; then
+        cmd+=" ${VIDEO_FILTER}"
+    fi
+
+    do_cmd "${cmd}"
+
+}
+
+#------------------------------------------------------------------------------
+video_converting2() {
 
+    echo
+    echo "#-------------------------------------------------------------------"
+    info "Schritt 3: Konvertiere Video-Stream zu XVID, ${GREEN}Schritt 2${NORMAL}."
+    echo
+    sleep 1
+    local cmd="mencoder \"${SRC_MOVIE}\" -of avi -o \"${TGT_MOVIE}\""
+    cmd+=" -oac mp3lame -lameopts vbr=3 -af volnorm=1"
+    cmd+=" -ovc xvid -xvidencopts pass=2"
+    if [[ "${BITRATE}" -ne 0 ]] ; then
+        cmd+=":bitrate=${BITRATE}"
+    fi
+
+    local avi_info="comment=\"Creation date $(date +'%F %H-%M-%S %z')\""
+    if [[ -n "${TITLE}" ]] ; then
+        avi_info+=":name=\"${TITLE}\""
+    fi
+    cmd+=" -info ${avi_info}"
+    if [[ -n "${VIDEO_FILTER}" ]] ; then
+        cmd+=" ${VIDEO_FILTER}"
+    fi
+
+    do_cmd "${cmd}"
+
+}
+
+#------------------------------------------------------------------------------
 main() {
 
     get_cmd_options "$@"
@@ -409,6 +529,19 @@ main() {
 
     countdown
 
+    preparing
+    audio_converting
+    video_converting1
+    video_converting2
+    sleep 1
+
+    if [[ -f "${TGT_MOVIE}" ]] ; then
+        show_movie_info "${TGT_MOVIE}"
+    fi
+
+    cleanup
+    echo
+    info "Fertig."
 }
 
 main "$@"