[FFmpeg-devel] [PATCH] recover from truncated aiff
Baptiste Coudurier
baptiste.coudurier
Tue Nov 25 19:37:25 CET 2008
Hi,
Maksym Veremeyenko wrote:
> Maksym Veremeyenko ???????(??):
> [...]
>> Please have a look on attached patch.
> i was wrong in pkt->dts calculation, so have a look at attached patch.
>
>
> ------------------------------------------------------------------------
>
> Index: libavformat/raw.c
> ===================================================================
> --- libavformat/raw.c (revision 15899)
> +++ libavformat/raw.c (working copy)
>
> [...]
>
> @@ -138,25 +142,29 @@
>
> static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
> {
> - int ret, size, bps;
> - // AVStream *st = s->streams[0];
> + int ret;
> + AVStream *st = s->streams[0];
>
> - size= RAW_PACKET_SIZE;
> + /* End of stream may be reached */
> + if (url_feof(s->pb))
> + return AVERROR(EIO);
>
> - ret= av_get_packet(s->pb, pkt, size);
> + /* Now for that packet */
> + ret= av_get_packet(s->pb, pkt, (RAW_PACKET_SIZE / st->codec->block_align) * st->codec->block_align);
Michael suggested to use RAW_PACKET_SIZE*st->codec->block_align in case
it was not clear, this way packets have the same duration, whatever
channels or bps it is.
> pkt->stream_index = 0;
> if (ret <= 0) {
> return AVERROR(EIO);
> }
> - /* note: we need to modify the packet size here to handle the last
> - packet */
> - pkt->size = ret;
>
> - bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
> - assert(bps); // if false there IS a bug elsewhere (NOT in this function)
> + /* align packet on truncated file */
> + if (0 != (ret % st->codec->block_align)) {
> + pkt->size -= pkt->size % st->codec->block_align;
> + av_log(s, AV_LOG_WARNING, "truncated packet detected, dropped %d bytes\n", ret - pkt->size);
> + }
Humm, you do not set pkt->size before ?
Also use "if (ret % st->codec->block_align) {", more clear.
> pkt->dts=
> - pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
> + pkt->pts= pkt->pos / st->codec->block_align;
This is cosmetic and should be in a separate patch IMHO.
[...]
--
Baptiste COUDURIER GnuPG Key Id: 0x5C1ABAAA
Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
checking for life_signs in -lkenny... no
More information about the ffmpeg-devel
mailing list