On a current side project I needed to create thumbnails on given timestamps in NRK programmes. After browsing around a bit, I found a quote that sums it up: “All of them (the links) say «Use FFMPEG OpenSource Project» for the job. “
Here are the steps taken to achieve a working solution and some performance tips learned underway.
- Getting the FFmpeg executable and placing it on local drive. A quick search and you will find it, there are a few builds for windows, choose the most appropriate for your environment.
- A quick test of a command (ffmpeg -y -i \\someSan\6\DVNR04\00\DVNR04003814\DVNR04003814AA_ID720.mp4 -s 50×50 -ss 00:02:10.100 -f image2 -vframes 1 out.png) worked beautifully, below is a screenshot of the output:
- I needed to write a programme to automate this. The programme needed logic to find the files on a SAN. Calculate the proper filenames based on programme Id and time. And lastly to execute the FFmpeg snap process. Below is a gist of the programme.
- When first trying to run the code on 10 programmes it was really slow. In NRK all our programmes come in 5 qualities and I was using the highest one (720p) to take the thumbnails. Using the highest quality for a 96×54 snap is a bit overkill so i switched to the lowest which was the first speed improvement.
- Below is a benchmark run on 10 programmes, it took 58 snaps in 6 minutes, not so great.
- A greater improvement was to put the -ss option in front of the -i option since that makes FFmpeg seeking use input as keyframes not decoding frame-by-frame. This really sped things up and the new benchmark showed improvement from about 6 minutes to 1 minute 18 seconds.
Things that could have been done differently/improved
Most of the FFmpeg options are hard coded, to fit my needs, should the need arise they should of course be made configurable.
I am pretty happy with the solution, it has worked flawlessly so far. Please feel free to comment or/and code review in english or norwegian.