Projects
Multimedia
nordlicht
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
nordlicht.spec
Changed
@@ -1,7 +1,7 @@ %define soname 0 Name: nordlicht -Version: 0.3.4 +Version: 0.3.5 Release: 0 License: GPL-2.0+ Summary: Creates colorful barcodes from video files
View file
_service:download_files:v0.3.4.tar.gz/test
Deleted
-(directory)
View file
_service:download_files:v0.3.4.tar.gz/test/test-bin.sh
Deleted
@@ -1,91 +0,0 @@ -#!/bin/bash - -pass() { - echo "Running '$@'" - $@ &> "$LOG" - exit_code=$? - - if test $exit_code != 0; then - cat "$LOG" - echo "command failed: $*" - exit 1 - fi - return 0 -} - -fail() { - echo "Running '$@'" - $@ &> "$LOG" - exit_code=$? - - if test $exit_code = 0; then - cat "$LOG" - echo "command succeded: $*" - exit 1 - elif test $exit_code -gt 129 -a $exit_code -le 192; then - echo "died by signal: $*" - exit 1 - elif test $exit_code = 127; then - echo "command not found: $*" - exit 1 - elif test $exit_code = 126; then - echo "valgrind error: $*" - exit 1 - fi - return 0 -} - -VIDEO='video.mp4' -LOG='test.log' -TMP="tests-tmp_$$/" - -mkdir "$TMP" && -ln -s ../nordlicht "$TMP" && -ln -s ../"$VIDEO" "$TMP" && -pushd "$TMP" || exit 1 - -# test environment -pass true -fail false -pass test -f "$VIDEO" - -# argument parsing -pass ./nordlicht --help -fail ./nordlicht -fail ./nordlicht --fubar -fail ./nordlicht "$VIDEO" somethingelse - -# input file -fail ./nordlicht nonexistantvideo.foo - -# size -pass ./nordlicht "$VIDEO" -w 1 -h 1 -pass ./nordlicht "$VIDEO" -w 1 -h 10000 -fail ./nordlicht "$VIDEO" -w huuuge -fail ./nordlicht "$VIDEO" -w 0 -fail ./nordlicht "$VIDEO" -h 0 -fail ./nordlicht "$VIDEO" -w '' -fail ./nordlicht "$VIDEO" -h '' -fail ./nordlicht "$VIDEO" -w -100 -fail ./nordlicht "$VIDEO" -h -100 -fail ./nordlicht "$VIDEO" -w 1.1 -fail ./nordlicht "$VIDEO" -h 1.1 -fail ./nordlicht "$VIDEO" -w 1,1 -fail ./nordlicht "$VIDEO" -h 1,1 - -# output file -pass ./nordlicht "$VIDEO" -w 1 -o ünîç⌀də.png -pass test -f ünîç⌀də.png -fail ./nordlicht "$VIDEO" -o ../"$TMP" -fail ./nordlicht "$VIDEO" -o "$VIDEO" -fail ./nordlicht "$VIDEO" -o '' - -# style -pass ./nordlicht "$VIDEO" -w 1 -s vertical -pass ./nordlicht "$VIDEO" -w 1 -s horizontal -fail ./nordlicht "$VIDEO" -s nope -fail ./nordlicht "$VIDEO" -s '' - -popd && rm -rv "$TMP" || exit 1 - -echo "All assertions passed. Yay!"
View file
_service:download_files:v0.3.4.tar.gz/.gitignore -> _service:download_files:v0.3.5.tar.gz/.gitignore
Changed
@@ -1,19 +1,19 @@ # Build products CMakeCache.txt CMakeFiles/ -CTestTestfile.cmake cmake_install.cmake +CTestTestfile.cmake libnordlicht.so libnordlicht.so.* Makefile nordlicht nordlicht.1 nordlicht.pc +testsuite version.h # Testing -Testing/ -tests-tmp_* +test_tmp_* video.mp4 *.png
View file
_service:download_files:v0.3.4.tar.gz/CMakeLists.txt -> _service:download_files:v0.3.5.tar.gz/CMakeLists.txt
Changed
@@ -1,7 +1,7 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.6) project(nordlicht C) -set(NORDLICHT_VERSION 0.3.4) +set(NORDLICHT_VERSION 0.3.5) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") set(LIB_SUFFIX "" CACHE STRING "Suffix of library directory name (for example '32' or '64')") @@ -12,7 +12,7 @@ find_package(PNG REQUIRED) find_package(Popt REQUIRED) -include_directories(${CMAKE_BINARY_DIR}/src ${FFMPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${POPT_INCLUDES}) +include_directories(${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/src ${FFMPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${POPT_INCLUDES}) add_library(nordlicht SHARED src/common.c src/graphics.c src/nordlicht.c src/video.c) set_target_properties(nordlicht PROPERTIES SOVERSION 0) @@ -22,6 +22,10 @@ set_target_properties(nordlicht-bin PROPERTIES OUTPUT_NAME nordlicht) target_link_libraries(nordlicht-bin nordlicht) +add_executable(testsuite tests/library.c) +target_link_libraries(testsuite nordlicht) +add_custom_target(test COMMAND testsuite COMMAND ${CMAKE_SOURCE_DIR}/tests/tool.sh) + configure_file(cmake/nordlicht.pc.in cmake/nordlicht.pc @ONLY) configure_file(src/version.h.in src/version.h @ONLY) add_custom_command(TARGET nordlicht-bin POST_BUILD
View file
_service:download_files:v0.3.4.tar.gz/README.md -> _service:download_files:v0.3.5.tar.gz/README.md
Changed
@@ -1,45 +1,58 @@ ![](examples/nordlicht-logo.png) -**nordlicht** is a C library for converting video files into colorful barcodes. It is inspired by the [Moviebarcode Tumblr](http://moviebarcode.tumblr.com/), but aims at the next logical step: Integrating these barcodes into video players to make navigation faster and more precise. +**nordlicht** is a C library for converting video files into colorful barcodes. It is inspired by the [Moviebarcode Tumblr](http://moviebarcode.tumblr.com/), but aims at the next step: Integrating these barcodes into video players to make navigation faster and more precise. *nordlicht* provides a command line tool, which you can use to generate your own barcodes easily. ## Examples -Here's the barcode for [Tears of Steel](http://tearsofsteel.org/). It was created by taking the movie's frames at regular intervals, scaling them to 1 pixel width, and appending them. You can differentiate inside and outside scenes, the credits, and the "secret" scene at the end: +Here's the barcode for [Tears of Steel](http://tearsofsteel.org/). *nordlicht* took the movie's frames at regular intervals, scaled them them to 1 pixel width, and appended them. You can differentiate inside and outside scenes, the credits, and the "secret" scene at the end: ![](examples/tears-of-steel.png) -This barcode of [Elephants Dream](http://www.elephantsdream.org/) uses the *vertical* style, which compresses video's frames to columns and rotates them counterclockwise. This style emphasizes the movement of characters: +This barcode of [Elephants Dream](http://www.elephantsdream.org/) uses the *vertical* style, which compresses video's frames to columns and rotates them 90 degrees counterclockwise. This style emphasizes the movement of characters: ![](examples/elephants-dream-vertical.png) ## Installation -- Arch Linux: Install the [`nordlicht`](https://aur.archlinux.org/packages/nordlicht/) package from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository) -- Gentoo: Install the `media-video/nordlicht` package from the [multimedia overlay](https://gitorious.org/gentoo-multimedia/gentoo-multimedia), [here's how](https://www.gentoo.org/proj/en/overlays/userguide.xml) -- On other distributions, get CMake, FFmpeg, libpng, [popt](http://freecode.com/projects/popt), and [help2man](https://www.gnu.org/software/help2man/), and issue: `mkdir build && cd build && cmake .. && make && make install` +There are packages for some Linux distributions: + +- Arch Linux: Install [`nordlicht`](https://aur.archlinux.org/packages/nordlicht/) from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository) +- Gentoo: Install `media-video/nordlicht` from the *multimedia* [overlay](https://www.gentoo.org/proj/en/overlays/userguide.xml) +- openSUSE: Install [`nordlicht`](http://packman.links2linux.de/package/nordlicht) from [Packman](http://en.opensuse.org/Additional_package_repositories#Packman)'s *Multimedia* project +- Ubuntu: Install `nordlicht` from Launchpad's [ppa:blinry/nordlicht](https://launchpad.net/~blinry/+archive/nordlicht), [here's how](https://help.launchpad.net/Packaging/PPA/InstallingSoftware) + +On other operating systems, get CMake, FFmpeg/libav, libpng, [popt](http://freecode.com/projects/popt), and [help2man](https://www.gnu.org/software/help2man/), and issue: `cmake .. && make` to create the `nordlicht` binary. Consider [contributing](#contributing) a package! ## Usage ### Command line tool -Basic usage: `nordlicht video.mkv -w 1000 -h 150 -o barcode.png` converts *video.mkv* to a barcode of 1000 x 150 pixels size and writes it to *barcode.png*. Run `nordlicht --help` to learn more. +Basic usage: `nordlicht video.mp4 -w 1000 -h 150 -o barcode.png` converts *video.mp4* to a barcode of 1000 x 150 pixels size and writes it to *barcode.png*. Run `nordlicht --help` to learn more. ### Library - API documentation: see [src/nordlicht.h](src/nordlicht.h) -- Simple usage example: see [src/main.c](src/main.c) +- Usage examples: see [examples/nordlicht-example.c](examples/nordlicht-example.c) ## Integrations ### mpv -For very recent versions of [mpv](http://mpv.io/), there is an experimental [lua plugin](/utils/mpv-nordlicht.lua). Simply put it in `~/.mpv/lua/` (or symlink it there!) and mpv should display a live-updating barcode of the current video file. You can turn it on and off by pressing `n`. You'll need a version of mpv after commit `d706f81` (>= v0.3.6) and ImageMagick! This is how it looks like (for [Decay](http://www.decayfilm.com/)): +For [mpv](http://mpv.io/) (>= 0.3.6), there is an experimental [lua plugin](/utils/mpv-nordlicht.lua). Symlink the file from `~/.mpv/lua/`, and mpv displays a live-updating barcode of the current video file at the top. You can turn it on and off by pressing `n`. You'll need ImageMagick! This is how it looks like (for [Decay](http://www.decayfilm.com/)): ![](/examples/mpv-integration.png) -For versions >= 0.2.0, there is an older script called [mpv-nordlicht](/utils/mpv-nordlicht). Put it in your `PATH` and use it instead of `mpv`. It doesn't support multiple files, and you cannot hide the barcode. +For mpv >= 0.2.0, there is an older script called [mpv-nordlicht](/utils/mpv-nordlicht). Put it in your `PATH` and use it instead of `mpv`. It doesn't support multiple files, and you cannot hide the barcode. + +## Contributing + +Development of *nordlicht* happens on GitHub. Please report any bugs or ideas to the [issue tracker](https://github.com/blinry/nordlicht/issues). To contribute code, fork the repository and submit a pull request. + +You can also help by packaging the software for your favorite operating system, or writing an integration for your favorite video player. Even rough prototypes are highly appreciated! + +*nordlicht* uses [semantic versioning](http://semver.org/). ## License: GPLv2+
View file
_service:download_files:v0.3.4.tar.gz/Vagrantfile -> _service:download_files:v0.3.5.tar.gz/Vagrantfile
Changed
@@ -4,6 +4,7 @@ c.vm.box_url = "http://files.vagrantup.com/precise64.box" c.vm.provision :shell, :path => "utils/bootstrap-debian.sh" c.vm.synced_folder ".", "/home/vagrant/nordlicht" + c.vm.synced_folder "~/.gnupg", "/home/vagrant/.gnupg" c.ssh.forward_agent = true end config.vm.define "debian" do |c| @@ -11,6 +12,7 @@ c.vm.box_url = "https://dl.dropboxusercontent.com/u/197673519/debian-7.2.0.box" c.vm.provision :shell, :path => "utils/bootstrap-debian.sh" c.vm.synced_folder ".", "/home/vagrant/nordlicht" + c.vm.synced_folder "~/.gnupg", "/home/vagrant/.gnupg" c.ssh.forward_agent = true end config.vm.define "gentoo" do |c|
View file
_service:download_files:v0.3.5.tar.gz/examples/nordlicht-example.c
Added
@@ -0,0 +1,74 @@ +// Compile with: `cc nordlicht-example.c -lnordlicht -lpthread -o nordlicht-example` + +#include <pthread.h> +#include <unistd.h> +#include <nordlicht.h> + +int main(int argc, const char **argv) { + nordlicht *n; + + char *input_file = "video.mp4"; + int width = 1000; + int height = 100; + + /*** USE CASE 1: Generate a barcode in the background ***/ + + // Initialize a new nordlicht: + n = nordlicht_init(input_file, width, height); + if (n == NULL) { + exit(1); + } + + // Generate the barcode: + if (nordlicht_generate(n) != 0) { + exit(1); + } + + // You can access the pixel buffer, it's in 32-bit BGRA format: + const unsigned char *data = nordlicht_buffer(n); + + // You can also write the barcode to a PNG file: + if (nordlicht_write(n, "barcode.png") != 0) { + exit(1); + } + + // When you're done, free the nordlicht: + nordlicht_free(n); + + + /*** USE CASE 2: Generate a barcode "live", into a buffer supplied by you ***/ + + // Initialize a new nordlicht: + n = nordlicht_init(input_file, width, height); + + // Allocate a buffer of the correct size and tell nordlicht to use it: + unsigned char *data2 = malloc(nordlicht_buffer_size(n)); + nordlicht_set_buffer(n, data2); + + // Set the style to "horizontal", which will compress the frames to a column: + nordlicht_set_style(n, NORDLICHT_STYLE_HORIZONTAL); + + // Set the strategy to "live", which gives you a rough approximation + // faster. This is nice if you generate the barcode in front of the user's eyes: + nordlicht_set_strategy(n, NORDLICHT_STRATEGY_LIVE); + + // Start the generation in a thread: + pthread_t thread; + pthread_create(&thread, NULL, (void*(*)(void*))nordlicht_generate, n); + + // Until it's done, check the progress ten times a second: + float progress = 0; + while (progress < 1) { + progress = nordlicht_progress(n); + // (Display the progress) + // (Redraw the buffer) + usleep(100000); + } + pthread_join(thread, NULL); + + // Since you called nordlicht_set_buffer, you own the buffer: + free(data2); + + // Free the nordlicht: + nordlicht_free(n); +}
View file
_service:download_files:v0.3.4.tar.gz/src/graphics.c -> _service:download_files:v0.3.5.tar.gz/src/graphics.c
Changed
@@ -10,9 +10,9 @@ float factor = 1.0*c->length/length; int i; - for(i=0; i<length; i++) { - int lower = factor*i+0.5; - int upper = factor*(i+1)-0.5; + for (i = 0; i < length; i++) { + int lower = factor*i + 0.5; + int upper = factor*(i+1) - 0.5; if (lower > upper) { // this can happen when upscaling. pick nearest-neighbour entry: @@ -23,7 +23,7 @@ int gsum = 0; int bsum = 0; int j; - for(j=lower; j<=upper; j++) { + for (j = lower; j <= upper; j++) { rsum += c->data[j*3+0]; gsum += c->data[j*3+1]; bsum += c->data[j*3+2]; @@ -49,11 +49,11 @@ int x, y; int step = i->width/20; - for (y=0; y<i->height; y++) { + for (y = 0; y < i->height; y++) { long rsum = 0; long gsum = 0; long bsum = 0; - for (x=0; x<i->width; x+=step) { + for (x = 0; x < i->width; x += step) { rsum += i->data[y*i->width*3+3*x+0]; gsum += i->data[y*i->width*3+3*x+1]; bsum += i->data[y*i->width*3+3*x+2]; @@ -74,11 +74,11 @@ int x, y; int step = 1; - for (x=0; x<i->width; x++) { + for (x = 0; x < i->width; x++) { long rsum = 0; long gsum = 0; long bsum = 0; - for (y=0; y<i->height; y+=step) { + for (y = 0; y < i->height; y += step) { rsum += i->data[y*i->width*3+3*x+0]; gsum += i->data[y*i->width*3+3*x+1]; bsum += i->data[y*i->width*3+3*x+2];
View file
_service:download_files:v0.3.4.tar.gz/src/main.c -> _service:download_files:v0.3.5.tar.gz/src/main.c
Changed
@@ -11,13 +11,25 @@ return base ? base+1 : path; } +const char *filename_ext(const char *path) { + const char *dot = strrchr(path, '.'); + if (!dot || dot == path) return ""; + return dot+1; +} + void print_help(poptContext popt, int ret) { poptPrintHelp(popt, ret == 0 ? stdout : stderr, 0); + printf("\n\ +Examples:\n\ + nordlicht video.mp4 generate video.mp4.png of 1000 x 100 pixels size\n\ + nordlicht video.mp4 --style=vertical compress individual frames to columns\n\ + nordlicht video.mp4 -w 1920 -h 200 -o barcode.png override size and name of the output file\n\ +"); exit(ret); } -void interesting_stuff(char *filename, char *output_file, int width, int height, nordlicht_style style, int live) { - nordlicht *n = nordlicht_init(filename, width, height, live); +void interesting_stuff(char *filename, char *output_file, int width, int height, nordlicht_style style, nordlicht_strategy strategy) { + nordlicht *n = nordlicht_init(filename, width, height); unsigned char *data = NULL; if (n == NULL) { @@ -25,8 +37,9 @@ } nordlicht_set_style(n, style); + nordlicht_set_strategy(n, strategy); - if (live) { + if (strategy == NORDLICHT_STRATEGY_LIVE) { int fd = open(output_file, O_CREAT | O_TRUNC | O_RDWR, 0666); if (fd == -1) { error("Could not open '%s'.", output_file); @@ -54,7 +67,7 @@ } pthread_join(thread, NULL); - if (!live) { + if (strategy != NORDLICHT_STRATEGY_LIVE) { nordlicht_write(n, output_file); } @@ -71,25 +84,24 @@ char *output_file = NULL; char *style_string = NULL; nordlicht_style style; + nordlicht_strategy strategy; int free_output_file = 0; int help = 0; int version = 0; - int live = 0; struct poptOption optionsTable[] = { {"width", 'w', POPT_ARG_INT, &width, 0, "set the barcode's width; by default it's \"height*10\", or 1000 pixels, if both are undefined", NULL}, {"height", 'h', POPT_ARG_INT, &height, 0, "set the barcode's height; by default it's \"width/10\"", NULL}, - {"output", 'o', POPT_ARG_STRING, &output_file, 0, "set filename of output PNG; the default is $(basename VIDEOFILE).png", "FILENAME"}, + {"output", 'o', POPT_ARG_STRING, &output_file, 0, "set output filename, the default is $(basename VIDEOFILE).png; when you specify an *.bgra file, you'll get a raw 32-bit BGRA file that is updated as the barcode is generated", "FILENAME"}, {"style", 's', POPT_ARG_STRING, &style_string, 0, "default is 'horizontal'; can also be 'vertical', which compresses the frames \"down\" to rows, rotates them counterclockwise by 90 degrees and then appends them", "STYLE"}, - {"live", '\0', 0, &live, 0, "generate a raw BGRA file instead of an PNG; you can display this file, it will update itself", NULL}, {"help", '\0', 0, &help, 0, "display this help and exit", NULL}, {"version", '\0', 0, &version, 0, "output version information and exit", NULL}, POPT_TABLEEND }; poptContext popt = poptGetContext(NULL, argc, argv, optionsTable, 0); - poptSetOtherOptionHelp(popt, "[OPTION]... VIDEOFILE\n"); + poptSetOtherOptionHelp(popt, "[OPTION]... VIDEOFILE\n\nOptions:"); char c; @@ -102,7 +114,7 @@ } if (version) { - printf("nordlicht %s\n", NORDLICHT_VERSION); + printf("nordlicht %s\n\nWritten by Sebastian Morr and contributors.\n", NORDLICHT_VERSION); return 0; } @@ -113,23 +125,18 @@ char *filename = (char*)poptGetArg(popt); if (filename == NULL) { - error("Please specify an input file."); + error("Please specify an input file.\n"); print_help(popt, 1); } if (poptGetArg(popt) != NULL) { - error("Please specify only one input file."); + error("Please specify only one input file.\n"); print_help(popt, 1); } if (output_file == NULL) { - if (live) { - output_file = malloc(snprintf(NULL, 0, "%s.bgra", gnu_basename(filename)) + 1); - sprintf(output_file, "%s.bgra", gnu_basename(filename)); - } else { - output_file = malloc(snprintf(NULL, 0, "%s.png", gnu_basename(filename)) + 1); - sprintf(output_file, "%s.png", gnu_basename(filename)); - } + output_file = malloc(snprintf(NULL, 0, "%s.png", gnu_basename(filename)) + 1); + sprintf(output_file, "%s.png", gnu_basename(filename)); free_output_file = 1; } @@ -155,12 +162,22 @@ } else if (strcmp(style_string, "vertical") == 0) { style = NORDLICHT_STYLE_VERTICAL; } else { - error("Unknown style '%s'.", style_string); + error("Unknown style '%s'.\n", style_string); print_help(popt, 1); } } - interesting_stuff(filename, output_file, width, height, style, live); + const char *ext = filename_ext(output_file); + if (strcmp(ext, "png") == 0) { + strategy = NORDLICHT_STRATEGY_FAST; + } else if (strcmp(ext, "bgra") == 0) { + strategy = NORDLICHT_STRATEGY_LIVE; + } else { + error("Unsupported file extension '%s'\n", ext); + print_help(popt, 1); + } + + interesting_stuff(filename, output_file, width, height, style, strategy); if (free_output_file) { free(output_file);
View file
_service:download_files:v0.3.4.tar.gz/src/nordlicht.c -> _service:download_files:v0.3.5.tar.gz/src/nordlicht.c
Changed
@@ -7,19 +7,20 @@ int width, height; char *filename; unsigned char *data; - int live; - nordlicht_style style; - int modifiable; + int owns_data; + int modifiable; + nordlicht_style style; + nordlicht_strategy strategy; float progress; video *source; }; size_t nordlicht_buffer_size(nordlicht *n) { - return n->width*n->height*4; + return n->width * n->height * 4; } -nordlicht* nordlicht_init(char *filename, int width, int height, int live) { +nordlicht* nordlicht_init(char *filename, int width, int height) { if (width < 1 || height < 1) { error("Dimensions must be positive (got %dx%d)", width, height); return NULL; @@ -34,9 +35,8 @@ n->data = calloc(nordlicht_buffer_size(n), 1); n->owns_data = 1; - n->live = !!live; - n->style = NORDLICHT_STYLE_HORIZONTAL; + n->strategy = NORDLICHT_STRATEGY_FAST; n->modifiable = 1; n->progress = 0; n->source = video_init(filename, width); @@ -58,14 +58,31 @@ free(n); } -void nordlicht_set_style(nordlicht *n, nordlicht_style s) { - if (n->modifiable) { - n->style = s; +int nordlicht_set_style(nordlicht *n, nordlicht_style s) { + if (! n->modifiable) { + return -1; + } + if (s < 0 || s > NORDLICHT_STYLE_VERTICAL) { + return -1; } + n->style = s; + return 0; +} + +int nordlicht_set_strategy(nordlicht *n, nordlicht_strategy s) { + if (! n->modifiable) { + return -1; + } + if (s < 0 || s > NORDLICHT_STRATEGY_LIVE) { + return -1; + } + n->strategy = s; + return 0; } unsigned char* get_column(nordlicht *n, int i) { - column *c = video_get_column(n->source, 1.0*(i+0.5-COLUMN_PRECISION/2.0)/n->width, 1.0*(i+0.5+COLUMN_PRECISION/2.0)/n->width, n->style); + column *c = video_get_column(n->source, 1.0*(i+0.5-COLUMN_PRECISION/2.0)/n->width, + 1.0*(i+0.5+COLUMN_PRECISION/2.0)/n->width, n->style); if (c == NULL) { return NULL; @@ -78,20 +95,25 @@ } int nordlicht_generate(nordlicht *n) { + n->modifiable = 0; + video_build_keyframe_index(n->source, n->width); int x, exact; - int do_a_fast_pass = n->live || !video_exact(n->source); + int do_a_fast_pass = (n->strategy == NORDLICHT_STRATEGY_LIVE) || !video_exact(n->source); int do_an_exact_pass = video_exact(n->source); - for(exact=(!do_a_fast_pass); exact<=do_an_exact_pass; exact++) { + for (exact = (!do_a_fast_pass); exact <= do_an_exact_pass; exact++) { video_set_exact(n->source, exact); - for (x=0; x<n->width; x++) { + for (x = 0; x < n->width; x++) { unsigned char *column = get_column(n, x); // TODO: Fill memory directly, no need to memcpy if (column) { int y; - for (y=0; y<n->height; y++) { - memcpy(n->data+n->width*4*y+4*x, column+3*y, 3); + for (y = 0; y < n->height; y++) { + // BGRA pixel format: + memcpy(n->data+n->width*4*y+4*x+2, column+3*y+0, 1); + memcpy(n->data+n->width*4*y+4*x+1, column+3*y+1, 1); + memcpy(n->data+n->width*4*y+4*x+0, column+3*y+2, 1); memset(n->data+n->width*4*y+4*x+3, 255, 1); } free(column); @@ -109,6 +131,11 @@ int nordlicht_write(nordlicht *n, char *filename) { int code = 0; + if (filename == NULL) { + error("Output filename must not be NULL"); + return -1; + } + if (strcmp(filename, "") == 0) { error("Output filename must not be empty"); return -1; @@ -118,12 +145,15 @@ if (realpath_output != NULL) { // output file exists char *realpath_input = realpath(n->filename, NULL); - if (strcmp(realpath_input, realpath_output) == 0) { - error("Will not overwrite input file"); - code = -1; - } + if (realpath_input != NULL) { + // otherwise, input filename is probably a URL - free(realpath_input); + if (strcmp(realpath_input, realpath_output) == 0) { + error("Will not overwrite input file"); + code = -1; + } + free(realpath_input); + } free(realpath_output); if (code != 0) { @@ -167,6 +197,8 @@ png_write_info(png, png_info); + png_set_bgr(png); + int y; for (y = 0; y < n->height; y++) { png_write_row(png, n->data+4*y*n->width); @@ -191,6 +223,14 @@ } int nordlicht_set_buffer(nordlicht *n, unsigned char *data) { + if (! n->modifiable) { + return -1; + } + + if (data == NULL) { + return -1; + } + if (n->owns_data) { free(n->data); }
View file
_service:download_files:v0.3.4.tar.gz/src/nordlicht.h -> _service:download_files:v0.3.5.tar.gz/src/nordlicht.h
Changed
@@ -9,20 +9,30 @@ NORDLICHT_STYLE_VERTICAL, // compress frames to rows, "move downwards" } nordlicht_style; +typedef enum nordlicht_strategy { + NORDLICHT_STRATEGY_FAST, // generate barcode in a single pass as fast as possible + NORDLICHT_STRATEGY_LIVE, // generate a fast approximation first, good for live display +} nordlicht_strategy; + // Allocate a new nordlicht of specific width and height, for a given video // file. When `live` is true, give a fast approximation before starting the // slow, exact generation. Use `nordlicht_free` to free the nordlicht again. // Returns NULL on errors. -nordlicht* nordlicht_init(char *filename, int width, int height, int live); +nordlicht* nordlicht_init(char *filename, int width, int height); // Free a nordlicht. void nordlicht_free(nordlicht *n); // Set the output style of the nordlicht. Default is NORDLICHT_STYLE_HORIZONTAL. -void nordlicht_set_style(nordlicht *n, nordlicht_style s); +// Returns 0 on success. +int nordlicht_set_style(nordlicht *n, nordlicht_style s); + +// Set the generation strategy of the nordlicht. Default is NORDLICHT_STRATEGY_FAST. +// Returns 0 on success. This function will be removed in the future. +int nordlicht_set_strategy(nordlicht *n, nordlicht_strategy s); // Returns a pointer to the nordlicht's internal buffer. You can use it to draw -// the barcode while it is generated. +// the barcode while it is generated. The pixel format is 32-bit BGRA. const unsigned char* nordlicht_buffer(nordlicht *n); // Replace the internal nordlicht's internal buffer. The data pointer is owned @@ -33,7 +43,7 @@ size_t nordlicht_buffer_size(nordlicht *n); // Generate the nordlicht. Calling this will freeze the nordlicht: -// "set" functions will be without effect. Returns 0 on success. +// "set" functions will fail. Returns 0 on success. int nordlicht_generate(nordlicht *n); // Returns a value between 0 and 1 indicating how much of the nordlicht is done.
View file
_service:download_files:v0.3.4.tar.gz/src/video.c -> _service:download_files:v0.3.5.tar.gz/src/video.c
Changed
@@ -38,7 +38,7 @@ long pts = packet->pts != 0 ? packet->pts : packet->dts; double sec = (double)(pts - v->format_context->streams[v->video_stream]->start_time) * av_q2d(v->format_context->streams[v->video_stream]->time_base); - return (int64_t)(fps(v) * sec + 0.5); + return (int64_t)(fps(v)*sec + 0.5); } int grab_next_frame(video *v) { @@ -52,7 +52,7 @@ while (!valid) { if (av_read_frame(v->format_context, &packet) >= 0) { - if(packet.stream_index == v->video_stream) { + if (packet.stream_index == v->video_stream) { avcodec_decode_video2(v->decoder_context, v->frame, &got_frame, &packet); if (got_frame) { pts = packet_pts(v, &packet); @@ -135,6 +135,10 @@ } video* video_init(char *filename, int width) { + if (filename == NULL) { + return NULL; + } + av_log_set_level(AV_LOG_FATAL); av_register_all(); @@ -196,7 +200,7 @@ long preceding_keyframe(video *v, long frame_nr) { int i; long best_keyframe = -1; - for (i=0; i < v->number_of_keyframes; i++) { + for (i = 0; i < v->number_of_keyframes; i++) { if (v->keyframes[i] <= frame_nr) { best_keyframe = v->keyframes[i]; } @@ -243,7 +247,7 @@ v->scaleframe->linesize); int y; - for (y=0; y<i->height; y++) { + for (y = 0; y < i->height; y++) { memcpy(i->data+y*i->width*3, v->scaleframe->data[0]+y*v->scaleframe->linesize[0], v->scaleframe->linesize[0]); }
View file
_service:download_files:v0.3.5.tar.gz/tests
Added
+(directory)
View file
_service:download_files:v0.3.5.tar.gz/tests/library.c
Added
@@ -0,0 +1,112 @@ +#include <assert.h> +#include <limits.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <stdarg.h> +#include <unistd.h> +#include "nordlicht.h" + +#define fail(call) assert(0 != (call)) +#define pass(call) assert(0 == (call)) +#define null(call) assert(NULL == (call)) + +int file_exists(char *filename) { + return access(filename, F_OK) != -1; +} + +int main(void) { + nordlicht *n; + char *VID = "video.mp4"; + + // test environment + assert(1); + assert(!0); + fail(-1); + pass(0); + assert(file_exists(VID)); + + // invalid input + null(nordlicht_init(NULL, 100, 100)); + null(nordlicht_init("", 100, 100)); + null(nordlicht_init("\0", 100, 100)); + null(nordlicht_init(".", 100, 100)); + null(nordlicht_init("..", 100, 100)); + null(nordlicht_init("nonexistant_file.123", 100, 100)); + + // invalid size + null(nordlicht_init(VID, 0, 100)); + null(nordlicht_init(VID, 100, 0)); + null(nordlicht_init(VID, 0, 0)); + null(nordlicht_init(VID, -100, 100)); + null(nordlicht_init(VID, 100, -100)); + null(nordlicht_init(VID, INT_MIN, INT_MIN)); + + // valid size + assert(nordlicht_init(VID, 1, 1)); + assert(nordlicht_init(VID, INT_MAX, INT_MAX)); + + // invalid output + n = nordlicht_init(VID, 1, 100); + assert(n); + fail(nordlicht_write(n, NULL)); + fail(nordlicht_write(n, "")); + fail(nordlicht_write(n, "\0")); + fail(nordlicht_write(n, ".")); + fail(nordlicht_write(n, "..")); + fail(nordlicht_write(n, VID)); + nordlicht_free(n); + + // style + n = nordlicht_init(VID, 1, 100); + assert(n); + pass(nordlicht_set_style(n, NORDLICHT_STYLE_HORIZONTAL)); + pass(nordlicht_set_style(n, NORDLICHT_STYLE_VERTICAL)); + fail(nordlicht_set_style(n, 2)); + fail(nordlicht_set_style(n, 1000000)); + fail(nordlicht_set_style(n, -1)); + nordlicht_free(n); + + // strategy + n = nordlicht_init(VID, 1, 100); + assert(n); + pass(nordlicht_set_strategy(n, NORDLICHT_STRATEGY_FAST)); + pass(nordlicht_set_strategy(n, NORDLICHT_STRATEGY_LIVE)); + fail(nordlicht_set_strategy(n, 2)); + fail(nordlicht_set_strategy(n, 1000000)); + fail(nordlicht_set_strategy(n, -1)); + nordlicht_free(n); + + // buffer + const unsigned char *buffer = NULL; + n = nordlicht_init(VID, 2, 100); + assert(n); + buffer = nordlicht_buffer(n); + assert(buffer); + assert(2*100*4 == nordlicht_buffer_size(n)); + unsigned char *buffer2 = NULL; + fail(nordlicht_set_buffer(n, buffer2)); + buffer2 = malloc(nordlicht_buffer_size(n)); + pass(nordlicht_set_buffer(n, buffer2)); + pass(nordlicht_set_buffer(n, buffer2)); + pass(nordlicht_set_buffer(n, buffer2)); + buffer = nordlicht_buffer(n); + assert(buffer == buffer2); + nordlicht_free(n); + free(buffer2); + + // complete run + n = nordlicht_init(VID, 1, 100); + assert(n); + assert(0 == nordlicht_progress(n)); + pass(nordlicht_generate(n)); + assert(1 == nordlicht_progress(n)); + fail(nordlicht_set_style(n, NORDLICHT_STYLE_HORIZONTAL)); + buffer2 = malloc(nordlicht_buffer_size(n)); + fail(nordlicht_set_buffer(n, buffer2)); + nordlicht_free(n); + free(buffer2); + + printf("--- nordlicht library test suite passed. ---\n"); + return 0; +}
View file
_service:download_files:v0.3.5.tar.gz/tests/tool.sh
Added
@@ -0,0 +1,104 @@ +#!/bin/bash + +nordlicht() { + ../nordlicht $@ +} + +abort() { + exit 1 +} + +pass() { + echo "Running '$@'" + $@ &> "$LOG" + exit_code=$? + + if test $exit_code != 0; then + cat "$LOG" + echo "command failed: $*" + abort + fi + return 0 +} + +fail() { + echo "Running '$@'" + $@ &> "$LOG" + exit_code=$? + + if test $exit_code = 0; then + cat "$LOG" + echo "command succeded: $*" + abort + elif test $exit_code -gt 129 -a $exit_code -le 192; then + echo "died by signal: $*" + abort + elif test $exit_code = 127; then + echo "command not found: $*" + abort + elif test $exit_code = 126; then + echo "valgrind error: $*" + abort + fi + return 0 +} + +LOG='test.log' +TMP="test_tmp_$$/" + +mkdir "$TMP" && +pushd "$TMP" || exit 1 + +VIDEO='../video.mp4' + +# test environment +pass true +fail false +pass test -f "$VIDEO" + +# argument parsing +pass nordlicht --help +fail nordlicht +fail nordlicht --fubar +fail nordlicht "$VIDEO" somethingelse + +# input file +fail nordlicht nonexistantvideo.foo + +# size +pass nordlicht "$VIDEO" -w 1 -h 1 +pass nordlicht "$VIDEO" -w 1 -h 10000 +fail nordlicht "$VIDEO" -w huuuge +fail nordlicht "$VIDEO" -w 0 +fail nordlicht "$VIDEO" -h 0 +fail nordlicht "$VIDEO" -w '' +fail nordlicht "$VIDEO" -h '' +fail nordlicht "$VIDEO" -w -100 +fail nordlicht "$VIDEO" -h -100 +fail nordlicht "$VIDEO" -w 1.1 +fail nordlicht "$VIDEO" -h 1.1 +fail nordlicht "$VIDEO" -w 1,1 +fail nordlicht "$VIDEO" -h 1,1 + +# output file +pass nordlicht "$VIDEO" -w 1 -o ünîç⌀də.png +pass test -f ünîç⌀də.png +fail nordlicht "$VIDEO" -o ../"$TMP" +fail nordlicht "$VIDEO" -o "$VIDEO" +fail nordlicht "$VIDEO" -o '' + +# style +pass nordlicht "$VIDEO" -w 1 -s vertical +pass nordlicht "$VIDEO" -w 1 -s horizontal +fail nordlicht "$VIDEO" -s nope +fail nordlicht "$VIDEO" -s '' + +# output formats +pass nordlicht "$VIDEO" -w 1 -o barcode.bgra +fail nordlicht "$VIDEO" -w 1 -o barcode.123 +fail nordlicht "$VIDEO" -w 1 -o not-a-png + +popd +rm -r "$TMP" + +echo "--- nordlicht tool test suite passed. ---"
View file
_service:download_files:v0.3.4.tar.gz/utils/bootstrap-debian.sh -> _service:download_files:v0.3.5.tar.gz/utils/bootstrap-debian.sh
Changed
@@ -1,4 +1,4 @@ #!/usr/bin/env bash apt-get update && -apt-get install -y cmake libavcodec-dev libswscale-dev libavformat-dev libpng-dev libpopt-dev git-buildpackage debhelper help2man +apt-get install -y cmake libavcodec-dev libswscale-dev libavformat-dev libpng-dev libpopt-dev git-buildpackage debhelper help2man python-software-properties
View file
_service:download_files:v0.3.4.tar.gz/utils/mpv-nordlicht -> _service:download_files:v0.3.5.tar.gz/utils/mpv-nordlicht
Changed
@@ -17,5 +17,5 @@ trap "kill 0" SIGINT SIGTERM EXIT -nordlicht "$VIDEO" -w $SCREEN_WIDTH -h $NORDLICHT_HEIGHT --live -o /tmp/nordlicht.bgra & +nordlicht "$VIDEO" -w $SCREEN_WIDTH -h $NORDLICHT_HEIGHT -o /tmp/nordlicht.bgra & { echo -n "fb"; while true; do echo -n "n"; sleep 0.01; done } | mpv --input-conf=/tmp/mpv_input.conf --osd-border-size=0 --osd-bar-align-y=$OSD_Y --osd-bar-w=100 --osd-bar-h=$OSD_H --osd-duration=3600000 "$@"
View file
_service:download_files:v0.3.4.tar.gz/utils/mpv-nordlicht.lua -> _service:download_files:v0.3.5.tar.gz/utils/mpv-nordlicht.lua
Changed
@@ -1,5 +1,5 @@ --- nordlicht integration for mpv. You need a version after commit d706f81 --- (>=v0.3.6, that is) to correctly support lua scripting. +-- nordlicht integration for mpv. You need mpv >= 0.3.6 to correctly support +-- lua scripting. function init() is_on = false @@ -19,7 +19,8 @@ os.execute("convert -depth 8 -size "..mw.."x"..mh.." bgra:/tmp/arrow_up.bgra -flip bgra:/tmp/arrow_down.bgra") new_file() - on() + -- wait for the convert commands to finish + mp.add_timeout(0.5, on) end function shutdown() @@ -40,7 +41,7 @@ kill() local path = mp.get_property("path") - local cmd = "nordlicht \""..path.."\" --live -o /tmp/nordlicht.bgra -w "..width.." -h "..height.." &" + local cmd = "nice nordlicht \""..path.."\" -o /tmp/nordlicht.bgra -w "..width.." -h "..height.." &" os.execute(cmd) if was_on then
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.