acowley / ffmpeg-light

Minimal Haskell bindings to the FFmpeg library
BSD 3-Clause "New" or "Revised" License
66 stars 29 forks source link

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

Closed plredmond closed 9 months ago

plredmond commented 9 months ago

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:

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

plredmond commented 9 months ago

Closing this because the bug is not consistently reproducible. I've migrated to using System.Process and just calling the ffmpeg executable. Still using ffmpeg-light for other things though! Thank you :)