rosenbjerg / FFMpegCore

A .NET FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your C# applications
MIT License
1.61k stars 290 forks source link

Time parsing error when transcoding long than 24 hours #482

Open kuochenwoo opened 10 months ago

kuochenwoo commented 10 months ago

When using ffmpegCore to transcoding for longer than 24hour, the following error is thrown:

Unhandled exception. System.OverflowException: The TimeSpan string '24:00:00.00' could not be parsed because at least one of the numeric components is out of range or contains too many digits.
   at System.Globalization.TimeSpanParse.TimeSpanResult.SetOverflowFailure()
   at System.Globalization.TimeSpanParse.ProcessTerminal_HMS_F_D(TimeSpanRawInfo& raw, TimeSpanStandardStyles style, TimeSpanResult& result)
   at FFMpegCore.FFMpegArgumentProcessor.ErrorData(Object sender, String msg)
   at System.Diagnostics.AsyncStreamReader.FlushMessageQueue(Boolean rethrowInNewThread)
--- End of stack trace from previous location ---
   at System.Diagnostics.AsyncStreamReader.<>c.<FlushMessageQueue>b__18_0(Object edi)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

We are using the latest versions of ffmepgCore of v5.1.0 And the related code snippet is:

private async Task<bool> FfmpegExecTask(string ffmpegInputOptions, string ffmpegOutputOptions, string codec
{
    return await FFMpegArguments
                            .FromPipeInput(this.RawVideoPipeWriter, options => options
                            .WithCustomArgument(ffmpegInputOptions))
                            .OutputToUrl(string.Empty, args => args
                            .WithVideoCodec(FFMpeg.GetCodec(codec))
                            .WithCustomArgument(ffmpegOutputOptions)
                            .UsingMultithreading(false)
                            .WithFastStart()
                            )
                            .NotifyOnProgress((time) => logger.Verbose($"Progress {this.StreamName}: {time}"))
                            .NotifyOnOutput((string output) =>
                            {
                                logger.Verbose($"RtspServer Notify output Stream {this.StreamName}: {output}");
                            })
                            .NotifyOnError((err) => { logger.Verbose($"RtspServer STDError Stream {this.StreamName}: {err}"); })
                            .CancellableThrough(cancellationToken, this.FfmpegTcpTimeout)
                            .ProcessAsynchronously().ConfigureAwait(false);
}

Similar issue is also mentioned in: https://github.com/rosenbjerg/FFMpegCore/pull/170#issuecomment-1046876101

I guess this error is related to https://github.com/rosenbjerg/FFMpegCore/blob/main/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs#L266 If the registered callback function tries to parse the TimeSpan string larger than “24:00:00”, then the parsing error would be thrown.

alahane-techtel commented 2 months ago

We are facing the same issue too :(

alahane-techtel commented 2 months ago

Hi Maintainers, I've proposed a PR above. Can someone plz review it?

alahane-techtel commented 2 months ago

is this repo maintained? cant see any release or checkins since 9 months :(

stcyuvoronin commented 1 month ago

Hi! We met this issue too. It would be great if you fixed this using the pull request above :)