Extract image from video (ffmpeg) - ffmpeg

I am trying to extract images from video using ffmpeg:
ffmpeg -i sample.mp4 -vf fps=1/30 img%03d.jpg
But I am getting this following error
ffmpeg version 2.2.1 Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 13 2014 13:00:18 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --disable-stripping
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/sites/filemanager.dev/public_html/wout/image/sample.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp42mp41
creation_time : 2009-05-25 21:58:02
Duration: 00:04:03.12, start: 0.000000, bitrate: 309 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 22050 Hz, stereo, fltp, 26 kb/s (default)
Metadata:
creation_time : 2009-05-25 21:58:02
handler_name : Apple Sound Media Handler
Stream #0:1(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x320 [SAR 1:1 DAR 3:2], 120 kb/s, 30.12 fps, 30.12 tbr, 2500 tbn, 1k tbc (default)
Metadata:
creation_time : 2009-05-25 21:58:02
handler_name : Apple Video Media Handler
Stream #0:2(eng): Data: none (rtp / 0x20707472), 128 kb/s
Metadata:
creation_time : 2009-05-25 21:58:02
handler_name : hint media handler
Stream #0:3(eng): Data: none (rtp / 0x20707472), 29 kb/s
Metadata:
creation_time : 2009-05-25 21:58:02
handler_name : hint media handler
[NULL # 0x1d25ea0] Unable to find a suitable output format for 'image2'
image2: Invalid argument
The final out required is I need to extract image at fps 30.

For extracting images from a video:
ffmpeg -i sample.mp4 -r 30 -s WxH -f image2 image%03d.jpg
The -r flag defines extracted image frames per second. It will output them in files named image001.jpeg, image002.jpeg, etc. The optional -s flag will rescale images to fit the new WxH values.
If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.
For more informations, check documentation.

Related

ffmpeg: "stream specifier '' in filtergraph description matches no streams" during concatenation audio and video

I'm trying to concatenate video and audio files, filling space between them with black frames or silence correspondingly.
I use the following command:
ffmpeg -i test/v/1.mkv -i test/v/2.mkv -i test/v/1.mka -i test/v/2.mka -filter_complex 'color=c=black:s=640x480:d=12ms[black0];
color=c=black:s=640x480:d=207725ms[black2];
aevalsrc=0:d=257495ms[silence1];
aevalsrc=0:d=114833ms[silence2];
[black0][0][black2][1][2][silence1][3][silence2]concat=n=8:v=1:a=1[v_out][a_out]' \
-map [v_out] -map [a_out] -c:v libvpx -c:a libopus result.webm
But I get the following error:
Stream specifier '' in filtergraph description matches no streams.
Full ffmpeg output:
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_9 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --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-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --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-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'test/v/1.mkv':
Metadata:
encoder : GStreamer matroskamux version 1.8.1.1
creation_time : 2021-02-05T16:54:38.000000Z
Duration: 00:00:52.24, start: 0.637000, bitrate: 1922 kb/s
Stream #0:0(eng): Video: vp8, yuv420p(progressive), 640x480, SAR 1:1 DAR 4:3, 29.83 tbr, 1k tbn, 1k tbc (default)
Metadata:
title : Video
Input #1, matroska,webm, from 'test/v/2.mkv':
Metadata:
encoder : GStreamer matroskamux version 1.8.1.1
creation_time : 2021-02-05T16:58:58.000000Z
Duration: 00:02:07.19, start: 260.603000, bitrate: 1966 kb/s
Stream #1:0(eng): Video: vp8, yuv420p(progressive), 640x480, SAR 1:1 DAR 4:3, 29.83 tbr, 1k tbn, 1k tbc (default)
Metadata:
title : Video
Input #2, matroska,webm, from 'test/v/1.mka':
Metadata:
encoder : GStreamer matroskamux version 1.8.1.1
creation_time : 2021-02-05T16:55:58.000000Z
Duration: 00:00:02.44, start: 0.624000, bitrate: 80 kb/s
Stream #2:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
title : Audio
Input #3, matroska,webm, from 'test/v/2.mka':
Metadata:
encoder : GStreamer matroskamux version 1.8.1.1
creation_time : 2021-02-05T16:59:01.000000Z
Duration: 00:00:12.40, start: 260.561000, bitrate: 43 kb/s
Stream #3:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
title : Audio
Stream specifier '' in filtergraph description color=c=black:s=640x480:d=12ms[black0];
color=c=black:s=640x480:d=207725ms[black2];
aevalsrc=0:d=257495ms[silence1];
aevalsrc=0:d=114833ms[silence3];
[black0][0][black2][1][2][silence1][3][silence3]concat=n=8:v=1:a=1[v_out][a_out] matches no streams.
Video files do not contain audio.
What I'm doing wrong? Help please.

ffmpeg unable to save a frame at specific time

I followed Im getting error "deprecated pixel format used, make sure you did set range correctly using ffmpeg".. can someone check my code below? to save a frame from a video but the saved frame is of timestamp 00:00:00 instead of the given timestamp
$ ffmpeg -i 001\ Introduction.mp4 -ss 00:03:12.00 -vframes 1 side_view.jpg
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.3.0 (Gentoo 9.3.0 p2)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/share/doc/ffmpeg-4.2.2/html --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags='-march=native -O2 -pipe' --disable-static --enable-avfilter --enable-avresample --disable-stripping --disable-optimizations --disable-libcelt --disable-indev=oss --disable-indev=jack --disable-outdev=oss --enable-version3 --enable-nonfree --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-gcrypt --disable-gnutls --enable-gmp --enable-gpl --disable-hardcoded-tables --enable-iconv --disable-libtls --enable-libxml2 --disable-lzma --enable-network --enable-opencl --disable-openssl --enable-postproc --disable-libsmbclient --enable-ffplay --enable-sdl2 --enable-vaapi --enable-vdpau --enable-xlib --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable-libcaca --disable-openal --enable-opengl --enable-libv4l2 --enable-libpulse --enable-libdrm --disable-libjack --disable-libopencore-amrwb --disable-libopencore-amrnb --disable-libcodec2 --disable-libdav1d --enable-libfdk-aac --enable-libopenjpeg --enable-libbluray --disable-libgme --disable-libgsm --disable-libaribb24 --disable-mmal --disable-libmodplug --enable-libopus --disable-libilbc --disable-librtmp --disable-libssh --disable-libspeex --enable-libsrt --enable-librsvg --disable-ffnvcodec --enable-libvorbis --enable-libvpx --disable-libzvbi --disable-appkit --disable-libbs2b --disable-chromaprint --disable-cuda-llvm --disable-libflite --disable-frei0r --disable-libfribidi --enable-fontconfig --disable-ladspa --enable-libass --disable-libtesseract --enable-lv2 --enable-libfreetype --disable-libvidstab --disable-librubberband --disable-libzmq --disable-libzimg --disable-libsoxr --enable-pthreads --disable-libvo-amrwbenc --enable-libmp3lame --disable-libkvazaar --disable-libaom --disable-libopenh264 --disable-libsnappy --enable-libtheora --disable-libtwolame --disable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-neon --disable-vfp --disable-vfpv3 --disable-armv8 --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-altivec --disable-amd3dnow --disable-amd3dnowext --disable-aesni --disable-avx --disable-avx2 --disable-fma3 --disable-fma4 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-xop --enable-pic --cpu=host --disable-doc --disable-htmlpages --enable-manpages
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '001 Introduction.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:09:40.10, start: 0.000000, bitrate: 1981 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1835 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 1280x108, 0 kb/s (default)
Metadata:
rotate : 0
creation_time : 2020-05-20T08:15:54.000000Z
File 'side_view.jpg' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler # 0x55e27e819520] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'side_view.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Stream #0:0(eng): Video: mjpeg, yuvj420p(pc), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.54.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 1 fps=0.1 q=5.2 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.00313x
video:44kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
In the above output, notice time=00:00:00.03 despite the given -ss 00:03:12.00.
Update
ffmpeg -i "001 Introduction.mp4" -ss 00:03:12.00 -vframes 1 -report -copyts side_view.jpg
https://gist.github.com/GowthamKudupudi/d3703f990548819a5bcd5e72bd5c0449
FFmpeg resets output timestamps to start from zero, unless the user expressly adds flags to override it. So, nothing wrong or unexpected here.

Convert videos from .264 to .265 (HEVC) with ffmpeg

I see that there are a few questions on this subject but I am still getting errors. All I want to do is convert videos in my library to HEVC so they take up less space.
I've tried this:
ffmpeg -i input.mp4 -c:v libx265 output.mp4
ffmpeg seems to take a long time and the output seems to be about the right size. The video will play with VLC but the icon is weird and when I try to open it with QuickTime, I get the error: 'The document “output.mov” could not be opened. The file isn’t compatible with QuickTime Player.'
I don't want to change any of the fancy settings. I just want the files to take up less space and with minimal or no quality loss.
Thanks!
EDIT:
Having trouble keeping the time stamp that I put into the videos.
Originally I was using exiftool in terminal. But, sometimes that doesn’t work with videos, so I would airdrop them to my iPhone, use an app called Metapho to change the dates, and then airdrop them back. Exiftool was create but sometimes I just wouldn’t work. It would change the date to something like 1109212 Aug 2nd. Weird. Bottom line is that when I do these conversions, I really don’t want lose the time stamps in them.
ORIGINAL FILE THAT I TIMESTAMPED, IN .264
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original.mov':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2019-10-22T18:48:43.000000Z
encoder : HandBrake 0.10.2 2015060900
com.apple.quicktime.creationdate: 1994-12-25T18:00:00Z
Duration: 00:01:21.27, start: 0.000000, bitrate: 800 kb/s
Chapter #0:0: start 0.000000, end 81.265000
Metadata:
title : Chapter 12
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 710x482 [SAR 58409:65535 DAR 1043348:794715], 634 kb/s, SAR 9172:10291 DAR 404229:307900, 29.95 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2019-10-22T18:48:43.000000Z
handler_name : Core Media Video
encoder : 'avc1'
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
creation_time : 2019-10-22T18:48:43.000000Z
handler_name : Core Media Audio
Stream #0:2(und): Data: bin_data (text / 0x74786574), 0 kb/s
Metadata:
creation_time : 2019-10-22T18:48:43.000000Z
handler_name : Core Media Text
At least one output file must be specified
FILE CONVERTED TO HEVC, WITHOUT -COPYTS TAG
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original_HEVC.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.29.100
Duration: 00:01:21.30, start: 0.000000, bitrate: 494 kb/s
Chapter #0:0: start 0.000000, end 81.265000
Metadata:
title : Chapter 12
Stream #0:0: Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, progressive), 710x482 [SAR 9172:10291 DAR 404229:307900], 356 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
Metadata:
handler_name : Core Media Video
encoder : Lavc58.54.100 libx265
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : Core Media Audio
Stream #0:2(eng): Data: bin_data (text / 0x74786574), 0 kb/s
Metadata:
handler_name : SubtitleHandler
At least one output file must be specified
FILE CONVERTED TO HEVC, WITH -COPYTS TAG
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
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
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original_HEVC_keepts.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.29.100
Duration: 00:01:21.30, start: 0.000000, bitrate: 494 kb/s
Chapter #0:0: start 0.000000, end 81.265000
Metadata:
title : Chapter 12
Stream #0:0: Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, progressive), 710x482 [SAR 9172:10291 DAR 404229:307900], 356 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
Metadata:
handler_name : Core Media Video
encoder : Lavc58.54.100 libx265
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : Core Media Audio
Stream #0:2(eng): Data: bin_data (text / 0x74786574), 0 kb/s
Metadata:
handler_name : SubtitleHandler
At least one output file must be specified
This answer was posted (under the CC BY-SA 4.0 license) as a comment by Gyan to the question Convert videos from .264 to .265 (HEVC) with ffmpeg.
Run this command for x265 convertation:
ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 output.mp4
Convert 4k to 1080 (no change in codec)
ffmpeg -i input4kvid.mp4 -vf scale=1920:1080 -c:a copy output1080vid.mp4
Convert h.264 to h.265 (no change in resolution)
ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 -c:a copy output.mp4
Convert 4k(h.264) to 1080(h.265)
Downscaling + Change in compression codec
ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 -vf scale=1920:1080 -crf 20 -c:a copy output.mp4
Options Explained
-i input file name or file path
-c:v libx265 -vtag hvc1 selecting compression. Default is libx264
-vf scale=1920:1080 specifying output resolution
-c:a copy copy audio as it is without any compression
-preset slow ask compression algorithm to take more time & look for more areas for compression. Default is medium. Other options are faster, fast, medium, slow, slower
-crf 20 Compression quality
-crf 0 high-quality, low compression, large file
-crf 23 default
-crf 51 low-quality, high compression, small file
-vtag hvc1 use codec hvc1 (a.k.a. HEVC or h.265) during conversion.
If -vtag isn't specified (like in the first snippet), it will then use the codec used in the src file.
If you have NVIDIA GPU, you can use hevc_nvenc for the encoder parameter which should be faster than a CPU encoder.
ffmpeg -i input.mp4 -c:v hevc_nvenc -rc vbr_hq -cq 18 -b:v 0k -2pass 0 output.mp4
However, note that hardware encoded files aren't as optimized as CPU encoded
for mobile phone users it's better to use the scale of 1080*1920.
ffmpeg -i input4kvid.mp4 -vf scale=1080:1920 -c:a copy output1080vid.mp4

Getting error while converting on FFMPEG? what's the meaning & how it should be fixed?

I am using this code to apply watermark on linux server;
-i input.mp4 logo.png -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' output.mp4
so ended-up with this error;
Please use -b:a or -b:v, -b is ambiguous
Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_overlay_0
Full error;
ffmpeg version N-71954-gbc6f84f Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/usr --enable-version3 --enable-gpl --enable-shared --
enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libvpx --
enable-libx264 --enable-libxvid --enable-libopencore-amrwb --enable-libopencore-
amrnb --enable-postproc --enable-nonfree --enable-pthreads --enable-x11grab --
enable-libfaac --enable-libopenjpeg --enable-zlib --disable-doc
libavutil 54. 23.101 / 54. 23.101
libavcodec 56. 37.101 / 56. 37.101
libavformat 56. 31.102 / 56. 31.102
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'uploaded/1502539665_21.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.31.102
enter code here
Duration: 00:02:27.32, start: 0.023220, bitrate: 635 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x320
[SAR 1:1 DAR 3:2], 476 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
enter code here
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 151 kb/s (default)
Metadata:
handler_name : SoundHandler
enter code here
Please use -b:a or -b:v, -b is ambiguous
Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_overlay_0
Your image isn't presented as an input so ffmpeg treats it as the first output, and output.mp4 as the 2nd output. The filter_complex only sees the video as an input.
Start your command like this
ffmpeg -i input.mp4 -i logo.png

ffmpeg : how to determine frame rate automatically?

I use this simple script to convert video to images using ffmpeg, but frame rate is fixed, how can I determine it automatically?
FRAME_RATE="30"
SEPARATOR='/'
VIDEO_PATH=$1
VIDEO_BASE_DIR=`dirname $1`
FRAMES_DIR=$VIDEO_BASE_DIR$SEPARATOR"Frames"
rm -rf $FRAMES_DIR
mkdir $FRAMES_DIR
#Convert video to images
./ffmpeg -r $FRAME_RATE -i $VIDEO_PATH $FRAMES_DIR$SEPARATOR"image%d.png"
UPDATE:
By ffprobe I checked that my 1st video frame rate is 30.
Also results are the same (339 frames are produced) even I reduce frame rate, so -r option doesn't work or work in some other way?
These command give the same result:
./ffmpeg -r 10 -i $VIDEO_PATH $FRAMES_DIR$SEPARATOR"image%d"$EXTENSION
./ffmpeg -r 30 -i $VIDEO_PATH $FRAMES_DIR$SEPARATOR"image%d"$EXTENSION
./ffmpeg -i $VIDEO_PATH $FRAMES_DIR$SEPARATOR"image%d"$EXTENSION
Output:
ffmpeg version N-63893-gc69defd Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 16 2014 05:38:01 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.101 / 55. 66.101
libavformat 55. 43.100 / 55. 43.100
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 8.100 / 4. 8.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/user/myvideo1.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-01-16 05:30:03
Duration: 00:00:11.33, start: 0.000000, bitrate: 4659 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 4539 kb/s, SAR 65536:65536 DAR 4:3, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 90
creation_time : 2016-01-16 05:30:03
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
creation_time : 2016-01-16 05:30:03
handler_name : SoundHandle
Output #0, image2, to '/home/user/Frames/image%d.png':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf55.43.100
Stream #0:0(eng): Video: png, rgb24, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 fps, 90k tbn, 30 tbc (default)
Metadata:
rotate : 90
creation_time : 2016-01-12 05:38:03
handler_name : VideoHandle
encoder : Lavc55.66.101 png
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> png (png))
Press [q] to stop, [?] for help
frame= 339 fps= 68 q=0.0 Lsize=N/A time=00:00:11.30 bitrate=N/A
video:195852kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
ffprobe -v 0 -of compact=p=0 -select_streams 0 \
-show_entries stream=r_frame_rate 'The Master (2012).mp4'
Result:
r_frame_rate=24000/1001
You can use ffprobe and awk to grab fps for you:
ffprobe -show_streams "video" 2>&1 | \
grep fps | \
awk '{split($0,a,"fps")}END{print a[1]}' | \
awk '{print $NF}'
Some time ago I wrote an article about generating ffmpeg previews from videos which is maybe similar to what you're trying to do. I had to count total number of frames in a video:
See https://www.binpress.com/tutorial/how-to-generate-video-previews-with-ffmpeg/138
What about
./ffmpeg -i input_file 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p"
ON windows 10,
ffmpeg -i <input video file>
The last portion will show fps info. Please check the line beginning with "Stream...."
The following video file is encoded in 60 fps .
C:\user\mitchell\ffmpeg -i video0001.mp4
ffmpeg version 2021-09-22-git-447cf53774-essentials_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.3.0 (Rev5, 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-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-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. 6.100 / 57. 6.100
libavcodec 59. 9.100 / 59. 9.100
libavformat 59. 5.100 / 59. 5.100
libavdevice 59. 0.101 / 59. 0.101
libavfilter 8. 9.100 / 8. 9.100
libswscale 6. 1.100 / 6. 1.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Input #0, matroska,webm, from 'video0001.mp4':
Metadata:
encoder : GStreamer matroskamux version 1.14.5
creation_time : 2021-09-22T17:52:09.000000Z
Duration: 00:00:25.75, start: 2.470000, bitrate: 4256 kb/s
Stream #0:0(eng): Video: hevc (Main), yuvj420p(pc, progressive), 3840x2160, SAR 1:1 DAR 16:9, 60 fps, 60 tbr, 1k tbn (default)
Metadata:
title : Video

Resources