| 47 | static int header = 0; |
| 48 | |
| 49 | static int decode(AVCodecContext *dec_ctx, AVFrame *frame, |
| 50 | AVPacket *pkt) |
| 51 | { |
| 52 | static uint64_t frame_cnt = 0; |
| 53 | int ret; |
| 54 | |
| 55 | ret = avcodec_send_packet(dec_ctx, pkt); |
| 56 | if (ret < 0) { |
| 57 | fprintf(stderr, "Error sending a packet for decoding: %s\n", av_err2str(ret)); |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | while (ret >= 0) { |
| 62 | const AVPixFmtDescriptor *desc; |
| 63 | char sum[AV_HASH_MAX_SIZE * 2 + 1]; |
| 64 | struct AVHashContext *hash; |
| 65 | |
| 66 | ret = avcodec_receive_frame(dec_ctx, frame); |
| 67 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { |
| 68 | return 0; |
| 69 | } else if (ret < 0) { |
| 70 | fprintf(stderr, "Error during decoding: %s\n", av_err2str(ret)); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | if (!header) { |
| 75 | printf( |
| 76 | "#format: frame checksums\n" |
| 77 | "#version: 2\n" |
| 78 | "#hash: MD5\n" |
| 79 | "#tb 0: 1/30\n" |
| 80 | "#media_type 0: video\n" |
| 81 | "#codec_id 0: rawvideo\n" |
| 82 | "#dimensions 0: 352x288\n" |
| 83 | "#sar 0: 128/117\n" |
| 84 | "#stream#, dts, pts, duration, size, hash\n"); |
| 85 | header = 1; |
| 86 | } |
| 87 | desc = av_pix_fmt_desc_get(dec_ctx->pix_fmt); |
| 88 | if ((ret = av_hash_alloc(&hash, "md5")) < 0) { |
| 89 | return ret; |
| 90 | } |
| 91 | av_hash_init(hash); |
| 92 | |
| 93 | for (int i = 0; i < frame->height; i++) |
| 94 | av_hash_update(hash, &frame->data[0][i * frame->linesize[0]], frame->width); |
| 95 | for (int i = 0; i < frame->height >> desc->log2_chroma_h; i++) |
| 96 | av_hash_update(hash, &frame->data[1][i * frame->linesize[1]], frame->width >> desc->log2_chroma_w); |
| 97 | for (int i = 0; i < frame->height >> desc->log2_chroma_h; i++) |
| 98 | av_hash_update(hash, &frame->data[2][i * frame->linesize[2]], frame->width >> desc->log2_chroma_w); |
| 99 | |
| 100 | av_hash_final_hex(hash, sum, av_hash_get_size(hash) * 2 + 1); |
| 101 | printf("0, %10"PRId64", %10"PRId64", 1, %8d, %s\n", |
| 102 | frame_cnt, frame_cnt, |
| 103 | (frame->width * frame->height + 2 * (frame->height >> desc->log2_chroma_h) * (frame->width >> desc->log2_chroma_w)), sum); |
| 104 | frame_cnt += 1; |
| 105 | av_hash_freep(&hash); |
| 106 | } |
no test coverage detected