Creating datasets using FFMPEG
- Go to ffmpeg.org and then click on the download button.
2. Select the windows option.
3. Select either gyan.dev or BtbN.
4. You should visit this page once you click the first link mentioned.
5. There are four specific sections here: git full get, git essentials, release full and release essentials. The ones with git full are built from the master branch and release full is built from the latest release meaning that they should be more stable. Full versus essential simply means that the full version comes with a large set of libraries and the essentials come only with commonly used libraries. Depending on what you need you can download either of these.
6. So, if you’d like the cutting-edge stick to the git. Otherwise scroll down further to the release section over here and download either full or essentials by clicking on one of these. The 7z files are the same as the zip file over here but they’re much more compressed as you can see. Download either of them.
7. This 7z file opens like any other zip file except you’ll need 7zip or another advanced unzipping program to open it up. If you don’t have 7-zip, simply download it from here 7-zip.org.
8. When you do eventually download it and open one of the zips or 7zip files, you’ll see a folder inside of it. Opening it up, we have presets, doc, bin, readme, and license. All we’re interested in here is the bin folder as it contains the built FFmpeg binaries.
9. So, let’s get to installing. First, hit start+e to bring up a new file explorer and head across to your c drive. Of course, you can put this anywhere but the easiest thing to do would be to put it in c followed by say path programs or simply a folder named FFmpeg.
10. I already have it installed here all you have to do is simply drag and drop the FFmpeg exes into a known location on a drive. In our case, FFmpeg is now installed in c PATH_Programs.
11. Let’s go ahead and add it to our system so that it recognizes where this file is. Hit start and type in the path then we’ll click edit the system environment variables.
12. After this window opens up simply head across to environment variables at the very bottom.
13. If you’d like it to apply for all users simply select it under the system variables path as such pick one and then click edit.
14. We have a huge list of files and folders. Click new at the very top and then type in the file location. You can of course simply select the file location at the top copy the text and paste it into the window here.
15. After doing that simply hit enter or click anywhere else click ok and ok once again. After closing out of the system properties window we’ve now successfully installed FFmpeg.
16. How do we know it’s installed well we simply check with the command prompt. Hold-down start press r and then simply type in cmd.
17. After this black console window opens type in FFmpeg. After hitting enter you’ll see a whole bunch of text returned to you and that’s about it, you’re done.
18. Now let’s try to create an image dataset from a video. Go to the directory where you have the video saved. In this case, we will try to test on Harpic unencoded products. Here we have a 40-second video. In this case, the video is taken in high quality for better results. This 40-second video was about 600 MB.
NOTE: Record the product’s video in high quality to extract high-quality images.
19. Open the command prompt and go to the location where you have your video saved.
20. Type the following command and hit enter.
ffmpeg -i Harpic.mp4 -qscale:v 1 test%03d.png
21. Here, we have terminated the cmd to stop it. We have achieved around 2300 frames from 20-second video, all high quality.
22. Result obtained:
How to extract a good-quality JPEG image from a video file with FFmpeg?
1. Use -qscale:v
to control the quality
2. Use -qscale:v
(or the alias -q:v
) as an output option.
· Normal range for JPEG is 2–31 with 31 being the worst quality.
· The scale is linear with double the qscale being roughly half the bitrate.
· Recommend trying values of 2–5.
· You can use a value of 1 but you must add the
-qmin 1
output option (because the default is-qmin 2
).
3. To output a series of images:
ffmpeg -i input.mp4 -qscale:v 2 output_%03d.jpg
4. To output a single image at ~60 seconds duration:
ffmpeg -ss 60 -i input.mp4 -qscale:v 4 -frames:v 1 output.jpg
5. Output the images in a lossless format such as PNG:
ffmpeg.exe -i 10fps.h264 -r 10 -f image2 10fps.h264_%03d.png
If you have any questions or suggestions regarding the blog, please comment down below. In case you have not followed me yet, please do. I hope to see you again for another blog.
Till then, take care!