Skip to content

Commit

Permalink
Added simple avifdump tool for aiding in AVIF debugging (work in pr…
Browse files Browse the repository at this point in the history
…ogress)
  • Loading branch information
Joe Drago committed Apr 15, 2020
1 parent 3e5134c commit 21bc4df
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added simple `avifdump` tool for aiding in AVIF debugging

## [0.6.4] - 2020-04-14
### Added
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ if(AVIF_BUILD_APPS)
target_link_libraries(avifdec avif ${AVIF_PLATFORM_LIBRARIES} ${ZLIB_LIBRARY} ${PNG_LIBRARY})
target_include_directories(avifdec PRIVATE apps/shared ${PNG_PNG_INCLUDE_DIR})

add_executable(avifdump
apps/avifdump.c

apps/shared/avifutil.c
)
if(AVIF_LOCAL_LIBGAV1)
set_target_properties(avifdump PROPERTIES LINKER_LANGUAGE "CXX")
endif()
target_link_libraries(avifdump avif ${AVIF_PLATFORM_LIBRARIES} ${ZLIB_LIBRARY} ${PNG_LIBRARY})
target_include_directories(avifdump PRIVATE apps/shared ${PNG_PNG_INCLUDE_DIR})

if(NOT SKIP_INSTALL_APPS AND NOT SKIP_INSTALL_ALL)
install(TARGETS avifenc avifdec
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
Expand Down
88 changes: 88 additions & 0 deletions apps/avifdump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2019 Joe Drago. All rights reserved.
// SPDX-License-Identifier: BSD-2-Clause

#include "avif/avif.h"

#include "avifutil.h"

#include <stdio.h>
#include <string.h>

int syntax(void)
{
printf("Syntax: aviffuzz input.avif\n");
return 0;
}

int main(int argc, char * argv[])
{
const char * inputFilename = NULL;
if (argc < 2) {
return 0;
}
inputFilename = argv[1];

FILE * inputFile = fopen(inputFilename, "rb");
if (!inputFile) {
fprintf(stderr, "Cannot open file for read: %s\n", inputFilename);
return 1;
}
fseek(inputFile, 0, SEEK_END);
size_t inputFileSize = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);

if (inputFileSize < 1) {
fprintf(stderr, "File too small: %s\n", inputFilename);
fclose(inputFile);
return 1;
}

avifRWData raw = AVIF_DATA_EMPTY;
avifRWDataRealloc(&raw, inputFileSize);
if (fread(raw.data, 1, inputFileSize, inputFile) != inputFileSize) {
fprintf(stderr, "Failed to read %zu bytes: %s\n", inputFileSize, inputFilename);
fclose(inputFile);
avifRWDataFree(&raw);
return 1;
}

fclose(inputFile);
inputFile = NULL;

avifDecoder * decoder = avifDecoderCreate();
avifResult result = avifDecoderParse(decoder, (avifROData *)&raw);
if (result == AVIF_RESULT_OK) {
printf("Image decoded: %s\n", inputFilename);

int frameIndex = 0;
avifBool firstImage = AVIF_TRUE;
while (avifDecoderNextImage(decoder) == AVIF_RESULT_OK) {
if (firstImage) {
firstImage = AVIF_FALSE;
avifImageDump(decoder->image);

printf(" * %zu timescales per second, %2.2f seconds (%zu timescales), %d frame%s\n",
decoder->timescale,
decoder->duration,
decoder->durationInTimescales,
decoder->imageCount,
(decoder->imageCount == 1) ? "" : "s");
printf(" * Frames:\n");
}

printf(" * Decoded frame [%d] [pts %2.2f (%zu timescales)] [duration %2.2f (%zu timescales)]\n",
frameIndex,
decoder->imageTiming.pts,
decoder->imageTiming.ptsInTimescales,
decoder->imageTiming.duration,
decoder->imageTiming.durationInTimescales);
++frameIndex;
}
} else {
printf("ERROR: Failed to decode image: %s\n", avifResultToString(result));
}

avifRWDataFree(&raw);
avifDecoderDestroy(decoder);
return 0;
}
1 change: 0 additions & 1 deletion apps/shared/avifutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void avifImageDump(avifImage * avif)
printf(" * imir (Mirror) : %u (%s)\n", avif->imir.axis, (avif->imir.axis == 0) ? "Vertical" : "Horizontal");
}
}
printf("\n");
}

void avifPrintVersions(void)
Expand Down

0 comments on commit 21bc4df

Please sign in to comment.