[Ffmpeg-devel] AVI Container Duration Incorrect

Paul Curtis pfc
Sun May 29 13:23:43 CEST 2005


I have a MPEG file that was encoded by a commerial editing product. When 
examined, the file is correct, plays correctly, and the mpeg container 
has the correct values for the duration.

# avprobe s XXXXXXX.mpg
Length: 1946
Duration: 1946711433
AVTimeBase: 1000000
Time: 00:32:26.7
Bitrate: 6273132
Size: 1526497280
StreamTitle:
StreamCopyright:
StreamAuthor:
MuxRate: 0
Video: mpeg2video, yuv420p, 720x480, 29.97 fps, 8000 kb/s
Audio: mp2, 48000 Hz, stereo, 224 kb/s


I then trancode this file for input into the Helix Producer. Helix 
Producer requires rawvideo + PCM audio. Using the current CVS of 
'ffmpeg', I do the following:

ffmpeg -y -i XXXXXXX.mpg -vcodec rawvideo -pix_fmt yuv420p -s 320x240 
-acodec pcm_s16le temp.avi

When I exmaine the resulting AVI file, I get:
# avprobe s temp.avi
Length: 294
Duration: 294727767
AVTimeBase: 1000000
Time: 00:04:54.7
Bitrate: 0
Size: 0
StreamTitle:
StreamCopyright:
StreamAuthor:
MuxRate: 0
Video: rawvideo, yuv420p, 320x240, 29.97 fps
Audio: pcm_s16le, 48000 Hz, stereo, 1536 kb/s

This causes a problem for the Helix Producer encoder, as the duration 
field in the AVFormatContext returns 294 seconds. The AVI file plays 
correctly with mplayer, with the correct duration. For whatever reason, 
any AVI created with the above 'ffmpeg' command line results in the same 
duration, 294 seconds.

Any ideas why the duration of the AVI is incorrect?

Regards,
Paul



---------- avprobe.c -----------
int main(int argc, char *argv[]) {
     AVFormatContext *ic;
     AVFormatParameters params, *ap = ¶ms;
     AVInputFormat *file_iformat = NULL;
     int err, ret, i, flags;
     char str[80];
     int64_t hours, mins, secs, us;

     if (argc != 3)
        return 1;

     av_register_all();

    /* open the input file with generic libav function */
     err = av_open_input_file(&ic, argv[2], file_iformat, 0, ap);
     if (err < 0) {
         print_error(argv[2], err);
         exit(1);
     }

     ret = av_find_stream_info(ic);
     if (ret < 0) {
         fprintf(stderr, "%s: could not find codec parameters\n", argv[2]);
         exit(1);
     }

     secs = ic->duration / AV_TIME_BASE;
     if (strncasecmp(argv[1], "t", 1) == 0) {
        printf("%lld", secs);
        return 0;
     }
     printf("Length: %lld\n", secs);
     printf("Duration: %lld\n", ic->duration);
     printf("AVTimeBase: %d\n", AV_TIME_BASE);

     us = ic->duration % AV_TIME_BASE;
     mins = secs / 60;
     secs %= 60;
     hours = mins / 60;
     mins %= 60;

     printf("Time: %02lld:%02lld:%02lld.%01lld\n", hours,mins,secs, (us 
* 10) / AV_TIME_BASE);
     printf("Bitrate: %d\n", ic->bit_rate);
     printf("Size: %lld\n", ic->file_size);
     if (ic->title)
        printf("StreamTitle: %s\n", ic->title);

     if (ic->copyright)
        printf("StreamCopyright: %s\n", ic->copyright);

     if (ic->author)
        printf("StreamAuthor: %s\n", ic->author);

     printf("MuxRate: %d\n", ic->mux_rate);

    for (i = 0; i < ic->nb_streams; i++) {
         AVStream *st = ic->streams[i];

         avcodec_string(str, sizeof(str), &st->codec, 0);
         flags = ic->iformat->flags;

         if (flags & AVFMT_SHOW_IDS) {
             printf("PID: 0x%x\n", st->id);
         }
         printf("%s\n", str);
     }
     return 0;
}





More information about the ffmpeg-devel mailing list