MP4Muxer.h 1.5 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
xiongziliang committed
9 10 11 12 13
 */

#ifndef ZLMEDIAKIT_MP4MUXER_H
#define ZLMEDIAKIT_MP4MUXER_H

xiongziliang committed
14
#ifdef ENABLE_MP4
xiongziliang committed
15 16 17

#include "Common/MediaSink.h"
#include "Extension/AAC.h"
18
#include "Extension/G711.h"
xiongziliang committed
19 20
#include "Extension/H264.h"
#include "Extension/H265.h"
xiongziliang committed
21
#include "Common/Stamp.h"
xiongziliang committed
22
#include "MP4.h"
xiongziliang committed
23 24 25

namespace mediakit{

xiongziliang committed
26
class MP4Muxer : public MediaSinkInterface, public MP4File{
xiongziliang committed
27
public:
xiongziliang committed
28 29
    MP4Muxer(const char *file);
    ~MP4Muxer() override;
xiongziliang committed
30 31 32 33 34

    /**
     * 添加已经ready状态的track
     */
    void addTrack(const Track::Ptr & track) override;
xiongziliang committed
35
    /**
xiongziliang committed
36
     * 输入帧
xiongziliang committed
37
     */
xiongziliang committed
38
    void inputFrame(const Frame::Ptr &frame) override;
xiongziliang committed
39 40

    /**
xiongziliang committed
41
     * 重置所有track
xiongziliang committed
42
     */
xiongziliang committed
43
    void resetTracks() override ;
xiongziliang committed
44 45 46 47

private:
    void openMP4();
    void closeMP4();
xiongziliang committed
48
    void stampSync();
xiongziliang committed
49

xiongziliang committed
50
private:
xiongziliang committed
51
    struct track_info {
52
        int track_id = -1;
53
        Stamp stamp;
54
    };
xiongziliang committed
55
    unordered_map<int, track_info> _codec_to_trackid;
56
    List<Frame::Ptr> _frameCached;
57 58
    bool _started = false;
    bool _have_video = false;
xiongziliang committed
59
    MP4File::Writer _mov_writter;
xiongziliang committed
60
    string _file_name;
xiongziliang committed
61 62 63
};

}//namespace mediakit
xiongziliang committed
64
#endif//#ifdef ENABLE_MP4
xiongziliang committed
65
#endif //ZLMEDIAKIT_MP4MUXER_H