Linux
哪個發行版允許您創建具有相同名稱的文件夾和文件?
我試圖弄清楚這個腳本(scene_splitter.sh)是為哪個發行版建構的。每次我嘗試使用它時,都會出現以下錯誤。
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 ==============================================================================
似乎它是為與允許文件夾和文件具有相同確切名稱的發行版一起使用而建構的,唯一的區別是一個文件夾和一個文件……假設發行版知道差異並因此允許它。
這是程式碼
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 "=============================================================================="
有誰知道如何編輯這個腳本,以便它不想創建一個與正在輸入的文件同名的目錄?
在任何 Linux 或 Unix 上創建一個與文件同名的目錄是不可能的(至少我知道。)
但這並不是腳本真正想要做的。
如果你仔細看,你會注意到它正在創建一個與輸入文件的基本名稱相同的目錄*,但在目前*目錄上。
看這部分:
bn="$(basename "$in")" # ... mkdir "./$bn"
因此,如果給定輸入文件
/path/to/movies/001.mp4
or../movies/001.mp4
,那麼它將嘗試創建與./001.mp4
輸入文件不同的目錄(假設您在/path/to/movies
我使用的範例之外的目錄中。)該腳本期望您從輸出目錄執行它,並且輸入文件位於與目前目錄不同的單獨目錄中。
例如,這種用法應該適合您:
x@x-pc:/media/x/WD_2TB_HDD/test$ mkdir output x@x-pc:/media/x/WD_2TB_HDD/test$ cd output x@x-pc:/media/x/WD_2TB_HDD/test/output$ ../scene_splitter.sh ../001.mp4
**更新:**如果您想修改腳本以避免名稱衝突,只需更改
bn
定義方式即可完成工作。例如,添加out-
前綴:bn="out-$(basename "$in")"