@@ -163,7 +163,7 @@ namespace pub
163163 // If there is no specified track, add all tracks.
164164 for (auto &[track_id, media_track] : GetStream ()->GetTracks ())
165165 {
166- if (AddTrack (media_track) == false )
166+ if (AddTrack (output_format, media_track) == false )
167167 {
168168 continue ;
169169 }
@@ -187,7 +187,7 @@ namespace pub
187187 continue ;
188188 }
189189
190- if (AddTrack (media_track) == false )
190+ if (AddTrack (output_format, media_track) == false )
191191 {
192192 continue ;
193193 }
@@ -203,7 +203,7 @@ namespace pub
203203 continue ;
204204 }
205205
206- if (AddTrack (media_track) == false )
206+ if (AddTrack (output_format, media_track) == false )
207207 {
208208 continue ;
209209 }
@@ -574,7 +574,49 @@ namespace pub
574574 return _writer;
575575 }
576576
577- bool FileSession::AddTrack (const std::shared_ptr<MediaTrack> &track)
577+ bool FileSession::IsSupportCodec (const ov::String output_format, const cmn::MediaCodecId codec_id)
578+ {
579+ if (output_format == " mp4" )
580+ {
581+ // For mp4 format, only a limited number of codecs are supported.
582+ if (codec_id == cmn::MediaCodecId::H264 ||
583+ codec_id == cmn::MediaCodecId::H265 ||
584+ codec_id == cmn::MediaCodecId::Aac ||
585+ codec_id == cmn::MediaCodecId::Mp3 ||
586+ codec_id == cmn::MediaCodecId::Opus)
587+ {
588+ return true ;
589+ }
590+ }
591+ else if (output_format == " mpegts" )
592+ {
593+ if (codec_id == cmn::MediaCodecId::H264 ||
594+ codec_id == cmn::MediaCodecId::H265 ||
595+ codec_id == cmn::MediaCodecId::Vp8 ||
596+ codec_id == cmn::MediaCodecId::Vp9 ||
597+ codec_id == cmn::MediaCodecId::Aac ||
598+ codec_id == cmn::MediaCodecId::Mp3 ||
599+ codec_id == cmn::MediaCodecId::Opus)
600+ {
601+ return true ;
602+ }
603+ }
604+ // Webm 지원 코덱
605+ else if (output_format == " webm" )
606+ {
607+ if (codec_id == cmn::MediaCodecId::Vp8 ||
608+ codec_id == cmn::MediaCodecId::Vp9 ||
609+ codec_id == cmn::MediaCodecId::Av1 ||
610+ codec_id == cmn::MediaCodecId::Opus)
611+ {
612+ return true ;
613+ }
614+ }
615+
616+ return false ;
617+ }
618+
619+ bool FileSession::AddTrack (const ov::String output_format, const std::shared_ptr<MediaTrack> &track)
578620 {
579621 auto writer = GetWriter ();
580622 if (writer == nullptr )
@@ -586,10 +628,19 @@ namespace pub
586628 // Check already added track
587629 if (writer->GetTrackByTrackId (track->GetId ()) != nullptr )
588630 {
589- logtw (" Track already added. trackId:%d, variantName: %s" , track->GetId (), track->GetVariantName ().CStr ());
631+ logtw (" Track already added. trackId: %d, variantName: %s" , track->GetId (), track->GetVariantName ().CStr ());
590632 return false ;
591633 }
592634
635+ if (IsSupportCodec (output_format, track->GetCodecId ()) == false )
636+ {
637+ logtw (" Could not supported codec. trackId: %u, container: %s codec: %s, variantName: %s" ,
638+ track->GetId (), output_format.CStr (), GetCodecIdString (track->GetCodecId ()), track->GetVariantName ().CStr ());
639+ return false ;
640+ }
641+
642+ logtd (" Adding track to writer. trackId: %d, variantName: %s" , track->GetId (), track->GetVariantName ().CStr ());
643+
593644 SelectDefaultTrack (track);
594645
595646 return writer->AddTrack (track);
0 commit comments