diff --git a/CHANGELOG.md b/CHANGELOG.md index a4c6bb1..3ba97da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 0.11.0 * Query stream duration (Matthias Treydte) +* Initial support for verbosity control; defaults to quiet + * Can be changed with the new `setLogLevel` function # 0.10. 0 diff --git a/demo/Main.hs b/demo/Main.hs index f0689df..3365517 100644 --- a/demo/Main.hs +++ b/demo/Main.hs @@ -66,7 +66,8 @@ loopFor time m = testCamera :: IO () testCamera = - do initFFmpeg + do initFFmpeg -- Defaults to quiet (minimal) logging + -- setLogLevel avLogInfo -- Restore standard ffmpeg logging (getFrame, cleanup) <- imageReader (Camera "0:0" defaultCameraConfig) frame1 <- getFrame case frame1 of diff --git a/src/Codec/FFmpeg.hs b/src/Codec/FFmpeg.hs index a52cfe7..1d08f84 100644 --- a/src/Codec/FFmpeg.hs +++ b/src/Codec/FFmpeg.hs @@ -2,7 +2,7 @@ -- | Interface to initialize FFmpeg, decode video files, encode video -- files, and convert decoded image frames to JuicyPixels images. module Codec.FFmpeg (-- * Initialization - initFFmpeg, + initFFmpeg, setLogLevel, -- * Decoding imageReader, imageReaderTime, imageReaderT, imageReaderTimeT, @@ -16,14 +16,22 @@ import Codec.FFmpeg.Encode import Codec.FFmpeg.Enums import Codec.FFmpeg.Juicy import Codec.FFmpeg.Types +import Foreign.C.Types (CInt(..)) foreign import ccall "av_register_all" av_register_all :: IO () foreign import ccall "avdevice_register_all" avdevice_register_all :: IO () --- foreign import ccall "avcodec_register_all" avcodec_register_all :: IO () +-- foreign import ccall "avcodec_register_all" avcodec_register_all :: IO ( --- | Initialize FFmpeg by registering all known codecs. This /must/ --- be called before using other FFmpeg functions. -initFFmpeg :: IO () -initFFmpeg = av_register_all >> avdevice_register_all +foreign import ccall "av_log_set_level" av_log_set_level :: CInt -> IO () + +-- | Log output is sent to stderr. +setLogLevel :: LogLevel -> IO () +setLogLevel (LogLevel l) = av_log_set_level l +-- | Initialize FFmpeg by registering all known codecs. This /must/ be +-- called before using other FFmpeg functions. The debug level is +-- initially set to @quiet@. If you would like the standard ffmpeg +-- debug level, call @setLogLevel avLogInfo@ after @initFFmpeg@. +initFFmpeg :: IO () +initFFmpeg = av_register_all >> avdevice_register_all >> setLogLevel avLogQuiet diff --git a/src/Codec/FFmpeg/Enums.hsc b/src/Codec/FFmpeg/Enums.hsc index 83c7ec1..9581073 100644 --- a/src/Codec/FFmpeg/Enums.hsc +++ b/src/Codec/FFmpeg/Enums.hsc @@ -212,3 +212,16 @@ newtype PacketFlag = PacketFlag CInt deriving (Eq, Bits, Storable) #enum PacketFlag, PacketFlag \ , AV_PKT_FLAG_KEY\ , AV_PKT_FLAG_CORRUPT + +newtype LogLevel = LogLevel CInt deriving (Eq, Bits, Storable) +#enum LogLevel, LogLevel \ + , AV_LOG_QUIET\ + , AV_LOG_PANIC\ + , AV_LOG_FATAL\ + , AV_LOG_ERROR\ + , AV_LOG_WARNING\ + , AV_LOG_INFO\ + , AV_LOG_VERBOSE\ + , AV_LOG_DEBUG\ + , AV_LOG_TRACE\ + , AV_LOG_MAX_OFFSET