]> git.rmz.io Git - dotfiles.git/commitdiff
add rename-video script
authorSamir Benmendil <samir.benmendil@gmail.com>
Tue, 20 Aug 2013 09:54:46 +0000 (11:54 +0200)
committerSamir Benmendil <samir.benmendil@gmail.com>
Fri, 23 Aug 2013 05:42:05 +0000 (07:42 +0200)
bin/rename-video.sh [new file with mode: 0755]

diff --git a/bin/rename-video.sh b/bin/rename-video.sh
new file mode 100755 (executable)
index 0000000..017179d
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+get_videoinfo() {
+    local -a mediainfo
+    IFS=,
+    mediainfo=( $(mediainfo --Output='Video;%Width%,%Height%,%ScanType%,%Format%,%Codec%' "$1") )
+    mediainfo=( $(ffprobe -select_streams v -show_entries stream=codec_name,width,height -of compact "$1" 2> /dev/null) )
+    local width=${mediainfo[0]}
+    local height=${mediainfo[1]}
+    local scan=${mediainfo[2]}
+    local format=${mediainfo[3]}
+    local codecid=${mediainfo[4]}
+
+    echo ${mediainfo[@]}
+    return
+
+    # same tests xbmc does:
+    # https://github.com/xbmc/xbmc/blob/master/xbmc/utils/StreamDetails.cpp#L514
+    if (( $width <= 720 && $height <= 480 )); then
+        resolution=480
+    elif (( $width <= 768 && $height <= 576)); then
+        resolution=576
+    elif (( $width <= 960 && $height <= 544)); then
+        resolution=540
+    elif (( $width <= 1280 && $height <= 720)); then
+        resolution=720
+    else
+        resolution=1080
+    fi
+
+    if [[ "$scan" == "Progressive" ]]; then
+        resolution+="p"
+    elif [[ "$scan" == "Interlaced" ]]; then
+        resolution+="i"
+    fi
+
+    vcodec=
+    if [[ "$format" == "AVC" ]]; then
+        vcodec=h264
+    elif [[ "$format" == "VC-1" && "$codecid" == "WVC1" ]]; then
+        vcodec=wvc1
+    elif [[ "$codecid" == "XVID" ]]; then
+        vcodec=xvid
+    elif [[ "$codecid" == "DIV3" || "$codecid" == "DX50" || "$codecid" == "DIVX" ]]; then
+        vcodec=divx
+    elif [[ "$codecid" == "V_MPEG2" ]]; then
+        vcodec=mpeg2
+    elif [[ "$codecid" == "MP42" ]]; then
+        vcodec=mp42
+    else
+        echo $f
+        echo $format $codecid
+    fi
+}
+
+#TODO
+get_audioinfo() {
+    local -a mediainfo
+    IFS=,
+    mediainfo=( $(mediainfo --Output='General;%Audio_Format_List%,%Audio_Language_List%,%AudioCount%' "$1") )
+    IFS=' / '
+    local format=( ${mediainfo[0]} )
+    local lang=( ${mediainfo[1]} )
+    local cnt=${mediainfo[2]}
+
+    audio=
+    local -i i=0
+    while (( $i < $cnt )) ; do
+        local iformat=${format[$i]}
+        local ilang=${lang[$i]}
+
+        acodec=
+        if [[ "$iformat" == "DTS" ]]; then
+            acodec=dts
+        elif [[ "$iformat" == "AC-3" ]]; then
+            acodec=ac3
+        elif [[ "$iformat" == "MPEG Audio" ]]; then
+            acodec=mp3
+        else
+    echo "$f"
+            echo "$iformat"
+        fi
+        alang=
+        if [[ "$ilang" == "English" ]]; then
+            alang=en
+        elif [[ "$ilang" == "German" ]]; then
+            alang=de
+        elif [[ "$ilang" == "French" ]]; then
+            alang=fr
+        else
+    echo "$f"
+            echo "$ilang"
+        fi
+        audio+="[${alang}]{${acodec}}"
+        i+=1
+    done
+}
+
+for f in "$@"; do
+    echo "$f"
+    get_videoinfo "$f"
+    #get_audioinfo "$f"
+#    echo "{$resolution}{$vcodec}$audio"
+done