-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathAvioReadCallback.cs
More file actions
38 lines (32 loc) · 1.41 KB
/
Copy pathAvioReadCallback.cs
File metadata and controls
38 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.IO;
namespace FFmpeg.Sharp.Example
{
/// <summary>
/// Maps to FFmpeg example: avio_read_callback.c
/// Demonstrate reading media from an in-memory buffer via a custom AVIOContext read callback.
/// The entire input file is read into a managed byte array, then an AVIOContext is created
/// with a read callback that serves bytes from that buffer — no disk access after the initial read.
/// </summary>
public class AvioReadCallback : ExampleBase
{
public AvioReadCallback() { Index = 2; Enable = false; }
public override void Execute()
{
var inFile = args.Length > 0 ? args[0] : "input.mp4";
// Slurp the whole file into a managed byte array.
var buffer = File.ReadAllBytes(inFile);
// Open a MemoryStream backed by that buffer.
// MediaDemuxer.Open(Stream) creates an AVIOContext with read/seek callbacks internally.
using var ms = new MemoryStream(buffer);
using var demuxer = MediaDemuxer.Open(ms);
demuxer.DumpFormat();
Console.WriteLine($"Number of streams: {demuxer.Count}");
for (int i = 0; i < demuxer.Count; i++)
{
var st = demuxer[i];
Console.WriteLine($" Stream #{i}: codec_type={st.CodecparRef.codec_type}, codec_id={st.CodecparRef.codec_id}");
}
}
}
}