简体   繁体   中英

Break video into images for processing

I have recently found friday , a image processing library for haskell and it seems pretty nice so far, but I would like to be able to load videos and break them up into images. Is there such a library available for haskell?

I do not know whether such a library exists, but I suspect not. Video codecs are pretty complicated. If something for haskell exists, it would most likely be an ffmpeg wrapper. Anyway, I would use the ffmpeg command line tool directly if you only need to extract the frames from some videos. Or use a system call to do it dynamically.

The ffmpeg command is pretty simple for this task:

ffmpeg -i "input.mov" -an -f image2 "output_%05d.jpg"

https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence

Notice there are some slick ffmpeg bindings that stream images from a video in the JuicyPixel image types. There is already a ticket for making friday and JuicyPixels play nice - if you are actually interested in getting this done in a clean manner I highly recommend you make a patch to friday addressing this ticket.

Also, since the friday maintainer is busy till September, I'd be happy to merge an of your changes with mine on my own repository for general use.

EDIT: This is fun. A way to get a lazy list of images is with unsafeInterleaveIO :

module LazyDemo where

import Vision.Image.JuicyPixels
import Vision.Image (RGBA)
import Codec.FFmpeg
import System.IO.Unsafe

lazyStream :: FilePath -> IO [RGBA]
lazyStream fp = do
    initFFmpeg
    (rd,close) <- imageReader fp
    go rd close
  where
   go rd close = do
       mi <- rd
       case mi of
           Nothing -> close >> return []
           Just i  -> (toFridayRGBA i : ) <$> unsafeInterleaveIO (go rd close)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM