I’m writing a simple bash script named video2png, using the ffmpeg
to turn certain frame of a video into png:
#!/bin/bash
ffmpeg -ss 30:00 -i "$1" -frames 1 -s 1280x880 -f image2 "$2"
I pass the video path and the wanted output path to the script as the first and the second parameter. As you can see in the script, I get these two paths through "$1"
and "$2"
.
I run the script in the Terminal on my Mac like the following:
Path1="/Users/jintai/Downloads/demon/a b/demon.mp4"
Path2="/Users/jintai/Downloads/demon/a b/demon.png"
bash video2png "$Path1" "$Path2"
However, it seems like the flag parameter -frames
for the ffmpeg
in the script is misunderstood as a file under the video path since I get the following error message:
Trailing option(s) found in the command: may be ignored.
-frames: No such file or directory
How may I solve this? Thank you for your time and advice!
Editted: As suggested by @muru, I run my script with -x
after bash
. But the problem is still here. Here are my run and all outputs:
(base) jintai@192 missing % bash -x video2png "$Path1" "$Path2"
+ ffmpeg -ss 30:00 -i -frames 1 -s 1280x880 -f image2
ffmpeg version 4.4.2 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-librsvg --enable-libtheora --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libsoxr --enable-libspeex --enable-libass --enable-libbluray --enable-libzimg --enable-libzvbi --enable-lzma --enable-gnutls --enable-fontconfig --enable-libfreetype --enable-libfribidi --enable-zlib --disable-libjack --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-indev=jack --enable-opencl --disable-outdev=xv --enable-audiotoolbox --enable-videotoolbox --enable-sdl2 --disable-securetransport --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --enable-libdav1d --enable-libaom --enable-librav1e --enable-libsvtav1 --arch=x86_64 --enable-x86asm --enable-gpl --enable-postproc --enable-libx264 --enable-libx265 --enable-libxvid --enable-libvidstab
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Trailing option(s) found in the command: may be ignored.
-frames: No such file or directory
Edited:
As suggested by @Gilles 'SO- stop being evil’, I posted my script here. Actually I’m a new learner of Bash and I used the echo
to write into the script. The first code block in the first post is what I use echo
to write into the script. Here is the script:
video2png. Thanks you all for your suggestions! I look forward to more discussion.
PathN=...
lines are some fancy Unicode quotes, which the shell will not recognize as actual quotes. I'm not sure if that's a presentation issue here, but if it's like that in your actual script too, that might cause issues. There's the same issue in the text where you mention”$1”
and”$2”
, but the rest of the quotes in the code segments seem ok. – ilkkachu Feb 21 '24 at 09:52bash -x video2png "$Path1" "$Path2"
and add the output to the post, please. – muru Feb 21 '24 at 10:07bash -x
output that they have no value. – terdon Feb 21 '24 at 10:27-i "$1"
part would expand to-i ''
, and Bash's trace output would explicitly show the empty string arg. (And this is true even in Bash 3.2 which their Mac might have.) – ilkkachu Feb 21 '24 at 12:04ffmpeg -i "$1"
in the script, vs.ffmpeg -i $1
. With the quotes, it'll pass ffmpeg a single argument, no matter what, even if it's the empty string. But that's not visible in the xtrace output. Which is why it looks like your script isn't what was posted here. – ilkkachu Feb 21 '24 at 13:05#/bin/bash -c
andffmpeg -ss 30:00 -i -frames 1 -s 1280x880 -f image2
. No reference to the command line args$1
and$2
at all and having that-c
in the hashbang line can't do anything useful. I'm not sure what you mean with "I used the echo to write into the script.", but the script as shown in the post above looks exactly like it should be. The one in the google share is just broken. – ilkkachu Feb 21 '24 at 13:07