#2773: Seeking past the end of an mp3 file has different behavior than other formats ----------------------------------+-------------------------------------- Reporter: wadams | Type: defect Status: new | Priority: normal Component: avformat | Version: git-master Keywords: mp3 seek | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | ----------------------------------+-------------------------------------- I am trying to determine with complete accuracy the length of audio files of various formats by seeking to the near the end and reading packets. This has worked since version 1.2 but since I pulled the latest master branch from git this method no longer works for mp3 files. After I call av_seek_frame() on particular files, the next call to av_read_frame() returns EOF even if I use AVSEEK_FLAG_BACKWARD. Other formats will generally seek to the last sync point in the file when seeking past the end with the backward flag.
I looked through the git history and found the the commit that changed this behavior is [http://git.videolan.org/?p=ffmpeg.git;a=commit;h=e096283ea55bc36a637b47329e19ddb26fb1440b e096283ea55bc36a637b47329e19ddb26fb1440b]. Here is some code that will reproduce the problem with the attached file. It executes as expected when I revert the above mentioned commit. {{{ int main(int argc, char** argv) { int err, i, streamIndex; AVFormatContext* fmtCtx; AVStream* stream; AVPacket pkt; av_register_all(); fmtCtx = avformat_alloc_context(); err = avformat_open_input(&fmtCtx, "test.mp3", NULL, NULL); if (err < 0) { fprintf(stderr, "Failed to open input\n"); return 1; } avformat_find_stream_info(fmtCtx, NULL); streamIndex = -1; for (i = 0; i < fmtCtx->nb_streams; i++) if (fmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { streamIndex = i; break; } if (streamIndex < 0) { fprintf(stderr, "No audio stream\n"); return 1; } stream = fmtCtx->streams[streamIndex]; err = av_seek_frame(fmtCtx, streamIndex, stream->duration, AVSEEK_FLAG_BACKWARD); if (err < 0) { fprintf(stderr, "Failed to seek stream\n"); return 1; } av_init_packet(&pkt); pkt.data = NULL; pkt.size = 0; err = av_read_frame(fmtCtx, &pkt); if (err < 0) { char buf[1024]; av_strerror(err, buf, sizeof(buf)); fprintf(stderr, "Failed to read frame. Error: %d, %s\n", err, buf); return 1; } av_free_packet(&pkt); avformat_close_input(&fmtCtx); return 0; } }}} Thanks, Bill -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2773> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker _______________________________________________ FFmpeg-trac mailing list FFmpeg-trac@avcodec.org http://avcodec.org/mailman/listinfo/ffmpeg-trac