E
E
Evgeny Ivanov2019-12-26 06:55:02
Video processing
Evgeny Ivanov, 2019-12-26 06:55:02

FFmpeg - how to split a video file into png images?

The cut_1.avi file (15 seconds, 25fps) needs to be split into png images.
I created a test folder where I put ffmpeg.exe and cut_1.avi.
In the same folder, I created a cut_1_images folder. PNG files should appear there.
And I created a bat file in which I wrote the following:

rem Выбор текущей папки
%~d1
cd "%~p1"
ffmpeg -i cut_1.avi -r 25 -f image2 cut_1_images\images%05d.png
@pause

But an error occurs
C:\TEMP\test>rem ╨Т╤Л╨▒╨╛╤А ╤В╨╡╨║╤Г╤Й╨╡╨╣ ╨┐╨░╨┐╨║╨╕

C:\TEMP\test>cd ""
C:\TEMP\test

C:\TEMP\test>ffmpeg -i cut_1.avi -r 25 -f image2 cut_1_images\images"C:\TEMP\tes
t\jpg_from_video.cmd"5d.png
ffmpeg version git-2019-11-13-4e0860e Copyright (c) 2000-2019 the FFmpeg develop
ers
  built with gcc 9.2.1 (GCC) 20191010
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libb
luray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --e
nable-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 --enab
le-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --en
able-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcode
c --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. 62.100 / 58. 62.100
  libavformat    58. 35.100 / 58. 35.100
  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
Input #0, avi, from 'cut_1.avi':
  Metadata:
    encoder         : Lavf58.35.100
  Duration: 00:00:16.04, start: 0.000000, bitrate: 102750 kb/s
    Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1920x1080, 102861 kb/
s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 k
b/s
Stream mapping:
  Stream #0:0 -> #0:0 (ffv1 (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'cut_1_images\imagesC:\TEMP\test\jpg_from_video.cmd5d.png'
:
  Metadata:
    encoder         : Lavf58.35.100
    Stream #0:0: Video: png, rgb24, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb
/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.62.100 png
[image2 @ 0000000000464540] Could not open file : cut_1_images\imagesC:\TEMP\tes
t\jpg_from_video.cmd5d.png
av_interleaved_write_frame(): I/O error
frame=    5 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=3 drop=0 s
peed=0.165x
video:6kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing ove
rhead: unknown
Conversion failed!
Для продолжения нажмите любую клавишу . . .

Could not open file : cut_1_images\imagesC:\TEMP\test\jpg_from_video.cmd5d.png - ???
Of course, I don't have that.
How to split a video file into png images? How to write a command correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@nidalee, 2019-12-26
@logpol32

You are pointing too much. For your purposes,
-f is enough, you don't need png - always png native.
-r too, because ffmpeg itself recognizes the frame rate of the video perfectly.
Perhaps you should specify the full path to the folder, with a drive letter. It's also good to avoid spaces in this path.
I also didn’t understand why you recognize and cd to the folder from which you run the bat-nick, it already works from its folder, just don’t run it from the admin, it doesn’t need it.
Better then do this:

@echo off
SETLOCAL
:hugly
if "%~1" EQU "" goto mugly
md images
ffmpeg -i "%~1" images\images%%05d.png
shift
goto hugly
:mugly
pause

Then just drag and drop your AVI file onto the bat-nick itself, it will create the "images" folder for the frames and extract them into it. If I didn't typo anywhere in the code, of course. Just remember that the folder is always the same, rename it after extracting frames.
UP: Rewrote both examples for Windows, the solution was to add one more to the %.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question