7875

Extract first non black keyframe with FFMPEG

I'm trying to extract a thumbnail image from a video keyframes using ffmpeg, my command line is:

ffmpeg -i video.mp4 -vframes 1 -s 200x200 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 -f image2 video.jpg

But the keyframe it extracts is totally black (the video starts with a black frame i guess) ... is there a way to automatically <strong>extract the first non black keyframe</strong> from a video, <strong>without</strong> seeking to a specific time (i have to manage multiple videos of many durations) ?

Thanks

Answer1:

I cannot think of a solution using ffmpeg alone. But if you extract the first few keyframes (by turning up to -vframes 20 for example) they could then be analyzed with ImageMagic. Reducing the image to one grayscale color will it with pick the average gray value from the picture. A command line like

convert avatar.jpeg -colors 1 -type grayscale -format '%c' histogram:info:

which will produce an output like

16384: ( 80, 80, 80) #505050 gray(80)

(I used Simone's avatar picture for an example.) The last number is the most interesting for your case. It expresses how dark the image is, with 0 for ideal black and 255 for pure white. A sed script can easily extract it

convert ... | sed 's/^.*(\(.*\))$/\1/'

Mix it up with some shell scripting to find the first image that has a gray value higher than a given threshold and use it as the thumbnail.

Answer2:

With the option thumbnail=num_frame you can choose when you extract a frame, but I don't know if it is possible extract the first non balck keyframe. http://ffmpeg.org/ffmpeg.html#thumbnail

Recommend

  • What is the sql query for this?
  • Azure deployment continually recycling since upgrading the June 2012 SDK 1.7
  • Row_number() function for Informix
  • How can I get process name of specific PID with ps command in alpine
  • css font-size and line-height not matching the baseline
  • Save website uploads in a subdomain
  • SSIS Designer is running VERY slowly
  • How to add the custom button on google's(device) native application in android?
  • AlertDialog style when using setView()
  • Failed to find version-tag string. File must be updated
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Compare struct to a constant in C
  • HTML5 video only works in IE. The other browsers shows the black screen
  • Django Haystack Rebuild Index
  • netsh acl setting (need alternative method - registry settings?)
  • how to set variables in a php include file?
  • AndEngine Applying Transparancy to AndEngine View
  • wxPython: displaying multiple widgets in same frame
  • Reduction and collapse clauses in OMP have some confusing points
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Cancel a live stream “fast motion” catch-up in Flash
  • Python CGI os.system causing malformed header
  • Recording logins for password protected directories
  • R - Combining Columns to String Based on Logical Match
  • JFileChooser in front of fullscreen Swing application
  • swift auto completion not working in Xcode6-Beta
  • Excel - Autoshape get it's name from cell (value)
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Jquery - Jquery Wysiwyg return html as a string
  • Confusion with PayPal's monthly billing cycle
  • Matrix multiplication with MKL
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • embed rChart in Markdown
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Unable to use reactive element in my shiny app
  • Converting MP3 duration time