@@ -878,92 +878,67 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil
878
878
qDebug () << " m_mediaParser->currentVideoStreams(): " << m_mediaParser->currentVideoStreams ().size ();
879
879
qDebug () << " m_mediaParser->currentAudioStreams(): " << m_mediaParser->currentAudioStreams ().size ();
880
880
881
- auto streams = m_mediaParser->availableVideoStreams ();
882
- streams.append (m_mediaParser->availableAudioStreams ());
883
-
884
- AVFormatContext* FormatContext = nullptr ;
885
- auto stdMediaFileName = mediaOrMkvReportFileName.toStdString ();
886
- AVDictionary* options = nullptr ;
887
- if (dpxOffset != -1 ) {
888
- auto dpxOffsetString = std::to_string (dpxOffset);
889
- av_dict_set (&options, " f" , " image2" , 0 );
890
- av_dict_set (&options, " start_number" , dpxOffsetString.c_str (), 0 );
891
- }
892
- if (avformat_open_input (&FormatContext, stdMediaFileName.c_str (), nullptr , &options)>=0 )
893
- {
894
- QVector<QAVStream*> orderedStreams;
895
- if (avformat_find_stream_info (FormatContext, NULL )>=0 ) {
896
-
897
- containerFormat = FormatContext->iformat ->long_name ;
898
- streamCount = FormatContext->nb_streams ;
899
- bitRate = FormatContext->bit_rate ;
900
-
901
- size_t VideoPos=0 ;
902
- size_t AudioPos=0 ;
903
-
904
- for (auto i = 0 ; i < FormatContext->nb_streams ; ++i) {
905
- auto codec_type = FormatContext->streams [i]->codecpar ->codec_type ;
906
- if (codec_type != AVMEDIA_TYPE_VIDEO && codec_type != AVMEDIA_TYPE_AUDIO)
907
- continue ;
908
-
909
- auto streamIt = std::find_if (streams.begin (), streams.end (), [i](QAVStream& stream) {
910
- return stream.stream ()->index == i;
911
- });
912
-
913
- if (streamIt == streams.end ()) {
914
- qDebug () << " error: it should never happen" ;
915
- assert (false );
916
- continue ;
917
- }
881
+ QVector<QAVStream> streams = m_mediaParser->currentVideoStreams () + m_mediaParser->currentAudioStreams ();
882
+ QVector<QAVStream*> orderedStreams;
883
+ for (int i = 0 ; i < streams.size (); ++i) {
884
+ if (streams[i].codec ()->codec () == nullptr ) {
885
+ qDebug () << " error: codec is null for stream" << streams[i].stream ()->index << " ... skipping" ;
886
+ continue ;
887
+ }
918
888
919
- if (streamIt->codec ()->codec () == nullptr ) {
920
- qDebug () << " error: codec is null for stream" << i << " ... skipping" ;
921
- continue ;
922
- }
923
- orderedStreams.append (&*streamIt);
924
-
925
- auto Duration = 0 ;
926
- auto FrameCount = streamIt->stream ()->nb_frames ;
927
- if (streamIt->stream ()->duration != AV_NOPTS_VALUE)
928
- Duration= ((double )streamIt->stream ()->duration )*streamIt->stream ()->time_base .num /streamIt->stream ()->time_base .den ;
929
-
930
- // If duration is not known, estimating it
931
- if (Duration==0 && FormatContext->duration !=AV_NOPTS_VALUE)
932
- Duration=((double )FormatContext->duration )/AV_TIME_BASE;
933
-
934
- // If frame count is not known, estimating it
935
- if (FrameCount==0 && streamIt->stream ()->avg_frame_rate .num && streamIt->stream ()->avg_frame_rate .den && Duration)
936
- FrameCount=Duration*streamIt->stream ()->avg_frame_rate .num /streamIt->stream ()->avg_frame_rate .den ;
937
- if (FrameCount==0
938
- && ((streamIt->stream ()->time_base .num ==1 && streamIt->stream ()->time_base .den >=24 && streamIt->stream ()->time_base .den <=60 )
939
- || (streamIt->stream ()->time_base .num ==1001 && streamIt->stream ()->time_base .den >=24000 && streamIt->stream ()->time_base .den <=60000 )))
940
- FrameCount=streamIt->stream ()->duration ;
941
-
942
- CommonStats* Stat = nullptr ;
943
-
944
- if (streamIt->stream ()->codecpar ->codec_type == AVMEDIA_TYPE_VIDEO) {
945
- if (!VideoPos || ActiveAllTracks[Type_Video])
946
- Stat = new VideoStats (FrameCount, Duration, &*streamIt);
947
- ++VideoPos;
948
- } else if (streamIt->stream ()->codecpar ->codec_type == AVMEDIA_TYPE_AUDIO) {
949
- if (!AudioPos || ActiveAllTracks[Type_Audio])
950
- Stat = new AudioStats (FrameCount, Duration, &*streamIt);
951
- ++AudioPos;
952
- }
889
+ auto codec_type = streams[i].stream ()->codecpar ->codec_type ;
890
+ if (codec_type != AVMEDIA_TYPE_VIDEO && codec_type != AVMEDIA_TYPE_AUDIO)
891
+ continue ;
953
892
954
- if (Stat)
955
- Stats.push_back (Stat);
956
- }
893
+ orderedStreams.append (&streams[i]);
894
+ }
895
+ std::sort (orderedStreams.begin (), orderedStreams.end (), [](QAVStream* a, QAVStream* b) {
896
+ return a->stream ()->index < b->stream ()->index ;
897
+ });
957
898
958
- streamsStats = new StreamsStats (orderedStreams, FormatContext);
959
- formatStats = new FormatStats (FormatContext);
899
+ containerFormat = m_mediaParser->avctx ()->iformat ->long_name ;
900
+ streamCount = m_mediaParser->avctx ()->nb_streams ;
901
+ bitRate = m_mediaParser->avctx ()->bit_rate ;
902
+
903
+ size_t VideoPos=0 ;
904
+ size_t AudioPos=0 ;
905
+
906
+ for ( auto streamIt = orderedStreams.begin (); streamIt != orderedStreams.end (); ++streamIt) {
907
+ auto Duration = 0 ;
908
+ auto FrameCount = (*streamIt)->stream ()->nb_frames ;
909
+ if ((*streamIt)->stream ()->duration != AV_NOPTS_VALUE)
910
+ Duration= ((double )(*streamIt)->stream ()->duration )*(*streamIt)->stream ()->time_base .num /(*streamIt)->stream ()->time_base .den ;
911
+
912
+ // If duration is not known, estimating it
913
+ if (Duration==0 && m_mediaParser->avctx ()->duration !=AV_NOPTS_VALUE)
914
+ Duration=((double ) m_mediaParser->avctx ()->duration )/AV_TIME_BASE;
915
+
916
+ // If frame count is not known, estimating it
917
+ if (FrameCount==0 && (*streamIt)->stream ()->avg_frame_rate .num && (*streamIt)->stream ()->avg_frame_rate .den && Duration)
918
+ FrameCount=Duration*(*streamIt)->stream ()->avg_frame_rate .num /(*streamIt)->stream ()->avg_frame_rate .den ;
919
+ if (FrameCount==0
920
+ && (((*streamIt)->stream ()->time_base .num ==1 && (*streamIt)->stream ()->time_base .den >=24 && (*streamIt)->stream ()->time_base .den <=60 )
921
+ || ((*streamIt)->stream ()->time_base .num ==1001 && (*streamIt)->stream ()->time_base .den >=24000 && (*streamIt)->stream ()->time_base .den <=60000 )))
922
+ FrameCount=(*streamIt)->stream ()->duration ;
923
+
924
+ CommonStats* Stat = nullptr ;
925
+
926
+ if ((*streamIt)->stream ()->codecpar ->codec_type == AVMEDIA_TYPE_VIDEO) {
927
+ if (!VideoPos || ActiveAllTracks[Type_Video])
928
+ Stat = new VideoStats (FrameCount, Duration, *streamIt);
929
+ ++VideoPos;
930
+ } else if ((*streamIt)->stream ()->codecpar ->codec_type == AVMEDIA_TYPE_AUDIO) {
931
+ if (!AudioPos || ActiveAllTracks[Type_Audio])
932
+ Stat = new AudioStats (FrameCount, Duration, *streamIt);
933
+ ++AudioPos;
960
934
}
961
935
962
- avformat_close_input (&FormatContext);
963
- }
964
- if (options) {
965
- av_dict_free (&options);
936
+ if (Stat)
937
+ Stats.push_back (Stat);
966
938
}
939
+
940
+ streamsStats = new StreamsStats (orderedStreams);
941
+ formatStats = new FormatStats (m_mediaParser->avctx ());
967
942
}
968
943
969
944
if (attachment.isEmpty ()) {
0 commit comments