From 98bfa11973db659084717db65f051680788e4295 Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Mon, 16 May 2022 00:26:26 +0800 Subject: [PATCH] Feature: set params of start_time/duration --- app/src/main/cpp/cut_video.cpp | 7 ++++++- app/src/main/cpp/cut_video.h | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/cut_video.cpp b/app/src/main/cpp/cut_video.cpp index 4287c3b..3aeea5e 100644 --- a/app/src/main/cpp/cut_video.cpp +++ b/app/src/main/cpp/cut_video.cpp @@ -53,6 +53,11 @@ int CutVideo::open_output_file(AVFormatContext *ifmt_ctx, const char *filename) return 0; } +void CutVideo:: setParam(int64_t start_time, int64_t duration) { + m_startTime = start_time; + m_duration = duration; +} + AVPacket* CutVideo::copy_packet(AVFormatContext *ifmt_ctx, AVPacket *packet) { AVStream* in_stream; AVStream* out_stream; @@ -95,7 +100,7 @@ int CutVideo::write_internal(AVFormatContext *ifmt_ctx, AVPacket *packet) void CutVideo::write_output_file(AVFormatContext *ifmt_ctx, AVPacket *packet) { int64_t timestamp = packet->pts * av_q2d(ifmt_ctx->streams[packet->stream_index]->time_base); - if (timestamp >= start_time && timestamp < start_time + duration) { + if (timestamp >= m_startTime && timestamp < m_startTime + m_duration) { // if (start_pts == 0 && start_dts == 0) { // start_pts = packet->pts; // start_dts = packet->dts; diff --git a/app/src/main/cpp/cut_video.h b/app/src/main/cpp/cut_video.h index 16deda0..8d48f11 100644 --- a/app/src/main/cpp/cut_video.h +++ b/app/src/main/cpp/cut_video.h @@ -16,8 +16,8 @@ extern "C" { class CutVideo { private: - int64_t start_time = 15; - int64_t duration = 10; + int64_t m_startTime = 15; + int64_t m_duration = 10; int64_t start_dts = 0; int64_t start_pts = 0; @@ -31,6 +31,8 @@ public: int open_output_file(AVFormatContext *ifmt_ctx, const char *filename); + void setParam(int64_t start_time, int64_t duration); + void write_output_file(AVFormatContext *ifmt_ctx, AVPacket *packet); void close_output_file();