test_thumbnailffmpeg.c (3259B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2013, 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_thumbnailffmpeg.c 22 * @brief testcase for the thumbnailffmpeg plugin 23 * @author Christian Grothoff 24 * 25 * The encoder's output depends on the FFmpeg version, so the JPEG can 26 * only be checked for its magic number. The PNG round, on the other 27 * hand, is decoded: testdata/thumbnail_pattern.ogv is black for the 28 * first 20 seconds and red afterwards, so the colour of the thumbnail 29 * says whether the plugin really sampled where it claims to. 30 */ 31 #include "platform.h" 32 #include "test_lib.h" 33 #include "test_media_lib.h" 34 35 36 /** 37 * Check that the thumbnail was taken from the red part of the video. 38 * 39 * @param data the PNG the plugin produced 40 * @param data_len number of bytes in @a data 41 * @return non-zero if the thumbnail looks right 42 */ 43 static int 44 validate_red (const void *data, 45 size_t data_len) 46 { 47 return TEST_media_png_center_is (data, 48 data_len, 49 0xFE, 50 0x00, 51 0x00); 52 } 53 54 55 /** 56 * Main function for the thumbnailffmpeg testcase. 57 * 58 * @param argc number of arguments (ignored) 59 * @param argv arguments (ignored) 60 * @return 0 on success 61 */ 62 int 63 main (int argc, char *argv[]) 64 { 65 uint8_t jpeg_magic[] = { 0xFF, 0xD8, 0xFF }; 66 uint8_t png_magic[] = { 137, 'P', 'N', 'G', '\r', '\n', 26, '\n' }; 67 struct SolutionData thumbnail_jpeg_sol[] = { 68 { 69 EXTRACTOR_METATYPE_THUMBNAIL, 70 EXTRACTOR_METAFORMAT_BINARY, 71 "image/jpeg", 72 (const char *) jpeg_magic, 73 sizeof (jpeg_magic), 74 0 75 }, 76 { 0, 0, NULL, NULL, 0, -1 } 77 }; 78 struct SolutionData thumbnail_png_sol[] = { 79 { 80 EXTRACTOR_METATYPE_THUMBNAIL, 81 EXTRACTOR_METAFORMAT_BINARY, 82 "image/png", 83 (const char *) png_magic, 84 sizeof (png_magic), 85 0, 86 0, 87 &validate_red 88 }, 89 { 0, 0, NULL, NULL, 0, -1 } 90 }; 91 struct ProblemSet ps_jpeg[] = { 92 { "testdata/thumbnail_pattern.ogv", 93 thumbnail_jpeg_sol }, 94 { NULL, NULL } 95 }; 96 struct ProblemSet ps_png[] = { 97 { "testdata/thumbnail_pattern.ogv", 98 thumbnail_png_sol }, 99 { NULL, NULL } 100 }; 101 int ret; 102 103 ret = ET_main ("thumbnailffmpeg", 104 ps_jpeg); 105 if (0 != ret) 106 return ret; 107 return ET_main ("thumbnailffmpeg(format=png,size=32)", 108 ps_png); 109 } 110 111 112 /* end of test_thumbnailffmpeg.c */