1 | #include <stdio.h>
|
---|
2 |
|
---|
3 | #include <Application.h>
|
---|
4 | #include <File.h>
|
---|
5 | #include <MediaFile.h>
|
---|
6 | #include <MediaTrack.h>
|
---|
7 | #include <Bitmap.h>
|
---|
8 |
|
---|
9 | BMediaTrack *GetVideoTrack(BMediaFile &mediaFile, media_format &mf)
|
---|
10 | {
|
---|
11 | for (int32 i = 0; i < mediaFile.CountTracks(); i++) {
|
---|
12 | BMediaTrack *track = mediaFile.TrackAt(i);
|
---|
13 |
|
---|
14 | if (track->EncodedFormat(&mf) >= B_OK) {
|
---|
15 | switch (mf.type) {
|
---|
16 | case B_MEDIA_RAW_VIDEO:
|
---|
17 | case B_MEDIA_ENCODED_VIDEO:
|
---|
18 | return track;
|
---|
19 | }
|
---|
20 | mediaFile.ReleaseTrack(track);
|
---|
21 | }
|
---|
22 | }
|
---|
23 | return NULL;
|
---|
24 | }
|
---|
25 |
|
---|
26 | int main(int argCnt, char **args)
|
---|
27 | {
|
---|
28 | BApplication app("application/x-vnd.Test-App");
|
---|
29 | if (argCnt < 2) return 1;
|
---|
30 | BFile file(args[1], B_READ_ONLY);
|
---|
31 | if (file.InitCheck() < B_OK) return 1;
|
---|
32 | BMediaFile mediaFile(&file);
|
---|
33 | media_format mf;
|
---|
34 | if (mediaFile.InitCheck() < B_OK) return 1;
|
---|
35 | BMediaTrack *videoTrack = GetVideoTrack(mediaFile, mf);
|
---|
36 | if (videoTrack == NULL) return 1;
|
---|
37 |
|
---|
38 | BRect bitmapBounds(
|
---|
39 | 0.0,
|
---|
40 | 0.0,
|
---|
41 | mf.u.encoded_video.output.display.line_width - 1.0,
|
---|
42 | mf.u.encoded_video.output.display.line_count - 1.0
|
---|
43 | );
|
---|
44 |
|
---|
45 | videoTrack->DecodedFormat(&mf);
|
---|
46 | BBitmap bitmap(bitmapBounds, mf.u.raw_video.display.format);
|
---|
47 | if (bitmap.InitCheck() < B_OK) return 1;
|
---|
48 |
|
---|
49 | for (;;) {
|
---|
50 | int64 frameCnt = 0;
|
---|
51 | media_header mh;
|
---|
52 | status_t res = videoTrack->ReadFrames(bitmap.Bits(), &frameCnt, &mh);
|
---|
53 | printf("frameCnt: %lld, mh.start_time: %lld\n", frameCnt, mh.start_time);
|
---|
54 | if (res < B_OK)
|
---|
55 | printf("res: %x\n", res);
|
---|
56 | if (frameCnt <= 0 || res < B_OK)
|
---|
57 | break;
|
---|
58 | }
|
---|
59 |
|
---|
60 | mediaFile.ReleaseTrack(videoTrack); videoTrack = NULL;
|
---|
61 |
|
---|
62 | return 0;
|
---|
63 | }
|
---|