Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Hardware & Software > PC Hard & Software

Reply
 
Thread Tools Search this Thread Display Modes
Old 14th August 2020, 06:35   #1  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
How to convert a video to images?

Hi, so I did some googling and according to this article: https://www.alexkras.com/convert-vid...-command-line/

I should be able to do so with this command in FFMPEG:
Code:
ffmpeg -i 1.mkv -r 24 a/output_%05d.png
But I get an error instead: [image2 @ 000000000232d300] Could not open file : a/output_H:\FFMPEG\bin\1.bat5d.png
av_interleaved_write_frame(): I/O error

This one: https://gist.github.com/savvot/9e4316dc68f6111f7b1f
My version:
Code:
ffmpeg -ss 00:14:13.000 -i "1.mkv" -t 00:00:13.000 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 frame%03d.jpg
Looks like I would be able to pick any point in time of a video and batch take screenshots from it for a period of time. Though it doesn't seem to have a way to configure the delay after each shot....as it shown in the above one.

Except I get this error: [image2 @ 000000000068d880] Could not open file : frameH:\FFMPEG\bin\1.bat3d.jpg
av_interleaved_write_frame(): I/O error

What am I doing wrong? Probably lots as I'm not really a CLI kind of person and prefer and dumb down GUI one, but there is no such thing, at least according to my google searches...although there are websites that would do this for you but I'm not going to upload a massive file...that's gonna take forever! So chose to do a local method with something I already have installed.
egr is offline   Reply With Quote
Old 14th August 2020, 12:08   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Maybe of some little help.

test.bat
Code:
REM test.bat : With location of ffmpeg.exe in environment PATH, and empty IMG directory relative to test.bat file.
REM Gotta have double %% in bat for it to work, or single if direct on command line, also used %%06d (not %%05d) as 100,000 [0->99999] frames max potentially a bit low for long src clip.
REM r 1, 1 frame per second (originally 24)
REM writes png files to IMG directory relative bat file.

ffmpeg -i 1.mkv -r 1 "IMG/output_%%06d.png"
Or to same dir as bat file (using bat file, so using double '%%')
Code:
ffmpeg -i 1.mkv -r 1 "output_%%06d.png"
Or to explict path to write at H:\IMG\ (using bat file, so using double '%%')
Code:
ffmpeg -i 1.mkv -r 1 "H:\IMG\output_%%06d.png"
or direct in CLI command (not in bat file, so using single '%')
Code:
ffmpeg -i 1.mkv -r 1 "H:\IMG\output_%06d.png"
EDIT:
Your "a/output_%05d.png", with single '%', CLI BAT processing, interprets the name of your test.bat as an arg inserted into the output filename

eg (from your error line)
"a/output_H:\FFMPEG\bin\1.bat5d.png"

so your original bat file was "H:\FFMPEG\bin\1.bat". [error was originating in bat processing, not ffmpeg]

Hope that you can use above to figure out how to get 2nd comand working, good luck.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th August 2020 at 14:46.
StainlessS is offline   Reply With Quote
Old 15th August 2020, 08:46   #3  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Quote:
Originally Posted by StainlessS View Post
Maybe of some little help.

test.bat
Code:
REM test.bat : With location of ffmpeg.exe in environment PATH, and empty IMG directory relative to test.bat file.
REM Gotta have double %% in bat for it to work, or single if direct on command line, also used %%06d (not %%05d) as 100,000 [0->99999] frames max potentially a bit low for long src clip.
REM r 1, 1 frame per second (originally 24)
REM writes png files to IMG directory relative bat file.

ffmpeg -i 1.mkv -r 1 "IMG/output_%%06d.png"
Or to same dir as bat file (using bat file, so using double '%%')
Code:
ffmpeg -i 1.mkv -r 1 "output_%%06d.png"
Or to explict path to write at H:\IMG\ (using bat file, so using double '%%')
Code:
ffmpeg -i 1.mkv -r 1 "H:\IMG\output_%%06d.png"
or direct in CLI command (not in bat file, so using single '%')
Code:
ffmpeg -i 1.mkv -r 1 "H:\IMG\output_%06d.png"
EDIT:
Your "a/output_%05d.png", with single '%', CLI BAT processing, interprets the name of your test.bat as an arg inserted into the output filename

eg (from your error line)
"a/output_H:\FFMPEG\bin\1.bat5d.png"

so your original bat file was "H:\FFMPEG\bin\1.bat". [error was originating in bat processing, not ffmpeg]

Hope that you can use above to figure out how to get 2nd comand working, good luck.
[GASPS!] It works! I see what I did wrong - the commands are suppose to be directly into cmd window, not in a batch file and saved for a later time; but adding that extra % allows it to be saved in a batch file and works from there anytime, thanks for the little help!

New line which combines both aspects:
Code:
ffmpeg -ss 00:14:04.000 -i "1.mkv" -t 00:00:12.000 -r 23.97602397602398 a/output_%%04d.png
That should make it so that ffmpeg jumps to 14:04, takes lossless image shots and with a delay equivalent to the frame rate of the video and for 12 seconds flat. Saves all png images in a folder called "a" using a 4 decimal naming scheme. The -i I think is tells it to only take keyframe shots and not any others.

Last edited by egr; 15th August 2020 at 08:52.
egr is offline   Reply With Quote
Old 15th August 2020, 11:50   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
using a 4 decimal naming scheme.
You will have to keep changing the "%04d" (or "%04d") when your requirements output more than 10,000 files,
best if you adopt a standard max number of frames, 6 digits cope with up to a million frames, and no screwing around when you change requirment. (avisynth standard is 6 digits with good reason).
A longish single movie can easily have hundreds of thousands of frames at standard 24/25FPS.
Also, any script to process output frame names might have to be edited whenever you change 4 decimal naming scheme, so best stick with something that dont need constant editing.

Quote:
The -i I think is tells it to only take keyframe shots and not any others.
I dont see any "-i I", (just -i "1.mkv" which is input filename.)
I think that this is the keyframe selection : -vf select="eq(pict_type\,PICT_TYPE_I)"

EDIT: Maybe removing "-r 23.97602397602398" will just output all frames using input framerate for 12 seconds, dont know.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 15th August 2020 at 11:59.
StainlessS is offline   Reply With Quote
Old 25th August 2020, 06:11   #5  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Quote:
Originally Posted by StainlessS View Post
You will have to keep changing the "%04d" (or "%04d") when your requirements output more than 10,000 files,
best if you adopt a standard max number of frames, 6 digits cope with up to a million frames, and no screwing around when you change requirment. (avisynth standard is 6 digits with good reason).
A longish single movie can easily have hundreds of thousands of frames at standard 24/25FPS.
Also, any script to process output frame names might have to be edited whenever you change 4 decimal naming scheme, so best stick with something that dont need constant editing.


I dont see any "-i I", (just -i "1.mkv" which is input filename.)
I think that this is the keyframe selection : -vf select="eq(pict_type\,PICT_TYPE_I)"

EDIT: Maybe removing "-r 23.97602397602398" will just output all frames using input framerate for 12 seconds, dont know.
Oh I see, fair enough I guess I might as well stick with a higher digit output.

Oh I guess I was wrong then if your bit is to select keyframes....
You're right, leaving the -r command and value outputs frames using input framerate source....

Hows it looking now:

Code:
ffmpeg -ss 00:00:00.000 -i "grab.mp4" -vf select="eq(pict_type\,PICT_TYPE_I)" -t 00:00:08.000 e/output_%%06d.png
Should take the first 8 seconds of the video file "grab.mp4" and export all keyframes at source framerate, whatever that is. Perfect piece of code when you want a cheap way to turn a video file into images to do some GIF or APNG files! Or for examining the video file more closesly for whatever details you need I guess.
egr is offline   Reply With Quote
Old 25th August 2020, 14:59   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I dont see anything obviously wrong, but then I aint no expert, just a novice.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 26th August 2020, 15:16   #7  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Quote:
Originally Posted by StainlessS View Post
I dont see anything obviously wrong, but then I aint no expert, just a novice.
Oh well thanks for helping then!
egr is offline   Reply With Quote
Old 26th August 2020, 15:22   #8  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 397
Any particular reason you only want key frames?
Cary Knoop is offline   Reply With Quote
Old 26th August 2020, 15:36   #9  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Quote:
Originally Posted by Cary Knoop View Post
Any particular reason you only want key frames?
Wouldnt they be cleaner to work with than transitional frames?
egr is offline   Reply With Quote
Old 26th August 2020, 15:55   #10  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 397
Quote:
Originally Posted by egr View Post
Wouldnt they be cleaner to work with than transitional frames?
What is the objective?
If you want all extract all the frames for a given time period it is obviously not enough to only select keyframes.

Basically everything is compressed in a video including keyframes. The idea that I frames are great and P and B frames are bad is an unrealistic simplification.
Cary Knoop is offline   Reply With Quote
Old 10th September 2020, 17:10   #11  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Quote:
Originally Posted by Cary Knoop View Post
What is the objective?
If you want all extract all the frames for a given time period it is obviously not enough to only select keyframes.

Basically everything is compressed in a video including keyframes. The idea that I frames are great and P and B frames are bad is an unrealistic simplification.
Oh, I thought it was so. So when would only picking out keyframes, make sense then?
egr is offline   Reply With Quote
Old 10th September 2020, 20:29   #12  |  Link
butterw2
Registered User
 
Join Date: Jun 2020
Posts: 303
Keyframes

Depending on encoding parameters, Keyframes may be more meaningful than other frames (ex: inserted on scene changes in movie encodes, they also allow lossless cutting with h264/hevc). There also less keyframes than regular frames.

Ex 100min movie:
- 100*60*24=144000 frames
- 1000 keyframes if average duration is 6s

Keyframes are also used for seeking in video players such as mcp-hc and video editors such as avidemux, vdub2, so they are good to use for screenshots.
Keyframes usually give the best result, when choosing a thumbnail for compressed video.

Last edited by butterw2; 10th September 2020 at 21:14.
butterw2 is offline   Reply With Quote
Old 16th September 2020, 16:40   #13  |  Link
egr
Registered User
 
Join Date: Jan 2017
Posts: 37
Oh so basically only good at taking clean shots, seeking and cutting purposes which is what this does.... I'm confused as to why Cary would say its not enough then...perhaps I'm not understanding the concept?
egr is offline   Reply With Quote
Old 20th September 2020, 12:02   #14  |  Link
butterw2
Registered User
 
Join Date: Jun 2020
Posts: 303
As was pointed out, all frames can be used, it just depends what your goal is.

If you don't need all frames: output only 1 frame per second for exemple, or keyframes only.

It's worth noting that all frames of a video could be keyframes in some cases (depends on encoding parameters).
butterw2 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 18:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.