Previously, the default timebase caused two warnings during decoding about not being able to update timestamps for skipped and discarded samples, respectively.
Unified · Split
| @@ -62,6 +62,7 @@ static int open_input_file(const char *filename, · 61 unmodified lines | ||
| 62 | 62 | { |
| 63 | 63 | AVCodecContext *avctx; |
| 64 | 64 | const AVCodec *input_codec; |
| 65 | + const AVStream *stream; | |
| 65 | 66 | int error; |
| 66 | 67 | |
| 67 | 68 | /* Open the input file to read from it. */ |
| @@ -89,8 +90,10 @@ static int open_input_file(const char *filename, · 21 unmodified lines | ||
| 89 | 90 | return AVERROR_EXIT; |
| 90 | 91 | } |
| 91 | 92 | |
| 93 | + stream = (*input_format_context)->streams[0]; | |
| 94 | + | |
| 92 | 95 | /* Find a decoder for the audio stream. */ |
| 93 | − if (!(input_codec = avcodec_find_decoder((*input_format_context)->streams[0]->codecpar->codec_id))) { | |
| 96 | + if (!(input_codec = avcodec_find_decoder(stream->codecpar->codec_id))) { | |
| 94 | 97 | fprintf(stderr, "Could not find input codec\n"); |
| 95 | 98 | avformat_close_input(input_format_context); |
| 96 | 99 | return AVERROR_EXIT; |
| @@ -105,7 +108,7 @@ static int open_input_file(const char *filename, · 8 unmodified lines | ||
| 105 | 108 | } |
| 106 | 109 | |
| 107 | 110 | /* Initialize the stream parameters with demuxer information. */ |
| 108 | − error = avcodec_parameters_to_context(avctx, (*input_format_context)->streams[0]->codecpar); | |
| 111 | + error = avcodec_parameters_to_context(avctx, stream->codecpar); | |
| 109 | 112 | if (error < 0) { |
| 110 | 113 | avformat_close_input(input_format_context); |
| 111 | 114 | avcodec_free_context(&avctx); |
| @@ -121,6 +124,9 @@ static int open_input_file(const char *filename, · 9 unmodified lines | ||
| 121 | 124 | return error; |
| 122 | 125 | } |
| 123 | 126 | |
| 127 | + /* Set the packet timebase for the decoder. */ | |
| 128 | + avctx->pkt_timebase = stream->time_base; | |
| 129 | + | |
| 124 | 130 | /* Save the decoder context for easier access later. */ |
| 125 | 131 | *input_codec_context = avctx; |
| 126 | 132 | |