Changes between Initial Version and Version 1 of Ticket #1831
- Timestamp:
- 10/18/2012 09:42:45 PM (7 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #1831
- Property Component changed from undetermined to avformat
-
Ticket #1831 – Description
initial v1 21 21 if (!frame) 22 22 { 23 std::cout << "Error allocating the frame" << std::endl;23 std::cout << "Error allocating the frame" << std::endl; 24 24 return 1; 25 25 } … … 29 29 { 30 30 av_free(frame); 31 std::cout << "Error opening the file" << std::endl;31 std::cout << "Error opening the file" << std::endl; 32 32 return 1; 33 33 } … … 37 37 av_free(frame); 38 38 av_close_input_file(formatContext); 39 std::cout << "Error finding the stream info" << std::endl;39 std::cout << "Error finding the stream info" << std::endl; 40 40 return 1; 41 41 } 42 42 43 AVStream* audioStream = NULL;44 for (unsigned int i = 0; i < formatContext->nb_streams; ++i)45 {46 if (formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)47 {48 audioStream = formatContext->streams[i];49 break;50 }51 }43 AVStream* audioStream = NULL; 44 for (unsigned int i = 0; i < formatContext->nb_streams; ++i) 45 { 46 if (formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) 47 { 48 audioStream = formatContext->streams[i]; 49 break; 50 } 51 } 52 52 53 53 if (audioStream == NULL) … … 55 55 av_free(frame); 56 56 av_close_input_file(formatContext); 57 std::cout << "Could not find any audio stream in the file" << std::endl;57 std::cout << "Could not find any audio stream in the file" << std::endl; 58 58 return 1; 59 59 } … … 66 66 av_free(frame); 67 67 av_close_input_file(formatContext); 68 std::cout << "Couldn't find a proper decoder" << std::endl;68 std::cout << "Couldn't find a proper decoder" << std::endl; 69 69 return 1; 70 70 } … … 73 73 av_free(frame); 74 74 av_close_input_file(formatContext); 75 std::cout << "Couldn't open the context with the decoder" << std::endl;75 std::cout << "Couldn't open the context with the decoder" << std::endl; 76 76 return 1; 77 77 } … … 80 80 av_init_packet(&packet); 81 81 82 int packetCount = 0;83 int decodedFrameCount = 0;82 int packetCount = 0; 83 int decodedFrameCount = 0; 84 84 while (av_read_frame(formatContext, &packet) == 0) 85 85 { 86 ++packetCount;86 ++packetCount; 87 87 if (packet.stream_index == audioStream->index) 88 88 { … … 92 92 if (frameFinished) 93 93 { 94 ++decodedFrameCount;95 }94 ++decodedFrameCount; 95 } 96 96 } 97 97 98 av_free_packet(&packet);98 av_free_packet(&packet); 99 99 } 100 100 101 std::cout << "packetCount: " << packetCount << "\tdecodedFrameCount: " << decodedFrameCount << std::endl;102 std::cout << "formatContext->iformat->flags: " << formatContext->iformat->flags << "\tno byte seeking: " << (formatContext->iformat->flags & AVFMT_NO_BYTE_SEEK) << std::endl;101 std::cout << "packetCount: " << packetCount << "\tdecodedFrameCount: " << decodedFrameCount << std::endl; 102 std::cout << "formatContext->iformat->flags: " << formatContext->iformat->flags << "\tno byte seeking: " << (formatContext->iformat->flags & AVFMT_NO_BYTE_SEEK) << std::endl; 103 103 104 avcodec_flush_buffers(codecContext);104 avcodec_flush_buffers(codecContext); 105 105 av_init_packet(&packet); 106 std::cout << "av_seek_frame() returned: " << av_seek_frame(formatContext, -1, 0, AVSEEK_FLAG_BYTE) << std::endl;107 108 packetCount = 0;109 decodedFrameCount = 0;106 std::cout << "av_seek_frame() returned: " << av_seek_frame(formatContext, -1, 0, AVSEEK_FLAG_BYTE) << std::endl; 107 108 packetCount = 0; 109 decodedFrameCount = 0; 110 110 while (av_read_frame(formatContext, &packet) == 0) 111 111 { 112 ++packetCount;112 ++packetCount; 113 113 if (packet.stream_index == audioStream->index) 114 114 { 115 // Try to decode the packet into a frame115 // Try to decode the packet into a frame 116 116 int frameFinished = 0; 117 117 avcodec_decode_audio4(codecContext, frame, &frameFinished, &packet); … … 119 119 if (frameFinished) 120 120 { 121 ++decodedFrameCount;122 }121 ++decodedFrameCount; 122 } 123 123 } 124 124 125 av_free_packet(&packet);125 av_free_packet(&packet); 126 126 } 127 127 128 std::cout << "packetCount: " << packetCount << "\tdecodedFrameCount: " << decodedFrameCount << std::endl;128 std::cout << "packetCount: " << packetCount << "\tdecodedFrameCount: " << decodedFrameCount << std::endl; 129 129 130 130 av_free(frame); … … 150 150 }}} 151 151 152 '''Alternative expected results:''' (if seeking really does fail )152 '''Alternative expected results:''' (if seeking really does fail because byte seeking is not allowed) 153 153 {{{ 154 154 packetCount: 526 decodedFrameCount: 259 155 formatContext->iformat->flags: 0 no byte seeking: 0155 formatContext->iformat->flags: 32768 no byte seeking: 32768 156 156 av_seek_frame() returned: -1 157 157 packetCount: 0 decodedFrameCount: 0


