47 stream_type_ = stream_info.stream_type();
49 if (stream_type_ == kStreamVideo) {
52 if (video_stream_info.codec() != Codec::kCodecH264) {
53 NOTIMPLEMENTED() <<
"Video codec " << video_stream_info.codec()
54 <<
" is not supported.";
57 timescale_scale_ = kTsTimescale / video_stream_info.time_scale();
59 return converter_->Initialize(video_stream_info.codec_config().data(),
60 video_stream_info.codec_config().size());
62 if (stream_type_ == kStreamAudio) {
65 timescale_scale_ = kTsTimescale / audio_stream_info.time_scale();
66 if (audio_stream_info.codec() == Codec::kCodecAAC) {
67 audio_stream_id_ = kAacAudioStreamId;
69 return adts_converter_->Parse(audio_stream_info.codec_config());
71 if (audio_stream_info.codec() == Codec::kCodecAC3 ||
72 audio_stream_info.codec() == Codec::kCodecEAC3 ||
73 audio_stream_info.codec() == Codec::kCodecMP3) {
74 audio_stream_id_ = kAc3AudioStreamId;
78 NOTIMPLEMENTED() <<
"Audio codec " << audio_stream_info.codec()
79 <<
" is not supported yet.";
83 NOTIMPLEMENTED() <<
"Stream type: " << stream_type_ <<
" not implemented.";
88 if (!current_processing_pes_)
89 current_processing_pes_.reset(
new PesPacket());
92 sample.pts() * timescale_scale_ + transport_stream_timestamp_offset_;
94 sample.dts() * timescale_scale_ + transport_stream_timestamp_offset_;
96 if (pts < 0 || dts < 0) {
97 LOG(ERROR) <<
"Seeing negative timestamp (" << pts <<
"," << dts <<
")"
98 <<
" after applying offset "
99 << transport_stream_timestamp_offset_
100 <<
". Please check if it is expected. Adjust "
101 "--transport_stream_timestamp_offset_ms if needed.";
105 current_processing_pes_->set_is_key_frame(sample.is_key_frame());
106 current_processing_pes_->set_pts(pts);
107 current_processing_pes_->set_dts(dts);
108 if (stream_type_ == kStreamVideo) {
110 std::vector<SubsampleEntry> subsamples;
111 if (sample.decrypt_config())
112 subsamples = sample.decrypt_config()->subsamples();
113 const bool kEscapeEncryptedNalu =
true;
114 std::vector<uint8_t> byte_stream;
115 if (!converter_->ConvertUnitToByteStreamWithSubsamples(
116 sample.data(), sample.data_size(), sample.is_key_frame(),
117 kEscapeEncryptedNalu, &byte_stream, &subsamples)) {
118 LOG(ERROR) <<
"Failed to convert sample to byte stream.";
122 current_processing_pes_->mutable_data()->swap(byte_stream);
123 current_processing_pes_->set_stream_id(kVideoStreamId);
124 pes_packets_.push_back(std::move(current_processing_pes_));
127 DCHECK_EQ(stream_type_, kStreamAudio);
129 std::vector<uint8_t> audio_frame;
132 if (adts_converter_) {
133 if (!adts_converter_->ConvertToADTS(sample.data(), sample.data_size(),
137 audio_frame.assign(sample.data(), sample.data() + sample.data_size());
142 current_processing_pes_->mutable_data()->swap(audio_frame);
143 current_processing_pes_->set_stream_id(audio_stream_id_);
144 pes_packets_.push_back(std::move(current_processing_pes_));