Skip to content

Instantly share code, notes, and snippets.

@vade
Created June 17, 2016 14:56
Show Gist options
  • Save vade/12cff17a193fd1d7d407e26eb412b14d to your computer and use it in GitHub Desktop.
Save vade/12cff17a193fd1d7d407e26eb412b14d to your computer and use it in GitHub Desktop.
unique_ptr<Frame> Decoder::convertVideoFrame( const Frame &frame ) const
{
CI_ASSERT( frame.getMediaType() == AVMEDIA_TYPE_VIDEO );
unique_ptr<Frame> result( new FrameVideo( frame.getTimeBase() ) );
result->getAvFrame()->format = AV_PIX_FMT_RGB24;
result->getAvFrame()->width = frame.getAvFrame()->width;
result->getAvFrame()->height = frame.getAvFrame()->height;
// allocate backing
av_frame_get_buffer( result->getAvFrame(), 64 );
// copy metadata
av_frame_copy_props( result->getAvFrame(), frame.getAvFrame() );
// swizzle the packet PTS / DTS to start at 0 if we have them set.
if( ( mStartTime != INT64_MIN ) && ( mEndTime != INT64_MAX ) ) {
av_frame_set_best_effort_timestamp( result->getAvFrame(), result->getAvFrame()->pts - mStartTime);
result->getAvFrame()->pts = result->getAvFrame()->pts - mStartTime;
result->getAvFrame()->pkt_pts = result->getAvFrame()->pkt_pts - mStartTime;
result->getAvFrame()->pkt_dts = result->getAvFrame()->pkt_dts - mStartTime;
}
// scale if we arent 1920x1080, and convert YUV->RGB
sws_scale( mPixelFormatConversionContext,
frame.getAvFrame()->data,
frame.getAvFrame()->linesize,
0,
frame.getAvFrame()->height,
result->getAvFrame()->data,
result->getAvFrame()->linesize );
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment