什么发行版允许您创建具有相同名称的文件夹和文件?

什么发行版允许您创建具有相同名称的文件夹和文件?

我试图找出这个脚本(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 "=============================================================================="

有谁知道如何编辑此脚本,以便它不想创建与输入的文件名称完全相同的目录?

答案1

在任何 Linux 或 Unix 上创建与文件同名的目录实际上都是不可能的(至少据我所知)。

但这并不是剧本真正想要做的。

如果你仔细观察,你会发现它正在创建一个具有相同内容的目录基本名称输入文件的,但在当前的目录。

看这部分:

bn="$(basename "$in")"
# ...
mkdir "./$bn"

因此,如果给定输入文件/path/to/movies/001.mp4../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")"

相关内容