@ -218,14 +218,11 @@ void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duratio
AVFormatContext * outputFormatContext = nullptr ;
AVPacket packet ;
av_register_all ( ) ;
avformat_network_init ( ) ;
# ifndef NDEBUG
// Set the custom log callback
av_log_set_callback ( ffmpeg_log_callback ) ;
av_log_set_level ( AV_LOG_ TRACE ) ;
av_log_set_level ( AV_LOG_ WARNING ) ;
# endif
@ -270,6 +267,11 @@ void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duratio
AVStream * inStream = inputFormatContext - > streams [ i ] ;
const AVCodecParameters * in_codecpar = inStream - > codecpar ;
// Skip audio streams
if ( inStream - > codecpar - > codec_type = = AVMEDIA_TYPE_AUDIO ) {
continue ;
}
if ( in_codecpar - > codec_type = = AVMEDIA_TYPE_VIDEO ) {
// Copy video stream as-is
const AVCodec * codec = avcodec_find_decoder ( in_codecpar - > codec_id ) ;
@ -359,7 +361,7 @@ void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duratio
auto startTime = av_gettime ( ) ;
// int64_t durationNs = (int64_t)duration * 1000000;
int64_t durationNs = ( int64_t ) duration * 1000 ;
int64_t durationNs = ( int64_t ) ( duration + 32 ) * 1000 ;
// Read packets from input and write them to output
while ( 1 ) {
@ -385,8 +387,29 @@ void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duratio
# endif
if ( av_read_frame ( inputFormatContext , & packet ) < 0 ) break ;
av_write_frame ( outputFormatContext , & packet ) ;
// Skip audio packets
if ( inputFormatContext - > streams [ packet . stream_index ] - > codecpar - > codec_type = = AVMEDIA_TYPE_AUDIO )
{
av_packet_unref ( & packet ) ;
continue ;
}
// Adjust packet timebase
AVStream * in_stream = inputFormatContext - > streams [ packet . stream_index ] ;
AVStream * out_stream = outputFormatContext - > streams [ packet . stream_index ] ;
av_packet_rescale_ts ( & packet , in_stream - > time_base , out_stream - > time_base ) ;
packet . pos = - 1 ;
res = av_write_frame ( outputFormatContext , & packet ) ;
av_packet_unref ( & packet ) ;
if ( res < 0 )
{
break ;
}
}
// stop_thread.join();