mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-06-04 05:57:49 +02:00
properly demux silent files; implemented precise framerate calculation
Originally committed as revision 2330 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
68a43d044a
commit
dda6142361
@ -96,7 +96,7 @@ typedef struct IPMVEContext {
|
|||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
int buf_size;
|
int buf_size;
|
||||||
|
|
||||||
int fps;
|
float fps;
|
||||||
int frame_pts_inc;
|
int frame_pts_inc;
|
||||||
|
|
||||||
unsigned int video_width;
|
unsigned int video_width;
|
||||||
@ -199,6 +199,9 @@ static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
|
|||||||
pkt->stream_index = s->video_stream_index;
|
pkt->stream_index = s->video_stream_index;
|
||||||
pkt->pts = s->video_pts;
|
pkt->pts = s->video_pts;
|
||||||
|
|
||||||
|
debug_ipmovie("sending video frame with pts %lld\n",
|
||||||
|
pkt->pts);
|
||||||
|
|
||||||
s->video_pts += s->frame_pts_inc;
|
s->video_pts += s->frame_pts_inc;
|
||||||
|
|
||||||
chunk_type = CHUNK_VIDEO;
|
chunk_type = CHUNK_VIDEO;
|
||||||
@ -330,10 +333,9 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
|
|||||||
chunk_type = CHUNK_BAD;
|
chunk_type = CHUNK_BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s->fps = 1000000 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
|
s->fps = 1000000.0 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
|
||||||
s->fps++; /* above calculation usually yields 14.9; we need 15 */
|
|
||||||
s->frame_pts_inc = 90000 / s->fps;
|
s->frame_pts_inc = 90000 / s->fps;
|
||||||
debug_ipmovie("%d frames/second (timer div = %d, subdiv = %d)\n",
|
debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n",
|
||||||
s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
|
s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -527,6 +529,8 @@ static int ipmovie_read_header(AVFormatContext *s,
|
|||||||
ByteIOContext *pb = &s->pb;
|
ByteIOContext *pb = &s->pb;
|
||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
|
unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
|
||||||
|
int chunk_type;
|
||||||
|
|
||||||
/* initialize private context members */
|
/* initialize private context members */
|
||||||
ipmovie->video_pts = ipmovie->audio_frame_count = 0;
|
ipmovie->video_pts = ipmovie->audio_frame_count = 0;
|
||||||
@ -540,8 +544,17 @@ static int ipmovie_read_header(AVFormatContext *s,
|
|||||||
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
|
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
/* process the next chunk which should be CHUNK_INIT_AUDIO */
|
/* peek ahead to the next chunk-- if it is an init audio chunk, process
|
||||||
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
|
* it; if it is the first video chunk, this is a silent file */
|
||||||
|
if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
|
||||||
|
CHUNK_PREAMBLE_SIZE)
|
||||||
|
return -EIO;
|
||||||
|
chunk_type = LE_16(&chunk_preamble[2]);
|
||||||
|
url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
|
||||||
|
|
||||||
|
if (chunk_type == CHUNK_VIDEO)
|
||||||
|
ipmovie->audio_type = 0; /* no audio */
|
||||||
|
else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
/* set the pts reference (1 pts = 1/90000) */
|
/* set the pts reference (1 pts = 1/90000) */
|
||||||
@ -563,6 +576,7 @@ static int ipmovie_read_header(AVFormatContext *s,
|
|||||||
st->codec.extradata_size = sizeof(AVPaletteControl);
|
st->codec.extradata_size = sizeof(AVPaletteControl);
|
||||||
st->codec.extradata = &ipmovie->palette_control;
|
st->codec.extradata = &ipmovie->palette_control;
|
||||||
|
|
||||||
|
if (ipmovie->audio_type) {
|
||||||
st = av_new_stream(s, 0);
|
st = av_new_stream(s, 0);
|
||||||
if (!st)
|
if (!st)
|
||||||
return AVERROR_NOMEM;
|
return AVERROR_NOMEM;
|
||||||
@ -578,6 +592,7 @@ static int ipmovie_read_header(AVFormatContext *s,
|
|||||||
if (st->codec.codec_id == CODEC_ID_INTERPLAY_DPCM)
|
if (st->codec.codec_id == CODEC_ID_INTERPLAY_DPCM)
|
||||||
st->codec.bit_rate /= 2;
|
st->codec.bit_rate /= 2;
|
||||||
st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
|
st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user