Git Product home page Git Product logo

ffmpeg-light's Introduction

Minimal bindings to the FFmpeg library.

Stream frames from an encoded video, or stream frames to a video output file. To read the first frame from an h264-encoded file into a JuicyPixels Maybe DynamicImage,

import Codec.FFmpeg
import Codec.Picture
import Control.Applicative

go :: IO (Maybe DynamicImage)
go = do initFFmpeg
        (getFrame, cleanup) <- imageReader (File "myVideo.mov")
        (fmap ImageRGB8 <$> getFrame) <* cleanup

A demonstration of creating an animation using the Rasterific library may be found in demo/Raster.hs. A weird animated variation of the Rasterific logo is the result:

Animated Rasterific Logo

Note that encoding an animation to a modern video codec like h264 can result in even smaller files. But those files can't be embedded in a README on github.

Tested on OS X 10.9.2 with FFmpeg 2.2.1 installed via homebrew.

Debian and Ubuntu users: Your package manager's ffmpeg package is actually a not-quite-compatible fork of the ffmpeg project. To use ffmpeg-light, run the included ffmpeg-ubuntu-compile.sh script as regular (non-root) user. This builds the ffmpeg libraries locally. Configure your projects that depend on ffmpeg-light with a modified PKG_CONFIG_PATH:

PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" cabal configure --disable-shared my-project

There are signs that the next Ubuntu release will come with the original ffmpeg and development packages.

Build Status

ffmpeg-light's People

Contributors

acowley avatar diegonolan avatar expipiplus1 avatar gelisam avatar imalsogreg avatar jonascarpay avatar jtdaugherty avatar lancelet avatar owickstrom avatar proger avatar tommd avatar traviswhitaker avatar tristancacqueray avatar waldheinz avatar wowofbob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffmpeg-light's Issues

Error in ffmpeg-ubuntu-compile.sh

hi, when I try to use the script and reaches the line 54 I have this error.
Is there something I am doing wrong?

Warning: The install command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-install
command or the legacy v1-install alias as new-style projects will become the
default in the next version of cabal-install. Please file a bug if you cannot
replicate a working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] next goal: ffmpeg-light (user goal)
[__0] rejecting: ffmpeg-light-0.14.0 (conflict: pkg-config package
libswresample-any, not found in the pkg-config database)
[__0] rejecting: ffmpeg-light-0.13.0, ffmpeg-light-0.12.2.2,
ffmpeg-light-0.12.2.1, ffmpeg-light-0.12.1.0, ffmpeg-light-0.12.0.1,
ffmpeg-light-0.12.0, ffmpeg-light-0.11.3, ffmpeg-light-0.11.1,
ffmpeg-light-0.11.0, ffmpeg-light-0.10.0, ffmpeg-light-0.9.0,
ffmpeg-light-0.8.2, ffmpeg-light-0.8.1, ffmpeg-light-0.8,
ffmpeg-light-0.7.1.1, ffmpeg-light-0.7.1, ffmpeg-light-0.7, ffmpeg-light-0.6,
ffmpeg-light-0.5, ffmpeg-light-0.4, ffmpeg-light-0.3.1, ffmpeg-light-0.3.0.1,
ffmpeg-light-0.3, ffmpeg-light-0.2.0.1, ffmpeg-light-0.2,
ffmpeg-light-0.1.0.1, ffmpeg-light-0.1.0.0, ffmpeg-light-0.12.2.0 (constraint
from user target requires ==0.14.0)
[__0] fail (backjumping, conflict set: ffmpeg-light)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ffmpeg-light```

Can't encode to jpeg, mjpeg codec refuses to accept `yuv420p` pixel format

Jpeg output is broken for me on Debian 11.

Example: take Transcode.hs from the demo folder and replace line 34 with below to specify jpeg output.
let ep = FF.EncodingParams (fromIntegral w) (fromIntegral h) 30 (Just FF.avCodecIdMjpeg) Nothing "" (Just "mjpeg")

This is what I get:

$ ./Transcode in.jpg out.jpg
[swscaler @ 0x26777c0] deprecated pixel format used, make sure you did set range correctly
[mjpeg @ 0x26923c0] Specified pixel format yuv420p is invalid or not supported
Transcode: Couldn't open codec
CallStack (from HasCallStack):
  error, called at src/Codec/FFmpeg/Encode.hsc:325:21 in ffmpeg-light-0.14.0-BlGBxINPYl8FPzWDcKbKCe:Codec.FFmpeg.Encode

compared to the what actual ffmpeg says when you specify yuv420p and jpeg:

$ ffmpeg -loglevel debug -i in.jpg -pix_fmt yuv420p out.jpg
[graph 0 input from stream 0:0 @ 0x5626d1d602c0] Setting 'pix_fmt' to value '14'
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
[format @ 0x5626d1d61080] Setting 'pix_fmts' to value 'yuvj420p'
[swscaler @ 0x5626d1dccc00] deprecated pixel format used, make sure you did set range correctly

FFmpeg auto-selects yuvj420p over yuv420p because apparently yuv420p has the wrong color range for jpeg.

I found these lines in my copy of /usr/include/x86_64-linux-gnu/libavutil/pixfmt.h

AV_PIX_FMT_YUVJ420P,  ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting color_range
AV_PIX_FMT_YUVJ422P,  ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting color_range
AV_PIX_FMT_YUVJ444P,  ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting color_range

but I couldn't find a way to use those colorspaces or set the color range here.

Encoder timebase is not set. Couldn't open codec.

Hey,
I tried running the example code (demo/Main.hs), but for some reason ffmpeg can't open codecs:

[libx264 @ 0x7fa493028400] The encoder timebase is not set.
ffmpegtest: Couldn't open codec

I'm using OS X 10.11.5, and homebrew installed ffmpeg version 3.1.3.

Opening a H.264 stream from a URL

At work I'm planning to decode H.264 streams from camera's and I hope I can use your library for that.

The first goal is to open a URL of the H.264 stream. I noticed that the InputSource type only has a File and Camera constructor:

  data InputSource = File FilePath | Camera String CameraConfig

We probably need a separate URL InputSource.

@TomMD, it was mentioned by @acowley to add you to this issue because you recently added the InputSource support. He also mentioned this link to an example of opening a video stream from a URL:

http://stackoverflow.com/questions/23020294/c-ffmpeg-api-get-video-stream-from-https-link

Drop unused `either` dependency

It seems like the either trans. instances were replaced (#39) a long time ago and at this moment there is no any usage of either package at all
I was able to compile the latest version of this package with cabal either dep. dropped
Please check out if the dependency can be dropped

ffmpeg-light install issue (lzma)

ubuntu 14.04
ghc 7.8.4
cabal 1.22
lzma 9.22

$ cabal install ffmpeg-light
...
...
Configuring ffmpeg-light-0.8.1...
cabal: Missing dependency on a foreign library:
* Missing C library: lzma
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
Failed to install ffmpeg-light-0.8.1
cabal: Error: some packages failed to install:
ffmpeg-light-0.8.1 failed during the configure step. The exception was:
ExitFailure 1

$ whereis lzma
lzma: /usr/bin/lzma /usr/bin/X11/lzma /usr/include/lzma /usr/share/man/man1/lzma.1.gz

$ lzma
lzma        lzma_alone  lzmainfo   

There are some instructions about additional flags to cabal but I'm not sure how to use them. Is StackOverflow better place for this kind of issue?

Allow reading from stdin and sockets

I'd like to use imageReader to get frames from stdin.

Perhaps, a generic way of reading from any System.IO.Handle would be even better.

Maybe, something like this:

import System.IO (Handle)

data InputSource = File FilePath
                 | Camera String CameraConfig
                 | InputHandle Handle
                 deriving (Eq, Show) -- System.IO.Handle doesn't have instances for Read and Ord

Or is there another way to read from stdin?

ResterDemo build

How can I build RasterDemo?

If I configure it like PKG_CONFIG_PATH="$DIR/ffmpeg_build/lib/pkgconfig" cabal configure --disable-shared -fBuildRasterDemo it claims

cabal: At least the following dependencies are missing:
Rasterific >=0.3

but after cabal build it builds first example (-fBuildDemo)

Add InputSource for reading custom buffer

There is an example in the FFmpeg documentation describing how to use a custom buffer as input, instead of a file or device.

Would it be possible to wrap the relevant ffmpeg api-functions used in the example?
Perhaps support a new InputSource type, like Buffer ByteString (Lazy, strict or something conduit/pipe/stream-like?)

I would be glad to help, here, as I have a use-case where extracting frames from videos in a streaming fashion is desirable (preferably without touching the disk)

Is it possible to append a frame to an existing video?

I'd like to append a new frame to the end of an existing video file. I'm not sure if this is possible (but I haven't figured out how), not yet possible (but worth me working on a PR to support it), or impossible (not really how ffmpeg works, or would require a major rewrite of this package or something).

I first tried simply opening an existing video with imageWriter and writing a single frame, which overwrites the whole video with just the new frame. I'm assuming this is the expected behavior.

Next, I tried reading all the frames of the existing video with imageReader, and then writing them all back out, plus the new frame, with imageWriter. This almost works, but with two significant problems. First, it's obviously very slow, but also, my method of grabbing all the frames seems to drop 2 of them? Given a 125 frame video, it reads 123 frames, and then adds my new frame, so every time I run the function my video actually ends up one frame shorter. I haven't yet determined which frames I'm failing to read.

Here's my code (somewhat simplified so I'm not 100% sure it compiles, but hopefully it gets the point across):

addFrame :: Image a -> IO ()
addFrame image = do
  initFFmpeg  
  (reader, cleanup) <- imageReader (File "/path/to/video.mp4") :: IO (IO (Maybe (Image PixelRGB8)), IO ())
  oldFrames <- unfoldM reader
  cleanup
  let newFrames = oldFrames ++ [image]
  writer <- imageWriter (defaultParams width height) "/path/to/video.mp4" :: IO (Maybe (Image PixelRGB8) -> IO ())
  mapM writer (map Just newFrames)
  writer Nothing
  return ()

So I have two questions:

  1. Why does unfoldM reader miss two frames of the video? If I run this function repeatedly, video.mp4 gets one frame shorter every time. And if I check the number of frames with ffmpeg before running the function and then print length oldFrames, it's always 2 frames shorter than what ffmpeg reported.
  2. Is there a way to avoid this and directly append the new frame? If it's possible in theory I'd be willing to work on a PR, but if it's out of the scope of this package then I'll find another way.

First frame of video is not at time zero, resulting in initial "black frame"

I'm creating movie files by emitting frames using imageWriter in ffmpeg-lightversion 0.9, ffmpeg version 2.8.1_1 installed via Homebrew, and GHC 7.10.2. When I play movies generated this way, the first frame appears to be black. Digging in a bit more using the approach suggested at http://superuser.com/a/559205, I ran ffprobe -show_frames on the video and I see this for the first frame:

[FRAME]
media_type=video
stream_index=0
key_frame=1
pkt_pts=507
pkt_pts_time=0.033008
pkt_dts=507
pkt_dts_time=0.033008
best_effort_timestamp=507
best_effort_timestamp_time=0.033008
...

This seems to suggest the reason for the apparent "black frame" is because the first frame I output gets put at time 0.033008 rather than 0.0 (which is what I see when I inspect a few videos I have from other sources that don't suffer from this problem).

I'm using defaultParams to set up imageWriter. Here's some info on my installation:

$ ffmpeg
ffmpeg version 2.8.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 7.0.0 (clang-700.0.72)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.1_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100

Support for access to input devices (libavdevice)

I have patched ffmpeg to support input devices, such as avfoundation. If I bother to polish it would you accept a pull? It would probably result in changing imageReader to something like:

data Input = File FIlePath | Camera String
imageReader :: Input -> IO (IO PictureThing, IO ())

testDecode in ghci causes segfault

ffmpeg-light-0.8.1 installed with cabal

When I do:
cd ~/.cabal/packages/hackage.haskell.org/ffmpeg-light/0.8.1/demo
runhaskell Main.hs "my_video.mp4"

it exits without messages, no files get generated. If run in ghci testEncode works fine, but when I do testDecode "my_video.mp4" it exits with segmentation fault. The path to file is correct, write premissions are correct.

ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
built on Nov 14 2014 12:17:00 with gcc 4.8 (SUSE Linux)
configuration: --shlibdir=/usr/lib64 --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib64 --enable-shared --disable-static --enable-debug --disable-stripping --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -fPIC -I/usr/include/gsm' --enable-gpl --enable-x11grab --enable-version3 --enable-pthreads --enable-avfilter --enable-libpulse --enable-libvpx --enable-libopus --enable-libass --enable-libx265 --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libxvid --enable-libx264 --enable-libschroedinger --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-postproc --enable-libdc1394 --enable-librtmp --enable-libfreetype --enable-avresample --enable-libtwolame --enable-libvo-aacenc --enable-gnutls
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.100 / 4. 11.100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100

Support ffmpeg 3.x

The new 3.x version has been released with much API breakage (stated up front at release time, I haven't looked myself). Eventually, after many package systems have moved to including 3.x, we should update this package to the new API.

Requires 'pkg-config' during installation

I'm newbie in haskell development.
I've made new stack project and added these lines:

# stack.yaml

extra-deps:
- ffmpeg-light-0.12.1.0
# package.yaml

dependencies:
- ffmpeg-light

then I ran:

stack build

and got this error:

Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2: The program 'pkg-config' version >=0.9.0 is required but it could not be found.

I'm on macOS 10.13.4

Inconsistent crash while encoding audio -- FFmpegException "Error while writing audio frame : Invalid argument"

I'm seeing an inconsistent (difficult to reproduce) crash while encoding audio that prints out the following error.

FFmpegException "Error while writing audio frame : Invalid argument"

This error seems to come from Codec.FFmpeg.Encode.hsc, just before a call to av_interleaved_write_frame.

This is in a program based off the audio demo that takes multiple filenames on the command-line and writes one after another into the same resampler (frame by frame, draining the resampler into the audioWriter after each frame). The program is used in a multithreaded context, but all the FFmpeg code is in this one "cat audio files" function. I have turned on debug logging and found the crash is sometimes preceded by this line:

[ipod @ 0x25e6400] pts (156837888) < dts (445413786) in stream 0                                                                                                                   

Or by this one:

[ipod @ 0x25ffb00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 19456 >= 18434

While it's possible the input data is invalid, these lines aren't consistently printed before a crash, and so it's not conclusive.

Based on google searches about av_interleaved_write_frame giving the error "invalid argument" I've tried certain mitigations:

  • One page mentioned this in the context of multithreading, and suggested mutex. I tried removing the -threaded compiler option and wrapping all FFmpeg code with a withMVar/MVar () based mutex. This hasn't eliminated the error.
  • Another page suggested that you check the layout/rate/format of each audio frame you read, before writing it to a resampler, to ensure the parameters match what the resampler expects. I've implemented this, but it hasn't eliminated the error.

I'll post the audio-cat function later if there's interest.

Use av_strerror for FFmpeg error messages?

Hi! First of all, thanks for the library! I've just started using it to process and chop up videos and it's working nicely so far.

I had some trouble opening files and the error message thrown by readFile isn't very helpful. As seen in the following error message, it prints the numeric error code.

*** Exception: user error (ffmpeg failed opening file: -1094995529)
CallStack (from HasCallStack):
  error, called at src/Codec/FFmpeg/Juicy.hs:128:27 in ffmpeg-light-0.12.1.0-cf5adea21c23b3bea23fc219b84d9eaa2476dc02798ac7442955da596dc4c1b2:Codec.FFmpeg.Juicy

Do you think ffmpeg-light and the openFile function could use the av_strerror function in FFmpeg to map errors into strings? I could take a stab at sending a PR, but I'm not very experienced with C FFI in Haskell, so it might not be solid.

Thanks!

Build fails with ffmpeg version 5.1

When building my project with stack I get this:

ffmpeg-light> configure
ffmpeg-light> Configuring ffmpeg-light-0.14.1...
ffmpeg-light> build
ffmpeg-light> Preprocessing library for ffmpeg-light-0.14.1..
ffmpeg-light> In file included from /usr/include/strings.h:23,
ffmpeg-light>                  from /usr/include/string.h:462,
ffmpeg-light>                  from /usr/include/libavutil/common.h:40,
ffmpeg-light>                  from /usr/include/libavutil/avutil.h:296,
ffmpeg-light>                  from /usr/include/libavcodec/codec.h:26,
ffmpeg-light>                  from /usr/include/libavformat/avformat.h:313,
ffmpeg-light>                  from Probe.hsc:34:
ffmpeg-light> Probe.hsc: In function ‘main’:
ffmpeg-light> /home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/template-hsc.h:75:24: error: ‘AVStream’ has no member named ‘codec’
ffmpeg-light>    75 |                 (long) offsetof (t, f));
ffmpeg-light>       |                        ^~~~~~~~
ffmpeg-light> /tmp/stack-9b4872e63d551bb1/ffmpeg-light-0.14.1/Probe.hsc:99:5: note: in expansion of macro ‘hsc_peek’
ffmpeg-light> /tmp/stack-9b4872e63d551bb1/ffmpeg-light-0.14.1/Probe.hsc:106:15: error: unknown type name ‘AVCodecContext’
ffmpeg-light> /tmp/stack-9b4872e63d551bb1/ffmpeg-light-0.14.1/Probe.hsc:106:5: note: in expansion of macro ‘hsc_peek’
ffmpeg-light> /tmp/stack-9b4872e63d551bb1/ffmpeg-light-0.14.1/Probe.hsc:111:15: error: unknown type name ‘AVCodecContext’
ffmpeg-light> /tmp/stack-9b4872e63d551bb1/ffmpeg-light-0.14.1/Probe.hsc:111:5: note: in expansion of macro ‘hsc_peek’
ffmpeg-light> compiling .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/Codec/FFmpeg/Probe_hsc_make.c failed (exit code 1)
ffmpeg-light> command was: /usr/bin/gcc -c .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/Codec/FFmpeg/Probe_hsc_make.c -o .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/Codec/FFmpeg/Probe_hsc_make.o -fno-stack-protector -fno-stack-protector -fuse-ld=gold -D__GLASGOW_HASKELL__=806 -Dlinux_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Isrc -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/src -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/autogen -I.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/global-autogen -include .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/autogen/cabal_macros.h -I/home/gusten/.stack/snapshots/x86_64-linux-tinfo6/33a5db3e2aa99c9b06b88f2640fe1d160993bc00a487d3137c5bcff1f4cdad0e/8.6.5/lib/x86_64-linux-ghc-8.6.5/JuicyPixels-3.3.5-I4RLYE996p5IaEhK0bEaLb/include -I/home/gusten/.stack/snapshots/x86_64-linux-tinfo6/33a5db3e2aa99c9b06b88f2640fe1d160993bc00a487d3137c5bcff1f4cdad0e/8.6.5/lib/x86_64-linux-ghc-8.6.5/vector-0.12.1.2-53ZStWTkIih2KWMAErdIai/include -I/home/gusten/.stack/snapshots/x86_64-linux-tinfo6/be51fdc41698c46cbccfe43fee2c42396b75be8f4d6ed216807ec95c2a9452f4/8.6.5/lib/x86_64-linux-ghc-8.6.5/primitive-0.6.4.0-ILgywxtLpvnAOlEISPpP5b/include -I/home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/bytestring-0.10.8.2/include -I/home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/base-4.12.0.0/include -I/home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/integer-gmp-1.0.2.0/include -I/home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/include -I/home/gusten/.stack/programs/x86_64-linux/ghc-tinfo6-8.6.5/lib/ghc-8.6.5/include/
Progress 1/2

--  While building package ffmpeg-light-0.14.1 (scroll up to its section to see the error) using:
      /home/gusten/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

The exact package used is the arch linux ffmpeg-2:5.1.2-1.

use of deprecated FFmpeg API

Building with FFmpeg 3.0.2

libavcodec/avcodec.h: struct AVPicture

use AVFrame or imgutils functions instead
(controlled with FF_API_AVPICTURE directive)

libavcodec/avcodec.h: struct AVCodecContext
int b_frame_strategy;

use encoder private options instead
(controlled with FF_API_PRIVATE_OPT directive)

Audio Support

It might require more dependencies, but supporting audio seems like an obvious next step. I don't have any specifics here, such as a pre-existing audio frame type already available on Hackage, so this requires quite a bit of fleshing out.

ffmpeg 'framrate not set' error while writing

Running your demo program in encode-mode, I get:

[mpeg4 @ 0x2459960] framerate not set
testff: Couldn't open codec

Failing on Ubuntu 14.04, ffmpeg 2.5.2 built from source

No problem with arch, ffmpeg 2.4.3 from the arch repr with the same config options.

Not urgent, I have a work-around for myself for now. Will give it some more thought.

Webcam example

Hi,

When I try the webcam example with:

./demo cam

I get:

demo: user error (ffmpeg failed opening file: No such file or directory)

If I enable debugging in Main.hs, I see:

Could not open framebuffer device '0:0': No such file or directory

Any advice?

Support more Juicy pixel formats

We should support at least Y8 and YUV formats. We can have a toJuicy function, and frameWriterJuicy that takes an Image type.

imageReader reads all but two frames of a video

imageReader reads all but two frames when attempting to read all frames of a video, regardless of the video length. I'm not yet sure which frames are not being read.

OS: NixOS 20.03
ffmpeg version: 3.4.7

Things I would like to try but haven't yet: other OSes, other ffmpeg versions, other video types, and making a short video with numbered frames so I can save the images and see which frames are dropped.

Steps to Reproduce

Make sure you have the following packages installed: ffmpeg-light, JuicyPixels, monad-loops.

  1. Make DroppedFrames.hs and add the following:
import Codec.FFmpeg
import Codec.Picture
import Control.Monad.Loops
import Data.Maybe

readAllFrames :: IO Int
readAllFrames = do
 initFFmpeg
 setLogLevel avLogTrace
 (reader, cleanup) <- imageReader (File "pulse.mov") :: IO (IO (Maybe (Image PixelRGB8)), IO ())
 frames <- unfoldM reader
 return $ length frames
  1. Generate pulse.mov, either by building the demo application and running with no arguments, or loading /demo/Main.hs in ghci and running testEncode.
  2. Run ffmpeg -i pulse.mov -map 0:v:0 -c copy -f null -, and in the second to last line of output you'll see frame= 600, indicating that this video has 600 frames.
  3. Load DroppedFrames.hs in ghci and run readAllFrames. The output is 598, indicating imageReader only got 598 frames out of this video.

Here's a gist with the output of ffmpeg and readAllFrames with log level set to trace: https://gist.github.com/burkaman/0bb1e18b6769eed13cdf521c240222c4

Control over log output

When I run programs using ffmpeg-light I get ffmpeg log output in the terminal. Is there any way to get more control over ffmpeg's log output? I'm using this in an application that also does curses-style terminal manipulation so any ffmpeg output is garbled. I could redirect stderr, but what I really want is to get more control over the library so I can use stderr for my own purposes.

frameReaderTime giving wrong timestamps

frameReaderTime is giving the wrong timestamps for some H.264 videos. I think this is the case because it is getting the time_base from the AVCodecContext. The time_base of the AVStream seems to give me the correct values. Is there a way to fix this?

audio-extract example doesn't work on wav files

I'm trying to use the audio-extract demo to copy audio from audio file to audio file. It works when targetting an mp3, but not when targetting a wav.

lc@earthrealm ~/ffmpeg-light (master) [1]> ./result/bin/audio-extract foo.mp3 bar.mp3
bitrate : 128000
sample rate : 44100
sample format : 8
channel layout : 3
channel count : 2
AVCodecID 86017
lc@earthrealm ~/ffmpeg-light (master)> ./result/bin/audio-extract foo.mp3 bar.wav
bitrate : 128000
sample rate : 44100
sample format : 8
channel layout : 3
channel count : 2
AVCodecID 65536
audio-extract: FFmpegException "Could not open audio codec : Invalid argument"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.