Skip to content

Commit f207e48

Browse files
committed
Support many image formats with our FFmpegReader, by safely protecting empty packets in GetPacketPTS, and generating a duration and setting the has_single_image property.
1 parent 05b997a commit f207e48

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/FFmpegReader.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,14 @@ void FFmpegReader::UpdateVideoInfo() {
819819
info.duration = float(info.file_size) / info.video_bit_rate;
820820
}
821821

822+
// Certain "image" formats do not have a valid duration
823+
if (info.duration <= 0.0f && pStream->duration == AV_NOPTS_VALUE && pFormatCtx->duration == AV_NOPTS_VALUE) {
824+
// Force an "image" duration
825+
info.duration = 60 * 60 * 1; // 1 hour duration
826+
info.video_length = 1;
827+
info.has_single_image = true;
828+
}
829+
822830
// Get the # of video frames (if found in stream)
823831
// Only set this 1 time (this method can be called multiple times)
824832
if (pStream->nb_frames > 0 && info.video_length <= 0) {
@@ -1849,12 +1857,17 @@ void FFmpegReader::Seek(int64_t requested_frame) {
18491857

18501858
// Get the PTS for the current video packet
18511859
int64_t FFmpegReader::GetPacketPTS() {
1852-
int64_t current_pts = packet->pts;
1853-
if (current_pts == AV_NOPTS_VALUE && packet->dts != AV_NOPTS_VALUE)
1854-
current_pts = packet->dts;
1855-
1856-
// Return adjusted PTS
1857-
return current_pts;
1860+
if (packet) {
1861+
int64_t current_pts = packet->pts;
1862+
if (current_pts == AV_NOPTS_VALUE && packet->dts != AV_NOPTS_VALUE)
1863+
current_pts = packet->dts;
1864+
1865+
// Return adjusted PTS
1866+
return current_pts;
1867+
} else {
1868+
// No packet, return NO PTS
1869+
return AV_NOPTS_VALUE;
1870+
}
18581871
}
18591872

18601873
// Update PTS Offset (if any)

0 commit comments

Comments
 (0)