Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ffmpeg demuxer: make sure we start mpegts video with an i-frame
  • Loading branch information
FernetMenta authored and margro committed Dec 5, 2013
1 parent f95bfd6 commit d84a74f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
Expand Up @@ -448,6 +448,13 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput, bool streaminfo)
if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && m_ioContext->seekable == 0)
m_pFormatContext->max_analyze_duration = 500000;

bool short_analyze = false;
if (iformat && (strcmp(iformat->name, "mpegts") == 0))
{
m_pFormatContext->max_analyze_duration = 500000;
short_analyze = true;
}

// we need to know if this is matroska or avi later
m_bMatroska = strncmp(m_pFormatContext->iformat->name, "matroska", 8) == 0; // for "matroska.webm"
m_bAVI = strcmp(m_pFormatContext->iformat->name, "avi") == 0;
Expand Down Expand Up @@ -476,6 +483,12 @@ bool CDVDDemuxFFmpeg::Open(CDVDInputStream* pInput, bool streaminfo)
}
}
CLog::Log(LOGDEBUG, "%s - av_find_stream_info finished", __FUNCTION__);

if (short_analyze)
{
// make sure we start video with an i-frame
ResetVideoStreams();
}
}
else
m_program = 0;
Expand Down Expand Up @@ -1535,7 +1548,7 @@ void CDVDDemuxFFmpeg::ParsePacket(AVPacket *pkt)
}

// for video we need a decoder to get desired information into codec context
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->codec->extradata &&
(!st->codec->width || st->codec->pix_fmt == PIX_FMT_NONE))
{
// open a decoder, it will be cleared down by ffmpeg on closing the stream
Expand Down Expand Up @@ -1597,3 +1610,19 @@ bool CDVDDemuxFFmpeg::IsVideoReady()
}
return true;
}

void CDVDDemuxFFmpeg::ResetVideoStreams()
{
AVStream *st;
for (unsigned int i = 0; i < m_pFormatContext->nb_streams; i++)
{
st = m_pFormatContext->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
if (st->codec->extradata)
m_dllAvUtil.av_free(st->codec->extradata);
st->codec->extradata = NULL;
st->codec->width = 0;
}
}
}
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h
Expand Up @@ -129,6 +129,7 @@ class CDVDDemuxFFmpeg : public CDVDDemux
void DisposeStreams();
void ParsePacket(AVPacket *pkt);
bool IsVideoReady();
void ResetVideoStreams();

AVDictionary *GetFFMpegOptionsFromURL(const CURL &url);
double ConvertTimestamp(int64_t pts, int den, int num);
Expand Down

0 comments on commit d84a74f

Please sign in to comment.