繁体   English   中英

Haskell - 将多个图像转换为视频文件 - ffmpeg-lights'frameWriter-function失败

[英]Haskell - Converting multiple images into a video file - ffmpeg-lights' frameWriter-function fails

情况
目前我正在开发一个图像处理应用程序,它使用ffmpeg-light来获取给定视频文件的所有帧,以便程序之后可以对每个帧应用灰度校正以及边缘检测算法。

在友好的stackoverflowers的帮助下,我能够设置一个方法,能够使用ffmpeg-lights的frameWriter函数将多个图像转换为一个视频文件。

问题
应用程序运行得很好,直到它命中frameWriter函数,我不知道为什么没有错误或抛出异常消息。 (OS:Win 10 64bit)

我尝试了什么?
我试过了..
- 不同版本的ffmpeg(从3.2到3.4)。
- 使用命令行测试ffmpeg.exe是否缺少任何编解码器,但我尝试过的任何转换都有效。
- 不同的EncodingParams-combinations:like .. EncodingParams width height fps(Nothing)(Nothing)“medium”


不幸的是,以上都没有工作,网络缺乏针对该特定案例的信息。 也许我错过了一些必要的东西(如ghc标志或其他东西)或在我的代码中犯了更大的错误。 这就是为什么我要问你:你对我有什么建议/意见吗?

Haskell包
- ffmpeg-light-0.12.0
- JuicyPixels-3.2.8.3


{--------------------------------------------------------------------------------------------
 Applies "juicyToFFmpeg'" and "getFPS" to a list of images and saves the output-video
 to a user defined location.
---------------------------------------------------------------------------------------------}     
saveVideo :: String -> [Image PixelYA8] -> Int -> IO ()
saveVideo path imgs fps = do
         -- program stops after hitting next line --
         frame <- frameWriter ep path
         ------------------------------------------------
         Prelude.mapM_ (frame . Just) ffmpegImgs 
         frame Nothing
         where ep = EncodingParams width height fps (Just avCodecIdMpeg4) (Just avPixFmtGray8a) "medium"
               width      = toCInt $ imageWidth  $ head imgs
               height     = toCInt $ imageHeight $ head imgs
               ffmpegImgs = juicyToFFmpeg' imgs
               toCInt x   = fromIntegral x :: CInt

{--------------------------------------------------------------------------------------------
 Converts a single image from JuicyPixel-format to ffmpeg-light-format. 
---------------------------------------------------------------------------------------------}      
juicyToFFmpeg :: Image PixelYA8 -> (AVPixelFormat, V2 CInt, Vector CUChar)
juicyToFFmpeg img = (avPixFmtGray8a, V2 (toCInt width) (toCInt height), ffmpegData)
                  where toCInt   x   = fromIntegral x :: CInt
                        toCUChar x   = fromIntegral x :: CUChar
                        width        = imageWidth img
                        height       = imageHeight img
                        ffmpegData   = VS.map toCUChar (imageData img)

{--------------------------------------------------------------------------------------------
 Converts a list of images from JuicyPixel-format to ffmpeg-light-format. 
---------------------------------------------------------------------------------------------}                        
juicyToFFmpeg' :: [Image PixelYA8] -> [(AVPixelFormat, V2 CInt, Vector CUChar)]
juicyToFFmpeg' imgs = Prelude.foldr (\i acc -> acc++[juicyToFFmpeg i]) [] imgs

{--------------------------------------------------------------------------------------------
 Simply calculates the FPS for image-to-video conversion.
 -> frame :: (Double, DynamicImage) where Double is a timestamp of when it got extracted 
---------------------------------------------------------------------------------------------}
getFPS :: [(Double, DynamicImage)] -> Int
getFPS frames = div (ceiling $ lastTimestamp - firstTimestamp) frameCount :: Int
              where firstTimestamp = fst $ head frames
                    lastTimestamp  = fst $ last frames
                    frameCount     = length frames

我怀疑你是否有与Windows环境有关的问题以及来自Haskell的ffmpeg的使用(即ffmpeg-simple)

我能够在Ubuntu 16.04上成功编译和运行您的模块,尽管我确实从ffmpeg获得了运行时错误:

$ ./main
[NULL @ 0x1ea6900] Unable to find a suitable output format for 'foo.avi'
main: Couldn't allocate output format context
CallStack (from HasCallStack):
  error, called at src/Codec/FFmpeg/Encode.hs:214:17 in ffmpeg-light-
0.12.0-DYHyy7pUAhZ7WHcd6Y2mLO:Codec.FFmpeg.Encode

似乎上面的错误可以通过调整一些ffmpeg参数来修复,但由于这不是您遇到的问题,我决定不再进一步调试它。

以防我的main

main :: IO ()
main = do
  Right (ImageYA8 img) <- readPng "foo_ya.png"
  saveVideo "foo.avi" (replicate 10 img) 10

我在Windows 7 64位上运行相同的东西,似乎我无法完全满足依赖项。

在Windows上完成编译和依赖项安装:

> stack exec -- pacman -Syu
> stack exec -- pacman -S mingw-w64-x86_64-gtk3
> stack exec -- pacman -S mingw-w64-x86_64-pkg-config
> stack exec -- pacman -S mingw-w64-x86_64-ffmpeg
> stack --install-ghc --resolver lts-9.10 exec --package vector --package JuicyPixels --package ffmpeg-light -- ghc main.hs -O2 -threaded
> stack exec -- main.exe

cmd运行时导致弹出错误( ps只是退出):

无法在动态链接库zlib1.dll中找到过程入口点inflateValidate

我不是Windows上的开发专家,所以我觉得我错过了一些东西。 希望我的尝试至少会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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