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