I am attempting to write a script that takes a photo every 3 seconds from camera source "1", the -pix_fmt I think is unique to my USB camera.
Here is the script:
#!/bin/bash
set -e
while :
do
nice_num=$(date +%s)
ffmpeg -ss 00:00:00 -f avfoundation -pix_fmt yuyv422 -r 30.000030 -i "1" -t 1 -frames:v 1 -q:v 2 "image_$nice_num_%03d.jpg"
wait
sleep 3
done
The issue is half the time it successfully takes the photo, and half the time it just hangs forever echoing this (not useful):
ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.1.6 (clang-1316.0.21.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/5.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
Then I CTRL-C 3 times and get:
^C^C^CReceived > 3 system signals, hard exiting
Other methods of "taking a photo every n seconds from bash" are also appreciated.
Related
I do not have much expertise. I have been trying to convert a 240 jpeg long sequence (in a folder named plane) in to a 24fps mp4 file. each file is named 0001.jpeg , 0002.jpeg and so on.
I have tried this
ffmpeg -framerate 24 -i C:\Desktop\plane\image%4d.jpg output.mp4 and some variations on that but nothing seems to work.
the above command results in this
C:\Users\username>ffmpeg -framerate 24 -i C:\Desktop\plane\image%4d.jpg output.mp4
ffmpeg version 2022-07-31-git-1368b5a725-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 57. 30.100 / 57. 30.100
libavcodec 59. 40.100 / 59. 40.100
libavformat 59. 29.100 / 59. 29.100
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 46.101 / 8. 46.101
libswscale 6. 8.101 / 6. 8.101
libswresample 4. 8.100 / 4. 8.100
libpostproc 56. 7.100 / 56. 7.100
[image2 # 0000018847e4d500] Could find no file with path 'C:\Desktop\plane\image%4d.jpg' and index in the range 0-4
C:\Desktop\plane\image%4d.jpg: No such file or directory
Any help will be greatly appreciated
I used the following command to transfer a rtsp stream to a .mp4 file:
ffmpeg -rtsp_transport tcp -timeout 5000000 -i "rtsp://zigong.stream.xl02.cn:557/HongTranSvr?DevId=1b038d27-858c-46a1-b803-a2984af343df&Session=1b038d27-858c-46a1-b803-a2984af343df" -vcodec copy -t 5 -y "capture.mp4"
The result is as below:
[rtsp # 0x5655577ccc00] Unable to open RTSP for listening
rtsp://zigong.stream.xl02.cn:557/HongTranSvr?DevId=1b038d27-858c-46a1-b803-a2984af343df&Session=1b038d27-858c-46a1-b803-a2984af343df: Cannot assign requested address
But it worded fine if I delete the timeout option...
the ffmpeg version is:
ffmpeg version 3.2.12-1~deb9u1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --prefix=/usr --extra-version='1~deb9u1' --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Try to update FFmpeg version and replace -timeout into -stimeout.
This issue was fixed a few months ago. [ref]
I want to convert a bunch of photos into a video with crossfade between them. The number of photos I am converting is variable
I am using the code from HERE to apply the crossfade:
Since the number of photos are variable I looped over all the photos in the directory and generated the -loop and also the second part ([0:v]fade=t=out:st=4:d=1[v0];):
for i in range(os.listdir('photos')):
if i == 0:
text += f'\n-loop 1 -t 60 -i photos/Image{i+1}.jpg \\\n'
text2 = '\n[0:v]fade=t=out:st=4:d=1[v0]; \\\n'
else:
text += f'-loop 1 -t 60 -i photos/Image{i+1}.jpg \\\n'
text2 += f' [{i}:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v{i}]; \\\n'
#And the Subprocess part
command = f'ffmpeg \
{text} \
-filter-complex \
{text2} -map "[v]" video/out.mp4'
p = subprocess.call(command, shell=True)
But this thing didn't create any video but said this:
Use -h to get full help or, even better, run 'man ffmpeg'
The full output:
ffmpeg version git-2019-11-11-20c5f4d Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20191010
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 35.101 / 56. 35.101
libavcodec 58. 61.100 / 58. 61.100
libavformat 58. 34.101 / 58. 34.101
libavdevice 58. 9.100 / 58. 9.100
libavfilter 7. 66.100 / 7. 66.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
On windows I could do something like this to list input devices:
ffmpeg -list_devices true -f dshow -i dummy
On Linux I try doing something like this:
ffmpeg -list_devices true -f <x11grab/avfoundation>
And I get an error (I have also tried the latest git build from here):
ffmpeg version n4.2.4 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Unrecognized option 'list_devices'.
Error splitting the argument list: Option not found
How can I list my input devices?
avfoundation is only available for Apple devices. x11grab is meant to capture X Window servers and does not have a list_devices option available.
Please take a look at Pulse Audio:
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Clients/Samples/AsyncDeviceList/
Example:
pactl list sources
Other alternatives using alsa:
/proc/asound/cards
/proc/asound/devices
I am attempting to combine youtube-dl and ffmpeg to clip audio from YouTube videos. Everything was fine on my laptop, but when I moved to my server (Debian 9) I started coming across this error. Why is this? Am I missing a dependency ... if so which one?
Input
ffmpeg -f m4a $(youtube-dl -f bestaudio[ext=m4a] -g \'https://www.youtube.com/watch?v=qnjYyfkcaNI\' | sed "s/.*/-ss 0 -i &/") -to 60 -c copy -y /public/audio/test.m4a
Error
[NULL # 0x55cf161f1e60] Requested output format 'm4a' is not a
suitable output format /public/audio/test.m4a: Invalid argument
ffmpeg info
ffmpeg version 3.2.12-1~deb9u1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --prefix=/usr --extra-version='1~deb9u1' --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
The error was not with ffmpeg. The youtube-dl command was failing and resulting in the error.
Updated command
ffmpeg -f m4a $(youtube-dl -f bestaudio[ext=m4a] -g https://www.youtube.com/watch?v=qnjYyfkcaNI | sed "s/.*/-ss 0 -i &/") -to 60 -c copy -y /public/audio/test.m4a
Basically just had to remove the \'.
I also had to go one step further and give permission to the www-data apache group for the output folder since the command was being executed from a PHP script.