Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A How can I efficiently create a collage of video thumbnails on Linux?

bash does not support floating point operations, so at least for a short video $interval will always be 0. That way you always get the same frame, which by chance probably was black for your video....

posted 1mo ago by GeraldS‭  ·  edited 1mo ago by GeraldS‭

Answer
#2: Post edited by user avatar GeraldS‭ · 2024-10-08T11:47:20Z (about 1 month ago)
  • bash does not support floating point operations, so at least for a short video `$interval` will always be `0`. That way you always get the same frame, which by chance probably was black for your video.
  • You notice that if you place an `echo` in front of your `ffmpeg` call to check the actual command. This resulted in this output for me:
  • ```
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame0.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame1.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame2.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame3.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame4.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame5.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame6.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame7.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame8.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame9.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame10.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame11.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame12.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame13.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame14.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame15.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame16.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame17.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame18.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame19.jpg
  • ```
  • As you can see, `-ss` is always `0`.
  • You can use for example [`bc`](https://linux.die.net/man/1/bc) to do the calculations (it's possible that you need to install it):
  • ```shell
  • interval=$(echo "$duration / 20" | bc)
  • ```
  • Afterwards the rest of your script mostly worked for me.
  • ![Output image of the script, a 5x4 grid of video images](https://linux.codidact.com/uploads/zqf5my353fnvcnm8mwgsxyo9ujgb)
  • More optimizations:
  • ```shell
  • for i in {0..19}; do
  • ffmpeg -ss $((interval * i)) -i "$1" -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 "${1%.*}_frame$i.jpg"
  • done
  • ```
  • - By using `0..19` instead of `1..20` you can clean up the calculations for the wanted second.
  • - `-frames:v 1` removes an error message
  • - `-loglevel 0` removes unnecessary clutter
  • ```shell
  • rm "${1%.*}"_frame*.jpg
  • ```
  • fixes the non working removal of the temporary images.
  • bash does not support floating point operations, so at least for a short video `$interval` will always be `0`. That way you always get the same frame, which by chance probably was black for your video.
  • You notice that if you place an `echo` in front of your `ffmpeg` call to check the actual command. This resulted in this output for me:
  • ```
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame0.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame1.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame2.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame3.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame4.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame5.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame6.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame7.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame8.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame9.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame10.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame11.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame12.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame13.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame14.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame15.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame16.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame17.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame18.jpg
  • ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 Example_frame19.jpg
  • ```
  • As you can see, `-ss` is always `0`.
  • You can use for example [`bc`](https://linux.die.net/man/1/bc) to do the calculations (it's possible that you need to install it):
  • ```shell
  • interval=$(echo "$duration / 20" | bc)
  • ```
  • Afterwards the rest of your script mostly worked for me.
  • ![Output image of the script, a 5x4 grid of video images](https://linux.codidact.com/uploads/zqf5my353fnvcnm8mwgsxyo9ujgb)
  • More optimizations:
  • ```shell
  • for i in {0..19}; do
  • ffmpeg -ss $((interval * i)) -i "$1" -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 "${1%.*}_frame$i.jpg"
  • done
  • ```
  • - By using `0..19` instead of `1..20` you can clean up the calculations for the wanted second.
  • - `-frames:v 1` removes an error message
  • - `-loglevel 0` removes unnecessary clutter
  • ```shell
  • rm "${1%.*}"_frame*.jpg
  • ```
  • fixes the non working removal of the temporary images.
#1: Initial revision by user avatar GeraldS‭ · 2024-10-08T11:46:10Z (about 1 month ago)
bash does not support floating point operations, so at least for a short video `$interval` will always be `0`. That way you always get the same frame, which by chance probably was black for your video.

You notice that if you place an `echo` in front of your `ffmpeg` call to check the actual command. This resulted in this output for me:

```
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame0.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame1.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame2.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame3.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame4.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame5.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame6.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame7.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame8.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame9.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame10.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame11.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame12.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame13.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame14.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame15.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame16.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame17.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame18.jpg
ffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame19.jpg
```

As you can see, `-ss` is always `0`.

You can use for example [`bc`](https://linux.die.net/man/1/bc) to do the calculations (it's possible that you need to install it):

```shell
interval=$(echo "$duration / 20" | bc)
```

Afterwards the rest of your script mostly worked for me.

![Output image of the script, a 5x4 grid of video images](https://linux.codidact.com/uploads/zqf5my353fnvcnm8mwgsxyo9ujgb)

More optimizations:

```shell
for i in {0..19}; do
    ffmpeg -ss $((interval * i)) -i "$1" -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 "${1%.*}_frame$i.jpg"
done
```

- By using `0..19` instead of `1..20` you can clean up the calculations for the wanted second.
- `-frames:v 1` removes an error message
- `-loglevel 0` removes unnecessary clutter

```shell
rm "${1%.*}"_frame*.jpg
```

fixes the non working removal of the temporary images.