Skip to content

Commit

Permalink
Merge pull request #1780 from daniel-riehm/dev/ffmpeg-copy-start-ts
Browse files Browse the repository at this point in the history
Copy input video start timestamp when transcoding
  • Loading branch information
daniel-riehm authored Jun 21, 2023
2 parents 01211a4 + fe9e4d7 commit 10dd0ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions arrows/ffmpeg/ffmpeg_video_input.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ ::implementation_settings() const
ffmpeg_video_settings_uptr result{ new ffmpeg_video_settings{} };
result->frame_rate = frame_rate();
result->klv_stream_count = klv_streams.size();
result->start_timestamp = format_context->start_time;

if( codec_context )
{
Expand Down
4 changes: 4 additions & 0 deletions arrows/ffmpeg/ffmpeg_video_output.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ ::implementation_settings() const
avcodec_parameters_from_context( result->parameters.get(),
d->video->codec_context.get() );
result->klv_stream_count = 0; // TODO
result->start_timestamp = d->video->format_context->start_time;
return kwiver::vital::video_settings_uptr{ result };
}

Expand Down Expand Up @@ -428,6 +429,9 @@ ::open_video_state(
}
output_format = format_context->oformat;

// Set timestamp value to start at
format_context->output_ts_offset = settings.start_timestamp;

// Prioritization scheme for codecs:
// (1) Match ffmpeg settings passed to constructor if present
// (2) Match configuration setting if present
Expand Down
14 changes: 10 additions & 4 deletions arrows/ffmpeg/ffmpeg_video_settings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ ffmpeg_video_settings
::ffmpeg_video_settings()
: frame_rate{ 0, 1 },
parameters{ avcodec_parameters_alloc() },
klv_stream_count{ 0 }
klv_stream_count{ 0 },
start_timestamp{ AV_NOPTS_VALUE }
{
if( !parameters )
{
Expand All @@ -34,7 +35,8 @@ ffmpeg_video_settings
::ffmpeg_video_settings( ffmpeg_video_settings const& other )
: frame_rate{ other.frame_rate },
parameters{ avcodec_parameters_alloc() },
klv_stream_count{ other.klv_stream_count }
klv_stream_count{ other.klv_stream_count },
start_timestamp{ other.start_timestamp }
{
throw_error_code(
avcodec_parameters_copy( parameters.get(), other.parameters.get() ),
Expand All @@ -46,7 +48,8 @@ ffmpeg_video_settings
::ffmpeg_video_settings( ffmpeg_video_settings&& other )
: frame_rate{ std::move( other.frame_rate ) },
parameters{ std::move( other.parameters ) },
klv_stream_count{ std::move( other.klv_stream_count ) }
klv_stream_count{ std::move( other.klv_stream_count ) },
start_timestamp{ other.start_timestamp }
{}

// ----------------------------------------------------------------------------
Expand All @@ -57,7 +60,8 @@ ::ffmpeg_video_settings(
size_t klv_stream_count )
: frame_rate( frame_rate ),
parameters{ avcodec_parameters_alloc() },
klv_stream_count{ klv_stream_count }
klv_stream_count{ klv_stream_count },
start_timestamp{ AV_NOPTS_VALUE }
{
if( !parameters )
{
Expand All @@ -84,6 +88,7 @@ ::operator=( ffmpeg_video_settings const& other )
avcodec_parameters_copy( parameters.get(), other.parameters.get() ),
"Could not copy codec parameters" );
klv_stream_count = other.klv_stream_count;
start_timestamp = other.start_timestamp;
return *this;
}

Expand All @@ -95,6 +100,7 @@ ::operator=( ffmpeg_video_settings&& other )
frame_rate = std::move( other.frame_rate );
parameters = std::move( other.parameters );
klv_stream_count = std::move( other.klv_stream_count );
start_timestamp = std::move( other.start_timestamp );
return *this;
}

Expand Down
1 change: 1 addition & 0 deletions arrows/ffmpeg/ffmpeg_video_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct KWIVER_ALGO_FFMPEG_EXPORT ffmpeg_video_settings
AVRational frame_rate;
codec_parameters_uptr parameters;
size_t klv_stream_count;
int64_t start_timestamp; // In AV_TIME_BASE units
};
using ffmpeg_video_settings_uptr = std::unique_ptr< ffmpeg_video_settings >;

Expand Down
2 changes: 2 additions & 0 deletions doc/release-notes/master.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Arrows: FFmpeg

* Added check for incoming raw video packets' timestamps and stream indices.

* Added functionality to copy the input video's start timestamp when transcoding.

Arrows: KLV

* Ensured that NaN comparisons happen consistently across all data structures.
Expand Down

0 comments on commit 10dd0ab

Please sign in to comment.