Opened 12 years ago
Last modified 11 years ago
#1878 new defect
Seeking causes later packets to be thrown away
Reported by: | mbradshaw | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | undetermined |
Version: | git-master | Keywords: | seek |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
Seeking causes certain packets to be thrown away, depending on which stream was sought. This is either a bug in the code, or an undocumented but critical "feature." I am unsure of which.
Link to sample file:
https://docs.google.com/uc?id=0BxWx_dIBnyRoSnMyTFNGOHR1c2c&export=download (321 MB)
I'm sorry it's not a perfectly direct link. Google Drive requires you to acknowledge that it hasn't been scanned for viruses because of its file size.
How to reproduce:
If I seek using a stream index of 1 (the audio stream), av_read_frame()
skips the first two video packets, but if I seek using a stream index of 0 (the video stream), av_read_frame()
does not skip the first two video packets. ffprobe shows that the first several packets in the file belong to the video stream, and I was hoping and assuming that seeking back to the very first packet in the file (which is why I was seeking by the audio stream index) would be a valid way to properly reset all streams to the beginning. However, this issue causes the first bit of video to be skipped, which is not acceptable in my situation.
Here is some sample code I wrote to illustrate the problem. There is a significant difference in output when seeking by stream index of 0 and seeking by stream index of 1.
#include <stdio.h> // Just remove the extern "C" part to compile as C extern "C" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswresample/swresample.h> } static void decodeFirstFrame(AVFormatContext* formatContext, AVStream* videoStream, AVFrame* frame) { AVPacket packet; int packetNumber; int frameFinished; int result; packetNumber = 0; av_init_packet(&packet); while (av_read_frame(formatContext, &packet) == 0) { printf("packet #: %7d\tdts: %7d\ttype: %s\n", packetNumber++, (int)packet.dts, (packet.stream_index == videoStream->index) ? "video *" : "audio"); if (packet.stream_index == videoStream->index) { frameFinished = 0; result = avcodec_decode_video2(videoStream->codec, frame, &frameFinished, &packet); if (result >= 0 && frameFinished) { printf("Got video frame at time %d\n", (int)av_frame_get_best_effort_timestamp(frame)); av_free_packet(&packet); break; } } av_free_packet(&packet); } } int main(int argc, char** argv) { AVFrame* frame; AVFormatContext* formatContext; AVStream* videoStream; AVCodecContext* codecContext; av_register_all(); frame = avcodec_alloc_frame(); if (!frame) { printf("Error allocating the frame\n"); return 1; } formatContext = NULL; if (avformat_open_input(&formatContext, "SIMPSONS_D2-CallOfTheSimpsons.m4v", NULL, NULL) != 0) { av_free(frame); printf("Error opening the file\n"); return 1; } if (avformat_find_stream_info(formatContext, NULL) < 0) { av_free(frame); avformat_close_input(&formatContext); printf("Error finding the stream info\n"); return 1; } videoStream = NULL; for (unsigned int i = 0; i < formatContext->nb_streams; ++i) { if (formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { videoStream = formatContext->streams[i]; break; } } if (videoStream == NULL) { av_free(frame); avformat_close_input(&formatContext); printf("Could not find any video stream in the file\n"); return 1; } codecContext = videoStream->codec; codecContext->codec = avcodec_find_decoder(codecContext->codec_id); if (codecContext->codec == NULL) { av_free(frame); avformat_close_input(&formatContext); printf("Couldn't find a proper decoder\n"); return 1; } else if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0) { av_free(frame); avformat_close_input(&formatContext); printf("Couldn't open the context with the decoder\n"); return 1; } decodeFirstFrame(formatContext, videoStream, frame); avcodec_flush_buffers(codecContext); printf("seek result: %d\n", av_seek_frame(formatContext, 0, -2000000000, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY)); decodeFirstFrame(formatContext, videoStream, frame); av_free(frame); avcodec_close(codecContext); avformat_close_input(&formatContext); return 0; }
Output from first call to decodeFirstFrame()
:
packet #: 0 dts: 0 type: audio packet #: 1 dts: 1024 type: audio packet #: 2 dts: 2048 type: audio packet #: 3 dts: 3072 type: audio packet #: 4 dts: 4096 type: audio packet #: 5 dts: 5120 type: audio packet #: 6 dts: 6144 type: audio packet #: 7 dts: -6006 type: video * packet #: 8 dts: -3003 type: video * packet #: 9 dts: 0 type: video * packet #: 10 dts: 3003 type: video * packet #: 11 dts: 7168 type: audio packet #: 12 dts: 8192 type: audio packet #: 13 dts: 9216 type: audio packet #: 14 dts: 10240 type: audio packet #: 15 dts: 11264 type: audio packet #: 16 dts: 12288 type: audio packet #: 17 dts: 13312 type: audio packet #: 18 dts: 6006 type: video * Got video frame at time 0
Seek result:
seek result: 0
Output from second call to decodeFirstFrame()
after performing av_seek_frame()
with stream_index = 1
(note it skips the first two video packets, which have DTS = -6006 and -3003) (these results are undesirable):
packet #: 0 dts: 0 type: audio packet #: 1 dts: 1024 type: audio packet #: 2 dts: 2048 type: audio packet #: 3 dts: 3072 type: audio packet #: 4 dts: 4096 type: audio packet #: 5 dts: 5120 type: audio packet #: 6 dts: 6144 type: audio packet #: 7 dts: 0 type: video * packet #: 8 dts: 3003 type: video * [h264 @ 0072fa80] reference picture missing during reorder [h264 @ 0072fa80] reference picture missing during reorder [h264 @ 0072fa80] reference picture missing during reorder [h264 @ 0072fa80] Missing reference picture [h264 @ 0072fa80] decode_slice_header error [h264 @ 0072fa80] concealing 1350 DC, 1350 AC, 1350 MV errors in P frame [h264 @ 00b6f800] mmco: unref short failure packet #: 9 dts: 7168 type: audio packet #: 10 dts: 8192 type: audio [h264 @ 00b6f800] packet #: 11 dts: 9216 type: audio packet #: 12 dts: 10240 type: audio Missing reference picture packet #: 13 dts: 11264 type: audio packet #: 14 dts: 12288 type: audio packet #: 15 dts: 13312 type: audio packet #: 16 dts: 6006 type: video * packet #: 17 dts: 9009 type: video * [h264 @ 00682de0] reference picture missing during reorder [h264 @ 00682de0] reference picture missing during reorder [h264 @ 00682de0] Missing reference picture [h264 @ 00682de0] Missing reference picture [h264 @ 0072fa80] mmco: unref short failure packet #: 18 dts: 12012 type: video * packet #: 19 dts: 15015 type: video * [h264 @ 00b6f800] reference picture missing during reorder [h264 @ 00b6f800] Missing reference picture packet #: 20 dts: 18018 type: video * packet #: 21 dts: 21021 type: video * packet #: 22 dts: 24024 type: video * packet #: 23 dts: 27027 type: video * packet #: 24 dts: 14336 type: audio packet #: 25 dts: 15360 type: audio packet #: 26 dts: 16384 type: audio packet #: 27 dts: 17408 type: audio packet #: 28 dts: 18432 type: audio packet #: 29 dts: 19456 type: audio packet #: 30 dts: 20480 type: audio packet #: 31 dts: 30030 type: video * packet #: 32 dts: 33033 type: video * packet #: 33 dts: 36036 type: video * packet #: 34 dts: 39039 type: video * packet #: 35 dts: 21504 type: audio packet #: 36 dts: 22528 type: audio packet #: 37 dts: 23552 type: audio packet #: 38 dts: 24576 type: audio packet #: 39 dts: 25600 type: audio packet #: 40 dts: 26624 type: audio packet #: 41 dts: 27648 type: audio packet #: 42 dts: 42042 type: video * packet #: 43 dts: 45045 type: video * packet #: 44 dts: 48048 type: video * packet #: 45 dts: 51051 type: video * packet #: 46 dts: 28672 type: audio packet #: 47 dts: 29696 type: audio packet #: 48 dts: 30720 type: audio packet #: 49 dts: 31744 type: audio packet #: 50 dts: 32768 type: audio packet #: 51 dts: 33792 type: audio packet #: 52 dts: 34816 type: audio packet #: 53 dts: 54054 type: video * packet #: 54 dts: 57057 type: video * packet #: 55 dts: 60060 type: video * packet #: 56 dts: 63063 type: video * packet #: 57 dts: 35840 type: audio packet #: 58 dts: 36864 type: audio packet #: 59 dts: 37888 type: audio packet #: 60 dts: 38912 type: audio packet #: 61 dts: 39936 type: audio packet #: 62 dts: 40960 type: audio packet #: 63 dts: 41984 type: audio packet #: 64 dts: 66066 type: video * packet #: 65 dts: 69069 type: video * packet #: 66 dts: 72072 type: video * packet #: 67 dts: 75075 type: video * packet #: 68 dts: 43008 type: audio packet #: 69 dts: 44032 type: audio packet #: 70 dts: -6006 type: audio packet #: 71 dts: 45056 type: audio packet #: 72 dts: 46080 type: audio packet #: 73 dts: 47104 type: audio packet #: 74 dts: 48128 type: audio packet #: 75 dts: 49152 type: audio packet #: 76 dts: 78078 type: video * packet #: 77 dts: 81081 type: video * packet #: 78 dts: 84084 type: video * packet #: 79 dts: 87087 type: video * packet #: 80 dts: 50176 type: audio packet #: 81 dts: 51200 type: audio packet #: 82 dts: 52224 type: audio packet #: 83 dts: 53248 type: audio packet #: 84 dts: 54272 type: audio packet #: 85 dts: 55296 type: audio packet #: 86 dts: 56320 type: audio packet #: 87 dts: 90090 type: video * packet #: 88 dts: 93093 type: video * packet #: 89 dts: 96096 type: video * packet #: 90 dts: 99099 type: video * packet #: 91 dts: 57344 type: audio packet #: 92 dts: 58368 type: audio packet #: 93 dts: 59392 type: audio packet #: 94 dts: 60416 type: audio packet #: 95 dts: 61440 type: audio packet #: 96 dts: 62464 type: audio packet #: 97 dts: 63488 type: audio packet #: 98 dts: 102102 type: video * packet #: 99 dts: 105105 type: video * packet #: 100 dts: 108108 type: video * packet #: 101 dts: 111111 type: video * packet #: 102 dts: 114114 type: video * packet #: 103 dts: 117117 type: video * packet #: 104 dts: 120120 type: video * packet #: 105 dts: 123123 type: video * packet #: 106 dts: 64512 type: audio packet #: 107 dts: 65536 type: audio packet #: 108 dts: 66560 type: audio packet #: 109 dts: 67584 type: audio packet #: 110 dts: 68608 type: audio packet #: 111 dts: 69632 type: audio packet #: 112 dts: 70656 type: audio packet #: 113 dts: 126126 type: video * packet #: 114 dts: 129129 type: video * packet #: 115 dts: 132132 type: video * packet #: 116 dts: 135135 type: video * packet #: 117 dts: 71680 type: audio packet #: 118 dts: 72704 type: audio packet #: 119 dts: 73728 type: audio packet #: 120 dts: 74752 type: audio packet #: 121 dts: 75776 type: audio packet #: 122 dts: 76800 type: audio packet #: 123 dts: 77824 type: audio packet #: 124 dts: 138138 type: video * packet #: 125 dts: 141141 type: video * packet #: 126 dts: 144144 type: video * packet #: 127 dts: 147147 type: video * packet #: 128 dts: 78848 type: audio packet #: 129 dts: 79872 type: audio packet #: 130 dts: 80896 type: audio packet #: 131 dts: 81920 type: audio packet #: 132 dts: 82944 type: audio packet #: 133 dts: 83968 type: audio packet #: 134 dts: 84992 type: audio packet #: 135 dts: 86016 type: audio packet #: 136 dts: 87040 type: audio packet #: 137 dts: 88064 type: audio packet #: 138 dts: 89088 type: audio packet #: 139 dts: 90112 type: audio packet #: 140 dts: 91136 type: audio packet #: 141 dts: 92160 type: audio packet #: 142 dts: 150150 type: video * packet #: 143 dts: 153153 type: video * packet #: 144 dts: 156156 type: video * packet #: 145 dts: 159159 type: video * packet #: 146 dts: 162162 type: video * packet #: 147 dts: 165165 type: video * packet #: 148 dts: 168168 type: video * packet #: 149 dts: 171171 type: video * packet #: 150 dts: 93184 type: audio packet #: 151 dts: 94208 type: audio packet #: 152 dts: 95232 type: audio packet #: 153 dts: 96256 type: audio packet #: 154 dts: 97280 type: audio packet #: 155 dts: 98304 type: audio packet #: 156 dts: 99328 type: audio packet #: 157 dts: 174174 type: video * packet #: 158 dts: 177177 type: video * packet #: 159 dts: 180180 type: video * packet #: 160 dts: 183183 type: video * packet #: 161 dts: 100352 type: audio packet #: 162 dts: 101376 type: audio packet #: 163 dts: 102400 type: audio packet #: 164 dts: 103424 type: audio packet #: 165 dts: 104448 type: audio packet #: 166 dts: 105472 type: audio packet #: 167 dts: 106496 type: audio packet #: 168 dts: 186186 type: video * packet #: 169 dts: 189189 type: video * packet #: 170 dts: 192192 type: video * packet #: 171 dts: 195195 type: video * packet #: 172 dts: 107520 type: audio packet #: 173 dts: 108544 type: audio packet #: 174 dts: 109568 type: audio packet #: 175 dts: 110592 type: audio packet #: 176 dts: 111616 type: audio packet #: 177 dts: 112640 type: audio packet #: 178 dts: 113664 type: audio packet #: 179 dts: 198198 type: video * packet #: 180 dts: 201201 type: video * packet #: 181 dts: 204204 type: video * packet #: 182 dts: 207207 type: video * packet #: 183 dts: 114688 type: audio packet #: 184 dts: 115712 type: audio packet #: 185 dts: 116736 type: audio packet #: 186 dts: 117760 type: audio packet #: 187 dts: 118784 type: audio packet #: 188 dts: 119808 type: audio packet #: 189 dts: 120832 type: audio packet #: 190 dts: 210210 type: video * packet #: 191 dts: 213213 type: video * packet #: 192 dts: 216216 type: video * packet #: 193 dts: 219219 type: video * packet #: 194 dts: 121856 type: audio packet #: 195 dts: 122880 type: audio packet #: 196 dts: 123904 type: audio packet #: 197 dts: 124928 type: audio packet #: 198 dts: 125952 type: audio packet #: 199 dts: 126976 type: audio packet #: 200 dts: 128000 type: audio packet #: 201 dts: 222222 type: video * packet #: 202 dts: 225530 type: video * packet #: 203 dts: 228533 type: video * packet #: 204 dts: 231536 type: video * packet #: 205 dts: 129024 type: audio packet #: 206 dts: 130048 type: audio packet #: 207 dts: 131072 type: audio packet #: 208 dts: 132096 type: audio packet #: 209 dts: 133120 type: audio packet #: 210 dts: 134144 type: audio packet #: 211 dts: 135168 type: audio packet #: 212 dts: 234539 type: video * packet #: 213 dts: 237542 type: video * packet #: 214 dts: 240545 type: video * packet #: 215 dts: 243548 type: video * packet #: 216 dts: 136192 type: audio packet #: 217 dts: 137216 type: audio packet #: 218 dts: 138240 type: audio packet #: 219 dts: 139264 type: audio packet #: 220 dts: 140288 type: audio packet #: 221 dts: 141312 type: audio packet #: 222 dts: 142336 type: audio packet #: 223 dts: 246551 type: video * packet #: 224 dts: 249554 type: video * packet #: 225 dts: 252557 type: video * packet #: 226 dts: 255560 type: video * packet #: 227 dts: 258563 type: video * packet #: 228 dts: 261566 type: video * packet #: 229 dts: 264569 type: video * packet #: 230 dts: 267572 type: video * packet #: 231 dts: 143360 type: audio packet #: 232 dts: 144384 type: audio packet #: 233 dts: 145408 type: audio packet #: 234 dts: 146432 type: audio packet #: 235 dts: 147456 type: audio packet #: 236 dts: 148480 type: audio packet #: 237 dts: 149504 type: audio packet #: 238 dts: 150528 type: audio packet #: 239 dts: 151552 type: audio packet #: 240 dts: 152576 type: audio packet #: 241 dts: 153600 type: audio packet #: 242 dts: 154624 type: audio packet #: 243 dts: 155648 type: audio packet #: 244 dts: 156672 type: audio packet #: 245 dts: 270575 type: video * packet #: 246 dts: 273578 type: video * packet #: 247 dts: 277334 type: video * packet #: 248 dts: 281087 type: video * packet #: 249 dts: 157696 type: audio packet #: 250 dts: 158720 type: audio packet #: 251 dts: 159744 type: audio packet #: 252 dts: 160768 type: audio packet #: 253 dts: 161792 type: audio packet #: 254 dts: 162816 type: audio packet #: 255 dts: 163840 type: audio packet #: 256 dts: 284840 type: video * packet #: 257 dts: 288593 type: video * packet #: 258 dts: 291596 type: video * packet #: 259 dts: 294599 type: video * packet #: 260 dts: 297602 type: video * packet #: 261 dts: 300605 type: video * packet #: 262 dts: 303608 type: video * packet #: 263 dts: 306611 type: video * packet #: 264 dts: 164864 type: audio packet #: 265 dts: 165888 type: audio packet #: 266 dts: 166912 type: audio packet #: 267 dts: 167936 type: audio packet #: 268 dts: 168960 type: audio packet #: 269 dts: 169984 type: audio packet #: 270 dts: 171008 type: audio packet #: 271 dts: 309614 type: video * packet #: 272 dts: 312617 type: video * packet #: 273 dts: 315620 type: video * packet #: 274 dts: 318623 type: video * packet #: 275 dts: 172032 type: audio packet #: 276 dts: 173056 type: audio packet #: 277 dts: 174080 type: audio packet #: 278 dts: 175104 type: audio packet #: 279 dts: 176128 type: audio packet #: 280 dts: 177152 type: audio packet #: 281 dts: 178176 type: audio packet #: 282 dts: 321626 type: video * packet #: 283 dts: 324629 type: video * packet #: 284 dts: 327632 type: video * packet #: 285 dts: 330635 type: video * packet #: 286 dts: 179200 type: audio packet #: 287 dts: 180224 type: audio packet #: 288 dts: 181248 type: audio packet #: 289 dts: 182272 type: audio packet #: 290 dts: 183296 type: audio packet #: 291 dts: 184320 type: audio packet #: 292 dts: 185344 type: audio packet #: 293 dts: 333638 type: video * packet #: 294 dts: 336641 type: video * packet #: 295 dts: 339644 type: video * packet #: 296 dts: 342647 type: video * packet #: 297 dts: 186368 type: audio packet #: 298 dts: 187392 type: audio packet #: 299 dts: 188416 type: audio packet #: 300 dts: 189440 type: audio packet #: 301 dts: 190464 type: audio packet #: 302 dts: 191488 type: audio packet #: 303 dts: 192512 type: audio packet #: 304 dts: 345650 type: video * packet #: 305 dts: 348653 type: video * packet #: 306 dts: 351656 type: video * packet #: 307 dts: 354659 type: video * packet #: 308 dts: 193536 type: audio packet #: 309 dts: 194560 type: audio packet #: 310 dts: 195584 type: audio packet #: 311 dts: 196608 type: audio packet #: 312 dts: 197632 type: audio packet #: 313 dts: 198656 type: audio packet #: 314 dts: 199680 type: audio packet #: 315 dts: 357662 type: video * packet #: 316 dts: 360665 type: video * packet #: 317 dts: 363668 type: video * packet #: 318 dts: 366671 type: video * packet #: 319 dts: 200704 type: audio packet #: 320 dts: 201728 type: audio packet #: 321 dts: 202752 type: audio packet #: 322 dts: 203776 type: audio packet #: 323 dts: 204800 type: audio packet #: 324 dts: 205824 type: audio packet #: 325 dts: 206848 type: audio packet #: 326 dts: 369674 type: video * packet #: 327 dts: 372677 type: video * packet #: 328 dts: 375680 type: video * packet #: 329 dts: 378683 type: video * packet #: 330 dts: 207872 type: audio packet #: 331 dts: 208896 type: audio packet #: 332 dts: 209920 type: audio packet #: 333 dts: 210944 type: audio packet #: 334 dts: 211968 type: audio packet #: 335 dts: 212992 type: audio packet #: 336 dts: 214016 type: audio packet #: 337 dts: 381686 type: video * packet #: 338 dts: 384689 type: video * packet #: 339 dts: 387692 type: video * packet #: 340 dts: 390695 type: video * packet #: 341 dts: 215040 type: audio packet #: 342 dts: 216064 type: audio packet #: 343 dts: 217088 type: audio packet #: 344 dts: 218112 type: audio packet #: 345 dts: 219136 type: audio packet #: 346 dts: 220160 type: audio packet #: 347 dts: 221184 type: audio packet #: 348 dts: 393698 type: video * packet #: 349 dts: 397454 type: video * packet #: 350 dts: 401207 type: video * packet #: 351 dts: 404960 type: video * packet #: 352 dts: 222208 type: audio packet #: 353 dts: 223232 type: audio packet #: 354 dts: 224256 type: audio packet #: 355 dts: 225280 type: audio packet #: 356 dts: 226304 type: audio packet #: 357 dts: 227328 type: audio packet #: 358 dts: 228352 type: audio packet #: 359 dts: 408713 type: video * packet #: 360 dts: 411716 type: video * packet #: 361 dts: 414719 type: video * packet #: 362 dts: 417722 type: video * packet #: 363 dts: 229376 type: audio packet #: 364 dts: 230400 type: audio packet #: 365 dts: 231424 type: audio packet #: 366 dts: 232448 type: audio packet #: 367 dts: 233472 type: audio packet #: 368 dts: 234496 type: audio packet #: 369 dts: 235520 type: audio packet #: 370 dts: 420725 type: video * packet #: 371 dts: 423728 type: video * packet #: 372 dts: 427484 type: video * packet #: 373 dts: 431237 type: video * packet #: 374 dts: 236544 type: audio packet #: 375 dts: 237568 type: audio packet #: 376 dts: 238592 type: audio packet #: 377 dts: 239616 type: audio packet #: 378 dts: 240640 type: audio packet #: 379 dts: 241664 type: audio packet #: 380 dts: 242688 type: audio packet #: 381 dts: 434990 type: video * packet #: 382 dts: 438743 type: video * packet #: 383 dts: 441746 type: video * packet #: 384 dts: 444749 type: video * packet #: 385 dts: 243712 type: audio packet #: 386 dts: 244736 type: audio packet #: 387 dts: 245760 type: audio packet #: 388 dts: 246784 type: audio packet #: 389 dts: 247808 type: audio packet #: 390 dts: 248832 type: audio packet #: 391 dts: 249856 type: audio packet #: 392 dts: 447752 type: video * packet #: 393 dts: 450755 type: video * packet #: 394 dts: 453758 type: video * packet #: 395 dts: 457514 type: video * packet #: 396 dts: 250880 type: audio packet #: 397 dts: 251904 type: audio packet #: 398 dts: 252928 type: audio packet #: 399 dts: 253952 type: audio packet #: 400 dts: 254976 type: audio packet #: 401 dts: 256000 type: audio packet #: 402 dts: 257024 type: audio packet #: 403 dts: 461267 type: video * packet #: 404 dts: 465020 type: video * packet #: 405 dts: 468773 type: video * packet #: 406 dts: 471776 type: video * packet #: 407 dts: 258048 type: audio packet #: 408 dts: 259072 type: audio packet #: 409 dts: 260096 type: audio packet #: 410 dts: 261120 type: audio packet #: 411 dts: 262144 type: audio packet #: 412 dts: 263168 type: audio packet #: 413 dts: 264192 type: audio packet #: 414 dts: 474779 type: video * packet #: 415 dts: 477782 type: video * packet #: 416 dts: 480785 type: video * packet #: 417 dts: 483788 type: video * packet #: 418 dts: 487544 type: video * packet #: 419 dts: 491297 type: video * packet #: 420 dts: 495050 type: video * packet #: 421 dts: 498803 type: video * packet #: 422 dts: 265216 type: audio packet #: 423 dts: 266240 type: audio packet #: 424 dts: 267264 type: audio packet #: 425 dts: 268288 type: audio packet #: 426 dts: 269312 type: audio packet #: 427 dts: 270336 type: audio packet #: 428 dts: 271360 type: audio packet #: 429 dts: 272384 type: audio packet #: 430 dts: 273408 type: audio packet #: 431 dts: 274432 type: audio packet #: 432 dts: 275456 type: audio packet #: 433 dts: 276480 type: audio packet #: 434 dts: 277504 type: audio packet #: 435 dts: 278528 type: audio packet #: 436 dts: 502559 type: video * packet #: 437 dts: 506312 type: video * packet #: 438 dts: 510065 type: video * packet #: 439 dts: 513818 type: video * packet #: 440 dts: 279552 type: audio packet #: 441 dts: 280576 type: audio packet #: 442 dts: 281600 type: audio packet #: 443 dts: 282624 type: audio packet #: 444 dts: 283648 type: audio packet #: 445 dts: 284672 type: audio packet #: 446 dts: 285696 type: audio packet #: 447 dts: 286720 type: audio packet #: 448 dts: 287744 type: audio packet #: 449 dts: 288768 type: audio packet #: 450 dts: 289792 type: audio packet #: 451 dts: 290816 type: audio packet #: 452 dts: 291840 type: audio packet #: 453 dts: 292864 type: audio packet #: 454 dts: 517574 type: video * packet #: 455 dts: 521327 type: video * packet #: 456 dts: 525080 type: video * packet #: 457 dts: 528833 type: video * packet #: 458 dts: 532589 type: video * packet #: 459 dts: 536342 type: video * packet #: 460 dts: 540095 type: video * packet #: 461 dts: 543848 type: video * packet #: 462 dts: 293888 type: audio packet #: 463 dts: 294912 type: audio packet #: 464 dts: 295936 type: audio packet #: 465 dts: 296960 type: audio packet #: 466 dts: 297984 type: audio packet #: 467 dts: 299008 type: audio packet #: 468 dts: 300032 type: audio packet #: 469 dts: 301056 type: audio packet #: 470 dts: 302080 type: audio packet #: 471 dts: 303104 type: audio packet #: 472 dts: 304128 type: audio packet #: 473 dts: 305152 type: audio packet #: 474 dts: 306176 type: audio packet #: 475 dts: 307200 type: audio packet #: 476 dts: 547604 type: video * packet #: 477 dts: 551357 type: video * packet #: 478 dts: 555110 type: video * packet #: 479 dts: 558863 type: video * packet #: 480 dts: 562619 type: video * packet #: 481 dts: 566372 type: video * packet #: 482 dts: 570125 type: video * packet #: 483 dts: 573878 type: video * packet #: 484 dts: 308224 type: audio packet #: 485 dts: 309248 type: audio packet #: 486 dts: 310272 type: audio packet #: 487 dts: 311296 type: audio packet #: 488 dts: 312320 type: audio packet #: 489 dts: 313344 type: audio packet #: 490 dts: 314368 type: audio packet #: 491 dts: 315392 type: audio packet #: 492 dts: 316416 type: audio packet #: 493 dts: 317440 type: audio packet #: 494 dts: 318464 type: audio packet #: 495 dts: 319488 type: audio packet #: 496 dts: 320512 type: audio packet #: 497 dts: 321536 type: audio packet #: 498 dts: 577634 type: video * packet #: 499 dts: 581387 type: video * packet #: 500 dts: 585140 type: video * packet #: 501 dts: 588893 type: video * packet #: 502 dts: 592649 type: video * packet #: 503 dts: 596402 type: video * packet #: 504 dts: 600155 type: video * Got video frame at time 592649
However, if I change av_seek_frame()
to use stream_index = 0
, I still get a seek result of 0 (indicating success) but I get the following (desired) output:
packet #: 0 dts: 0 type: audio packet #: 1 dts: 1024 type: audio packet #: 2 dts: 2048 type: audio packet #: 3 dts: 3072 type: audio packet #: 4 dts: 4096 type: audio packet #: 5 dts: 5120 type: audio packet #: 6 dts: 6144 type: audio packet #: 7 dts: -6006 type: video * packet #: 8 dts: -3003 type: video * packet #: 9 dts: 0 type: video * packet #: 10 dts: 3003 type: video * packet #: 11 dts: 7168 type: audio packet #: 12 dts: 8192 type: audio packet #: 13 dts: 9216 type: audio packet #: 14 dts: 10240 type: audio packet #: 15 dts: 11264 type: audio packet #: 16 dts: 12288 type: audio packet #: 17 dts: 13312 type: audio packet #: 18 dts: 6006 type: video * Got video frame at time 0
ffprobe's output for the first several packets, showing that a video frame exists and how the two video packets with DTS = -6006 and -3003 are skipped:
ffprobe -show_packets SIMPSONS_D2-CallOfTheSimpsons.m4v ffprobe version N-45279-g1a104bf Copyright (c) 2007-2012 the FFmpeg developers built on Oct 10 2012 19:19:16 with gcc 4.7.2 (GCC) configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 51. 74.100 / 51. 74.100 libavcodec 54. 65.100 / 54. 65.100 libavformat 54. 31.100 / 54. 31.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 19.102 / 3. 19.102 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 16.100 / 0. 16.100 libpostproc 52. 1.100 / 52. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'SIMPSONS_D2-CallOfTheSimpsons.m4v': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42isomavc1 encoder : HandBrake 0.9.5 2011010300 Duration: 00:23:06.51, start: 0.000000, bitrate: 1944 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x480 [SAR 118:135 DAR 59:45], 1774 kb/s, 25.50 fps, 29.97 tbr, 90k tbn, 180k tbc Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 164 kb/s Stream #0:2(und): Subtitle: mov_text (text / 0x74786574) [PACKET] codec_type=audio stream_index=1 pts=0 pts_time=0.000000 dts=0 dts_time=0.000000 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=6 pos=168 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=1024 pts_time=0.021333 dts=1024 dts_time=0.021333 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=21 pos=174 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=2048 pts_time=0.042667 dts=2048 dts_time=0.042667 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=10 pos=195 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=3072 pts_time=0.064000 dts=3072 dts_time=0.064000 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=10 pos=205 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=4096 pts_time=0.085333 dts=4096 dts_time=0.085333 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=10 pos=215 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=5120 pts_time=0.106667 dts=5120 dts_time=0.106667 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=10 pos=225 flags=K [/PACKET] [PACKET] codec_type=audio stream_index=1 pts=6144 pts_time=0.128000 dts=6144 dts_time=0.128000 duration=1024 duration_time=0.021333 convergence_duration=N/A convergence_duration_time=N/A size=10 pos=235 flags=K [/PACKET] [PACKET] codec_type=video stream_index=0 pts=0 pts_time=0.000000 dts=-6006 dts_time=-0.066733 duration=N/A duration_time=N/A convergence_duration=N/A convergence_duration_time=N/A size=36509 pos=245 flags=K [/PACKET] [PACKET] codec_type=video stream_index=0 pts=3003 pts_time=0.033367 dts=-3003 dts_time=-0.033367 duration=N/A duration_time=N/A convergence_duration=N/A convergence_duration_time=N/A size=35 pos=36754 flags=_ [/PACKET] [PACKET] codec_type=video stream_index=0 pts=9009 pts_time=0.100100 dts=0 dts_time=0.000000 duration=N/A duration_time=N/A convergence_duration=N/A convergence_duration_time=N/A size=32245 pos=36789 flags=_ [/PACKET]
This bug seems to still exist as of ffmpeg 2.2. It's particularly bad when seeking to 0 and the first frame contains the first key frame. It gets dropped so when decoding finally gets going there's a bunch of grey goo of delta frames until the second key frame.