-
Notifications
You must be signed in to change notification settings - Fork 1
Add example CLI project #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Erik-White
wants to merge
6
commits into
main
Choose a base branch
from
add-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.0.0 | ||
| 1.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| cmake_minimum_required (VERSION 3.9) | ||
|
|
||
| set(TARGET cli) | ||
|
|
||
| include_directories("${CMAKE_SOURCE_DIR}/src") | ||
|
|
||
| add_executable(${TARGET} cli.c) | ||
|
|
||
| target_link_libraries(${TARGET} PRIVATE ${FFMPEG_LIBS}) | ||
| target_link_libraries(${TARGET} PRIVATE Griffeye.VideoProcessor.Native) | ||
| target_link_libraries(${TARGET} PRIVATE m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <stdbool.h> | ||
| #include <string.h> | ||
| #include <libavcodec/avcodec.h> | ||
| #include <libavfilter/avfilter.h> | ||
| #include <libavformat/avformat.h> | ||
|
|
||
| #include "libvx.h" | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| int result = 1; | ||
| char* video_path = argc > 1 ? argv[1] : ""; | ||
| vx_video* video = calloc(1, sizeof(vx_video)); | ||
| vx_video_info* video_info = calloc(1, sizeof(vx_video_info)); | ||
| vx_frame_info* frame_info = calloc(1, sizeof(vx_frame_info)); | ||
| vx_frame* frame = NULL; | ||
|
|
||
| vx_audio_params audio_params = { | ||
| .channels = 2, | ||
| .sample_format = VX_SAMPLE_FMT_FLT, | ||
| .sample_rate = 44100 | ||
| }; | ||
| const vx_video_options options = { | ||
| .audio_params = audio_params, | ||
| .autorotate = true, | ||
| .crop_area = {0}, | ||
| .hw_criteria = VX_HW_ACCEL_ALL, | ||
| .scene_threshold = 0.5 | ||
| }; | ||
|
|
||
| if (vx_open(video_path, options, &video, video_info) != VX_ERR_SUCCESS) { | ||
| printf("Failed to open video: %s\n", video_path); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| // Initialize an empty frame that will be reused throughout the video | ||
| frame = vx_frame_create(video, video_info->width, video_info->height, VX_PIX_FMT_RGB32); | ||
| if (!frame) { | ||
| printf("Failed to create frame\n"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| // Iterate over all frames in the video. The frame is decoded when stepping | ||
| while (vx_frame_step(video, frame_info) == VX_ERR_SUCCESS) { | ||
| bool is_video_frame = frame_info->flags & VX_FF_HAS_IMAGE; | ||
|
|
||
| printf("Frame: %ld, %dx%d\n", video->frame_count, frame_info->width, frame_info->height); | ||
|
|
||
| // Perform processing and tranfer from GPU to CPU if necessary | ||
| if (vx_frame_transfer_data(video, frame) != VX_ERR_SUCCESS) { | ||
| printf("Failed to transfer frame data\n"); | ||
| goto cleanup; | ||
| } | ||
| else { | ||
| printf("Frame type: %s\n", is_video_frame ? "video" : "audio"); | ||
| // The frame image could be accessed via frame->buffer | ||
| // Alternatively for audio frames, the audio samples could be accessed via frame->audio_data | ||
| } | ||
| } | ||
|
|
||
| result = 0; | ||
|
|
||
| cleanup: | ||
| vx_close(video); | ||
| if (video_info) { | ||
| free(video_info); | ||
| } | ||
| if (frame) { | ||
| vx_frame_destroy(frame); | ||
| } | ||
| if (frame_info) { | ||
| free(frame_info); | ||
| } | ||
|
|
||
| return result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,69 +31,32 @@ | |
| static bool initialized = false; | ||
| static vx_log_callback log_cb = NULL; | ||
|
|
||
| struct vx_audio_info | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to move these to the header file so they could be used in the new CLI |
||
| { | ||
| double peak_level; | ||
| double rms_level; | ||
| double rms_peak; | ||
| }; | ||
|
|
||
| struct vx_scene_info | ||
| { | ||
| double difference; | ||
| double scene_score; | ||
| bool new_scene; | ||
| }; | ||
|
|
||
| struct vx_frame | ||
| { | ||
| int width; | ||
| int height; | ||
| vx_pix_fmt pix_fmt; | ||
| int sample_count; | ||
| int max_samples; | ||
|
|
||
| vx_audio_info audio_info; | ||
| vx_scene_info scene_info; | ||
|
|
||
| uint8_t** audio_buffer; | ||
| void* buffer; | ||
| }; | ||
|
|
||
| struct vx_frame_info | ||
| { | ||
| int width; | ||
| int height; | ||
| double timestamp; | ||
| vx_frame_flag flags; | ||
| }; | ||
|
|
||
| static vx_log_level av_to_vx_log_level(const int level) | ||
| { | ||
| // See: lavu_log_constants | ||
| switch (level) { | ||
| case AV_LOG_QUIET: | ||
| return VX_LOG_NONE; | ||
| case AV_LOG_QUIET: | ||
| return VX_LOG_NONE; | ||
|
|
||
| case AV_LOG_PANIC: | ||
| case AV_LOG_FATAL: | ||
| return VX_LOG_FATAL; | ||
| case AV_LOG_PANIC: | ||
| case AV_LOG_FATAL: | ||
| return VX_LOG_FATAL; | ||
|
|
||
| case AV_LOG_ERROR: | ||
| return VX_LOG_ERROR; | ||
| case AV_LOG_ERROR: | ||
| return VX_LOG_ERROR; | ||
|
|
||
| case AV_LOG_WARNING: | ||
| return VX_LOG_WARNING; | ||
| case AV_LOG_WARNING: | ||
| return VX_LOG_WARNING; | ||
|
|
||
| case AV_LOG_INFO: | ||
| case AV_LOG_VERBOSE: | ||
| return VX_LOG_INFO; | ||
| case AV_LOG_INFO: | ||
| case AV_LOG_VERBOSE: | ||
| return VX_LOG_INFO; | ||
|
|
||
| case AV_LOG_DEBUG: | ||
| return VX_LOG_DEBUG; | ||
| case AV_LOG_DEBUG: | ||
| return VX_LOG_DEBUG; | ||
|
|
||
| default: | ||
| return VX_LOG_NONE; | ||
| default: | ||
| return VX_LOG_NONE; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,13 @@ extern "C" { | |
| #endif | ||
|
|
||
| #ifdef _MSC_VER | ||
| // Microsoft | ||
| // Microsoft | ||
| #define VX_DECLSPEC __declspec(dllexport) | ||
| #define VX_CDECL __cdecl | ||
| #else | ||
| // GCC | ||
| // GCC | ||
| #define VX_DECLSPEC __attribute__((visibility("default"))) | ||
| #define VX_CDECL __attribute__((__cdecl__)) | ||
| #define VX_CDECL | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure this change doesn't cause any issues on Linux |
||
| #endif | ||
|
|
||
| #define FRAME_QUEUE_SIZE 32 | ||
|
|
@@ -120,6 +120,43 @@ struct av_audio_params | |
| AVRational time_base; | ||
| }; | ||
|
|
||
| struct vx_audio_info | ||
| { | ||
| double peak_level; | ||
| double rms_level; | ||
| double rms_peak; | ||
| }; | ||
|
|
||
| struct vx_scene_info | ||
| { | ||
| double difference; | ||
| double scene_score; | ||
| bool new_scene; | ||
| }; | ||
|
|
||
| struct vx_frame_info | ||
| { | ||
| int width; | ||
| int height; | ||
| double timestamp; | ||
| vx_frame_flag flags; | ||
| }; | ||
|
|
||
| struct vx_frame | ||
| { | ||
| int width; | ||
| int height; | ||
| vx_pix_fmt pix_fmt; | ||
| int sample_count; | ||
| int max_samples; | ||
|
|
||
| vx_audio_info audio_info; | ||
| vx_scene_info scene_info; | ||
|
|
||
| uint8_t** audio_buffer; | ||
| void* buffer; | ||
| }; | ||
|
|
||
| struct vx_video_options | ||
| { | ||
| vx_audio_params audio_params; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building from the command line was not working (
cmake -S . -B build_linux/) since CMAKE_BUILD_TYPE was not set at that stage. That mean that the ffmpeg packages couldn't be found because the path was incomplete.