Post History
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....
Answer
#2: Post edited
- 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.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame1.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame2.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame3.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame4.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame5.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame6.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame7.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame8.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame9.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame10.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame11.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame12.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame13.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame14.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame15.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame16.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame17.jpgffmpeg -ss 0 -i Example.mp4 -vf scale=200:-1 -q:v 2 -frames:v 1 -loglevel 0 Example_frame18.jpgffmpeg -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
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.