From 8c5f06c37f3c267ecd8f867cd49765c366b5f47c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 18 Aug 2022 23:11:29 -0400 Subject: many additions --- ffmpeg_backend.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'ffmpeg_backend.cpp') diff --git a/ffmpeg_backend.cpp b/ffmpeg_backend.cpp index 6f0aeb5..03d3214 100644 --- a/ffmpeg_backend.cpp +++ b/ffmpeg_backend.cpp @@ -6,6 +6,7 @@ extern "C" { #include } +/* // workaround to make libav error printing work #ifdef av_err2str #undef av_err2str @@ -16,6 +17,7 @@ av_always_inline std::string av_err2string(int errnum) { } #define av_err2str(err) av_err2string(err).c_str() #endif // av_err2str +*/ #include "ffmpeg_backend.h" @@ -54,9 +56,7 @@ bool32 AV_TryFrame(av_info *AV, int32 *err) return 0; } -// TODO(fox): Could be combined into AV_Init once we have dealloc functions for -// the AVInfo allocation. -bool32 AV_IsFileSupported(char *filename) +bool32 AV_IsFileSupported(char *filename, bool32 *IsVideo) { int32 err = 0; @@ -81,9 +81,22 @@ bool32 AV_IsFileSupported(char *filename) return 0; } - avformat_free_context(temp); + for (uint32 i = 0; i < temp->nb_streams; i++) + { + AVCodecParameters *LocalCodecParameters = NULL; + LocalCodecParameters = temp->streams[i]->codecpar; + if (LocalCodecParameters->codec_type == AVMEDIA_TYPE_VIDEO) { + if (temp->streams[i]->duration > 1) { + *IsVideo = true; + } + avformat_free_context(temp); + return 1; + } + } - return 1; + printf("Libav error: No video track found."); + + return 0; } // Note that we can't get away with not having to keep track of the AV pointer @@ -142,7 +155,7 @@ void AV_Init(source *Source, av_info *AV, memory *Memory) AV->VideoCodec = avcodec_find_decoder(AV->VideoCodecParameters->codec_id); if (!AV->VideoCodec) { - printf("Libav error: Video codec could not be identified."); + printf("Libav error: Suitable decoder could not be identified for codec:\n"); } /* int16 codecs = 0; @@ -261,7 +274,7 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo, // first frame, so we need to check until it's correct. if (FrameToSeek == 0 && AV->VideoFrame->pts != AV->VideoStream->start_time) { av_frame_unref(AV->VideoFrame); - printf("NON-START: avg: %li, real pts: %li", SeekPTS, AV->VideoFrame->pts); + // printf("NON-START: avg: %li, real pts: %li", SeekPTS, AV->VideoFrame->pts); continue; } @@ -270,9 +283,9 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo, { if (AV->PreviousPTS == -1) { AV->PreviousPTS = AV->VideoFrame->pts; - printf("avg: %li, real pts: %li, difference: %li\n", SeekPTS, AV->VideoFrame->pts, Difference); + // printf("avg: %li, real pts: %li, difference: %li\n", SeekPTS, AV->VideoFrame->pts, Difference); } else { - printf("avg: %li, real pts: %li, difference: %li difference from last pts: %li\n", SeekPTS, AV->VideoFrame->pts, AV->VideoFrame->pts - SeekPTS, AV->VideoFrame->pts - AV->PreviousPTS); + // printf("avg: %li, real pts: %li, difference: %li difference from last pts: %li\n", SeekPTS, AV->VideoFrame->pts, AV->VideoFrame->pts - SeekPTS, AV->VideoFrame->pts - AV->PreviousPTS); AV->PreviousPTS = AV->VideoFrame->pts; } @@ -308,7 +321,7 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo, else { // If this gets printed when not seeking, a frame has been skipped! - printf("FRAME SKIP: avg: %li, real pts: %li, difference: %li\n", SeekPTS, AV->VideoFrame->pts, Difference); + // printf("FRAME SKIP: avg: %li, real pts: %li, difference: %li\n", SeekPTS, AV->VideoFrame->pts, Difference); } av_frame_unref(AV->VideoFrame); } -- cgit v1.2.3