如何從文件名為 yyyy-MM-dd:HH:mm:ss 的圖像創建視頻

如何從文件名為 yyyy-MM-dd:HH:mm:ss 的圖像創建視頻

我有很多圖像 (>11.000),我想創建一個使用 avconv 作為時間間隔的影片。使用 ffmpeg 我做到了這一點:

ffmpeg -r 25 -i "/mnt/stora/dahopi/Pictures/Gartencam/%*.jpg" \
       -vf scale=800:600 -c:v mpeg4 -vtag xvid -qscale:v \
       10 gartencam.avi

但對 avconv 來說這是行不通的。我認為問題出在文件選擇器上%*.jpg,我想知道我是否有機會在不修改文件名的情況下創建影片。

如果沒有 - 你知道另一種工具可以做到這一點嗎?

答案1

恐怕您對文件選擇器導致的錯誤的看法是正確的。引用手冊:

      For creating a video from many images:

              avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi

      The syntax "foo-%03d.jpeg" specifies to use a decimal number composed of
      three digits padded with zeroes to express the sequence number. It is the
      same syntax supported by the C printf function, but only formats accepting a
      normal integer are suitable.

如果您願意,可以從大於 0 的整數開始:

  -start_number start
  Specify the first number in the sequence

您不需要真正重命名:您可以使用該ln命令創建符號鏈接,這將佔用您的磁碟空間很少。

我建議您在嘗試腳本之前先備份圖片

您可以嘗試使用這個 bash 腳本:

#! /bin/bash
INPUTDIR="$1"
OUPUTDIR="$2"

SORTEDLIST="$(cd "$INPUTDIR" && ls -1 | sort -n)"

COUNT="$(echo -e "$SORTEDLIST"|wc -l)"
echo "Found $COUNT files"

ZEROES="$(echo -e "$COUNT"|wc -c)" # (will count \n)
echo "Using $ZEROES characters to display integers"

COUNTER="0"
for file in $SORTEDLIST; do
    ID="$(printf "%0${ZEROES}d" "$COUNTER")"

    echo "ln -s $INPUTDIR/$file $OUPUTDIR/$ID.jpg"
    ln -s "$INPUTDIR/$file" "$OUPUTDIR/$ID.jpg"

    COUNTER=$((COUNTER + 1))
done

此腳本假定您的所有圖像都位於僅包含您想要包含在影片中的圖像的目錄中。使用方法:

  • 建立一個包含連結的輸出目錄:mkdir output
  • 執行它./script.sh nameofthefoldercontainingyourimages output

相關內容