-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add three seek improvements which increase the range of file formats that can be directly decoded through FFmpeg and thus reduce the likelihood that audio proxies are required: - report container duration when stream duration is unavailable, - consider non-zero start times, - handle cases where seeks end up too early.
- Loading branch information
1 parent
2d531d0
commit 682cf2d
Showing
9 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace Aurio.FFmpeg.UnitTest | ||
{ | ||
public class FFmpegReaderTests | ||
{ | ||
/// <summary> | ||
/// MKV does not carry individual stream lenghts, only a total container length. | ||
/// </summary> | ||
[Fact] | ||
public void MKV_LengthFromContainerAvailable() | ||
{ | ||
var fileInfo = new FileInfo("./Resources/sine440-44100-16-mono-200ms.mkv"); | ||
|
||
var reader = new FFmpegReader(fileInfo, Type.Audio); | ||
|
||
Assert.NotEqual(long.MinValue, reader.AudioOutputConfig.length); | ||
} | ||
|
||
[Fact] | ||
public void TS_NonZeroStartTime() | ||
{ | ||
var fileInfo = new FileInfo("./Resources/sine440-44100-16-mono-200ms.ts"); | ||
var reader = new FFmpegReader(fileInfo, Type.Audio); | ||
var sourceBuffer = new byte[reader.FrameBufferSize]; | ||
var startTimeSecs = 2000; | ||
|
||
reader.ReadFrame(out long readerPosition, sourceBuffer, sourceBuffer.Length, out _); | ||
|
||
Assert.Equal( | ||
startTimeSecs * reader.AudioOutputConfig.format.sample_rate, | ||
readerPosition | ||
); | ||
} | ||
|
||
[Fact] | ||
public void SignalEOF() | ||
{ | ||
var fileInfo = new FileInfo("./Resources/sine440-44100-16-mono-200ms.ts"); | ||
var reader = new FFmpegReader(fileInfo, Type.Audio); | ||
var sourceBuffer = new byte[reader.FrameBufferSize]; | ||
int result; | ||
|
||
// Read over all frames (seeking does not work here due to short stream) | ||
do | ||
{ | ||
result = reader.ReadFrame(out _, sourceBuffer, sourceBuffer.Length, out _); | ||
} while (result > 0); | ||
|
||
// -1 signals EOF | ||
Assert.Equal(-1, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters