I am trying to figure out which distro this script (scene_splitter.sh) was built for. Everytime I try to use it I get the following error.
x@x-pc:/media/x/WD_2TB_HDD/test$ ./scene_splitter.sh 001.mp4
==============================================================================
FILE START: 001.mp4
mkdir: cannot create directory ‘./001.mp4’: File exists
Finding Scene... this might take a while...
./scene_splitter.sh: line 12: ./001.mp4/ffout.tmp.txt: Not a directory
Filtering timestamp... this might take a while...
./scene_splitter.sh: line 15: ./001.mp4/timestamps.tmp.txt: Not a directory
grep: ./001.mp4/ffout.tmp.txt: Not a directory
./scene_splitter.sh: line 17: ./001.mp4/timestamps.tmp.txt: Not a directory
Found scenes
./scene_splitter.sh: line 31: ./001.mp4/timestamps.tmp.txt: Not a directory
---------------------------------------------------------------------------
LAST SCENE START:0/ (0,end)
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '001.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:04:17.77, start: 0.000000, bitrate: 4771 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 9:8 DAR 2:1], 4635 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
./001.mp4/001.mp4.(0 of ).mp4: Not a directory
LAST SCENE DONE:0/ (0,end)
---------------------------------------------------------------------------
FILE DONE: 001.mp4
==============================================================================
It seems it was built for using with a distro that allows a folder and a file to have the same exact name, only difference being one a folder and one a file... assuming that distro knows the difference and thus allows it.
Here is the code for scene_splitter.sh
#/bin/bash
start=0;
count=0;
in="$1"
bn="$(basename "$in")"
echo "=============================================================================="
echo "FILE START: $bn"
mkdir "./$bn"
echo "Finding Scene... this might take a while..."
ffmpeg -nostdin -i "$in" -filter:v "select='gt(scene,0.1)',showinfo" -f null - 2>"./$bn/ffout.tmp.txt"
echo "Filtering timestamp... this might take a while..."
grep showinfo "./$bn/ffout.tmp.txt" | grep pts_time:[0-9.]* -o | grep '[0-9]*\.[0-9]*' -o > "./$bn/timestamps.tmp.txt"
scenes=$(wc -l < "./$bn/timestamps.tmp.txt")
echo "Found $scenes scenes"
sleep 1
while IFS= read -r line; do
echo "---------------------------------------------------------------------------"
echo "SCENE START: $count/$scenes ($start,$line)"
ffmpeg -i "$in" -ss "$start" -to "$line" -nostdin -y -vcodec libx264 -acodec aac -g 120 -s 1280x720 -r 30 "./$bn/$bn.($count of $scenes).mp4"
echo "SCENE DONE:$count/$scenes ($start,$line)"
echo "---------------------------------------------------------------------------"
start=$line
count=$(($count+1))
sleep 1
done <"./$bn/timestamps.tmp.txt"
echo "---------------------------------------------------------------------------"
echo "LAST SCENE START:$count/$scenes ($start,end)"
ffmpeg -i "$in" -ss "$start" -nostdin -y -vcodec libx264 -acodec aac -g 120 -s 1280x720 -r 30 "./$bn/$bn.($count of $scenes).mp4"
echo "LAST SCENE DONE:$count/$scenes ($start,end)"
echo "---------------------------------------------------------------------------"
echo "FILE DONE: $bn"
echo "=============================================================================="
Does anyone know how to edit this script so that it doesn't want to create a directory with the exact same name as the file being inputted?