1MP4(3) MP4 File Format Library MP4(3)
2
3
4
6 MP4ReadSample - Read a track sample
7
9 #include <mp4.h>
10
11 bool MP4ReadSample(
12 MP4FileHandle hFile,
13 MP4TrackId trackId,
14 MP4SampleId sampleId,
15 u_int8_t** ppBytes,
16 u_int32_t* pNumBytes,
17 MP4Timestamp* pStartTime = NULL,
18 MP4Duration* pDuration = NULL,
19 MP4Duration* pRenderingOffset = NULL,
20 bool pIsSyncSample = NULL
21 );
22
24 hFile Specifies the mp4 file to which the operation applies.
25
26 trackId
27 Specifies the track to which the operation applies.
28
29 sampleId
30 Specifies which sample is to be read. Caveat: the first sample
31 has id 1 not 0.
32
33 ppBytes
34 Pointer to the pointer to the sample data. See DESCRIPTION for
35 details on this argument.
36
37 pNumBytes
38 Pointer to variable that will be hold the size in bytes of the
39 sample.
40
41 pStartTime
42 If non-NULL, pointer to variable that will receive the starting
43 timestamp for this sample. Caveat: The timestamp is in the track
44 timescale.
45
46 pDuration
47 If non-NULL, pointer to variable that will receive the duration
48 for this sample. Caveat: The duration is in the track timescale
49 units.
50
51 pRenderingOffset
52 If non-NULL, pointer to variable that will receive the rendering
53 offset for this sample. Currently the only media type that needs
54 this feature is MPEG video. Caveat: The offset is in the track
55 timescale units.
56
57 pIsSyncSample
58 If non-NULL, pointer to variable that will receive the state of
59 the sync/random access flag for this sample.
60
62 Upon success, true (1). Upon an error, false (0).
63
65 MP4ReadSample reads the specified sample from the specified track. Typ‐
66 ically this sample is then decoded in a codec dependent fashion and
67 rendered in an appropriate fashion.
68
69 The argument, ppBytes, allows for two possible approaches for buffer‐
70 ing:
71
72 If the calling application wishes to handle its own buffering it can
73 set *ppBytes to the buffer it wishes to use. The calling application is
74 responsible for ensuring that the buffer is large enough to hold the
75 sample. This can be done by using either MP4GetSampleSize() or MP4Get‐
76 TrackMaxSampleSize() to determine before-hand how large the receiving
77 buffer must be.
78
79 If the value of *ppBytes is NULL, then an appropriately sized buffer is
80 automatically malloc'ed for the sample data and *ppBytes set to this
81 pointer. The calling application is responsible for free'ing this mem‐
82 ory.
83
84 The last four arguments are pointers to variables that can receive
85 optional sample information.
86
87 Typically for audio none of these are needed. MPEG audio such as MP3 or
88 AAC has a fixed sample duration and every sample can be accessed at
89 random.
90
91 For video, all of these optional values could be needed. MPEG video can
92 be encoded at a variable frame rate, with only occasional random access
93 points, and with "B frames" which cause the rendering (display) order
94 of the video frames to differ from the storage/decoding order.
95
96 Other media types fall between these two extremes.
97
99 MP4(3)
100
101
102
103Cisco Systems Inc. Version 0.9 MP4(3)