| /** |
| * Copyright (C) 2020 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| #include <media/stagefright/FileSource.h> |
| #include <media/stagefright/MediaExtractor.h> |
| #include <media/stagefright/MediaSource.h> |
| #include <media/stagefright/MetaData.h> |
| #include "include/MPEG4Extractor.h" |
| #define CONVERSION_FACTOR_SEC_TO_MICROSEC 1000000 |
| |
| using namespace android; |
| |
| int main(int argc, char **argv) { |
| if(argc < 2) { |
| return EXIT_FAILURE; |
| } |
| const sp<DataSource> dataSource = new FileSource(argv[1]); |
| MediaExtractor *mp4Extractor = new MPEG4Extractor(dataSource.get()); |
| |
| if(!mp4Extractor) { |
| return EXIT_FAILURE; |
| } |
| //seek to 10 seconds in the mp4 file |
| int64_t seekTimeUs = 10 * CONVERSION_FACTOR_SEC_TO_MICROSEC; |
| size_t numTracks = mp4Extractor->countTracks(); |
| sp<IMediaSource> mediaSource; |
| sp<MetaData> metadata; |
| for(size_t i = 0; i < numTracks; ++i) { |
| mediaSource = mp4Extractor->getTrack(i); |
| metadata = mp4Extractor->getTrackMetaData(i, MediaExtractor::kIncludeExtensiveMetaData); |
| MediaSource::ReadOptions options; |
| if (seekTimeUs >= 0) { |
| options.setSeekTo(seekTimeUs, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC); |
| } |
| MediaBuffer *mbuf = nullptr; |
| mediaSource->start(metadata.get()); |
| mediaSource->read(&mbuf, &options); |
| } |
| return EXIT_SUCCESS; |
| } |