QGMP4Parser.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // QGMP4Parser.h
  2. // Tencent is pleased to support the open source community by making vap available.
  3. //
  4. // Copyright (C) 2020 Tencent. All rights reserved.
  5. //
  6. // Licensed under the MIT License (the "License"); you may not use this file except in
  7. // compliance with the License. You may obtain a copy of the License at
  8. //
  9. // http://opensource.org/licenses/MIT
  10. //
  11. // Unless required by applicable law or agreed to in writing, software distributed under the License is
  12. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  13. // either express or implied. See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #import <Foundation/Foundation.h>
  16. #import "QGMP4Box.h"
  17. @class QGMP4Parser;
  18. @protocol QGMP4ParserDelegate <NSObject>
  19. @optional
  20. - (void)didParseMP4Box:(QGMP4Box *)box parser:(QGMP4Parser *)parser;
  21. - (void)MP4FileDidFinishParse:(QGMP4Parser *)parser;
  22. @end
  23. @interface QGMP4Parser : NSObject
  24. @property (nonatomic, strong) QGMP4Box *rootBox;
  25. @property (nonatomic, strong) NSFileHandle *fileHandle;
  26. @property (nonatomic, weak) id<QGMP4ParserDelegate> delegate;
  27. - (instancetype)initWithFilePath:(NSString *)filePath;
  28. - (void)parse;
  29. - (NSData *)readDataForBox:(QGMP4Box *)box;
  30. - (NSInteger)readValue:(const char*)bytes length:(NSInteger)length;
  31. @end
  32. @interface QGMP4ParserProxy : NSObject
  33. - (instancetype)initWithFilePath:(NSString *)filePath;
  34. @property (nonatomic, assign) NSInteger picWidth; //视频宽度
  35. @property (nonatomic, assign) NSInteger picHeight; //视频高度
  36. @property (nonatomic, assign) NSInteger fps; //视频fps
  37. @property (nonatomic, assign) double duration; //视频时长
  38. @property (nonatomic, strong) NSData *spsData; //sps
  39. @property (nonatomic, strong) NSData *ppsData; //pps
  40. @property (nonatomic, strong) NSArray *videoSamples; //所有帧数据,包含了位置和大小等信息
  41. @property (nonatomic, strong) NSArray *videoSyncSampleIndexes; // 所有关键帧的index
  42. @property (nonatomic, strong) QGMP4Box *rootBox; //mp4文件根box
  43. @property (nonatomic, strong) QGMP4TrackBox *videoTrackBox; //视频track
  44. @property (nonatomic, strong) QGMP4TrackBox *audioTrackBox; //音频track
  45. /** vps */
  46. @property (nonatomic, strong) NSData *vpsData;
  47. /** 视频流编码器ID类型 */
  48. @property (nonatomic, assign) QGMP4VideoStreamCodecID videoCodecID;
  49. - (void)parse;
  50. - (NSData *)readPacketOfSample:(NSInteger)sampleIndex;
  51. - (NSData *)readDataOfBox:(QGMP4Box *)box length:(NSInteger)length offset:(NSInteger)offset;
  52. @end