Skip to content

Commit 2d68f4b

Browse files
author
Clement Champetier
committed
Merge branch 'develop' of https://github.com/mikrosimage/avTranscoder into refactore_context
Conflicts: src/AvTranscoder/file/InputFile.cpp
2 parents 13a6872 + 0ac8ba4 commit 2d68f4b

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void InputFile::seekAtFrame( const size_t frame )
158158

159159
void InputFile::activateStream( const size_t streamIndex, bool activate )
160160
{
161-
_inputStreams.at( streamIndex )->activate( activate );
161+
getStream( streamIndex ).activate( activate );
162162
}
163163

164164
AvInputStream& InputFile::getStream( size_t index )

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "AudioProperties.hpp"
22

3-
#include <stdexcept>
4-
53
extern "C" {
64
#include <libavcodec/avcodec.h>
75
#include <libavformat/avformat.h>
@@ -10,6 +8,8 @@ extern "C" {
108
#include <libavutil/channel_layout.h>
119
}
1210

11+
#include <stdexcept>
12+
1313
namespace avtranscoder
1414
{
1515

@@ -151,7 +151,9 @@ size_t AudioProperties::getBitRate() const
151151
{
152152
if( ! _codecContext )
153153
throw std::runtime_error( "unknown codec context" );
154-
return _codecContext->bit_rate;
154+
int bitsPerSample = av_get_bits_per_sample( _codecContext->codec_id );
155+
size_t bitRate = bitsPerSample ? _codecContext->sample_rate * _codecContext->channels * bitsPerSample : _codecContext->bit_rate;
156+
return bitRate;
155157
}
156158

157159
size_t AudioProperties::getNbSamples() const

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ VideoProperties::VideoProperties( const FormatContext& formatContext, const size
4848
if( _codecContext )
4949
_pixelProperties = PixelProperties( _codecContext->pix_fmt );
5050

51-
// Skip decoding for selected frames
52-
_codecContext->skip_frame = AVDISCARD_NONE;
53-
5451
if( level == eAnalyseLevelFirstGop )
5552
analyseGopStructure( progress );
5653
}
@@ -322,14 +319,19 @@ int64_t VideoProperties::getStartTimecode() const
322319

323320
std::string VideoProperties::getStartTimecodeString() const
324321
{
325-
int64_t stratTimeCode = getStartTimecode();
322+
int64_t startTimeCode = getStartTimecode();
326323
std::ostringstream os;
327-
os << std::setfill( '0' );
328-
os << std::setw(2) << ( stratTimeCode >> 19 & 0x1f ) << ":"; // 5-bit hours
329-
os << std::setw(2) << ( stratTimeCode >> 13 & 0x3f ) << ":"; // 6-bit minutes
330-
os << std::setw(2) << ( stratTimeCode >> 6 & 0x3f ) ; // 6-bit seconds
331-
os << ( stratTimeCode & 1 << 24 ? ';' : ':' ); // 1-bit drop flag
332-
os << std::setw(2) << ( stratTimeCode & 0x3f ); // 6-bit frames
324+
if( startTimeCode == -1 )
325+
os << "unset";
326+
else
327+
{
328+
os << std::setfill( '0' );
329+
os << std::setw(2) << ( startTimeCode >> 19 & 0x1f ) << ":"; // 5-bit hours
330+
os << std::setw(2) << ( startTimeCode >> 13 & 0x3f ) << ":"; // 6-bit minutes
331+
os << std::setw(2) << ( startTimeCode >> 6 & 0x3f ) ; // 6-bit seconds
332+
os << ( startTimeCode & 1 << 24 ? ';' : ':' ); // 1-bit drop flag
333+
os << std::setw(2) << ( startTimeCode & 0x3f ); // 6-bit frames
334+
}
333335
return os.str();
334336
}
335337

@@ -493,15 +495,24 @@ bool VideoProperties::hasBFrames() const
493495
return (bool) _codecContext->has_b_frames;
494496
}
495497

498+
// CODEC_FLAG_CLOSED_GOP is superior of INT_MAX, and _codecContext->flags is an int
499+
// => Need a patch from FFmpeg
500+
//bool VideoProperties::isClosedGop() const
501+
//{
502+
// if( ! _codecContext )
503+
// throw std::runtime_error( "unknown codec context" );
504+
// return ( _codecContext->flags & CODEC_FLAG_CLOSED_GOP ) == CODEC_FLAG_CLOSED_GOP;
505+
//}
506+
496507
void VideoProperties::analyseGopStructure( IProgress& progress )
497508
{
498509
if( _formatContext && _codecContext && _codec )
499510
{
500-
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
501-
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
502-
503511
if( _codecContext->width && _codecContext->height )
504512
{
513+
// Discard no frame type when decode
514+
_codecContext->skip_frame = AVDISCARD_NONE;
515+
505516
AVPacket pkt;
506517

507518
#if LIBAVCODEC_VERSION_MAJOR > 54
@@ -567,7 +578,7 @@ PropertiesMap VideoProperties::getPropertiesAsMap() const
567578
detail::add( dataMap, "profile", getProfile() );
568579
detail::add( dataMap, "profileName", getProfileName() );
569580
detail::add( dataMap, "level", getLevel() );
570-
detail::add( dataMap, "startTimecode", getStartTimecode() );
581+
detail::add( dataMap, "startTimecode", getStartTimecodeString() );
571582
detail::add( dataMap, "width", getWidth() );
572583
detail::add( dataMap, "height", getHeight() );
573584
detail::add( dataMap, "pixelAspectRatio", getSar().num / getSar().den );
@@ -595,9 +606,10 @@ PropertiesMap VideoProperties::getPropertiesAsMap() const
595606
for( size_t frameIndex = 0; frameIndex < _gopStructure.size(); ++frameIndex )
596607
{
597608
gop += _gopStructure.at( frameIndex ).first;
598-
gop += ( _gopStructure.at( frameIndex ).second ? "*" : " " );
609+
gop += " ";
599610
}
600611
detail::add( dataMap, "gop", gop );
612+
//detail::add( dataMap, "isClosedGop", isClosedGop() );
601613

602614
detail::add( dataMap, "hasBFrames", hasBFrames() );
603615
detail::add( dataMap, "referencesFrames", getReferencesFrames() );

src/AvTranscoder/mediaProperty/VideoProperties.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class AvExport VideoProperties
6262
double getDuration() const; ///< in seconds
6363

6464
bool hasBFrames() const;
65+
//bool isClosedGop() const;
6566

6667
//@{
6768
// Warning: Can acces these data when analyse first gop
@@ -80,7 +81,7 @@ class AvExport VideoProperties
8081
const PixelProperties& getPixelProperties() const { return _pixelProperties; }
8182
#endif
8283

83-
PropertiesMap getPropertiesAsMap() const; ///< Return all video properties as a map (name of property: value)
84+
PropertiesMap getPropertiesAsMap() const; ///< Return all video and pixel properties as a map (name of property: value)
8485

8586
private:
8687
/**

test/pyTest/testSetFrame.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def testSetVideoFrame():
2828
ouputFile.beginWrap()
2929
transcoder.preProcessCodecLatency()
3030

31-
# process 255 frames
32-
for i in range(0,255):
31+
# process 10 frames
32+
for i in range(0, 10):
3333
transcoder.processFrame()
3434
# set video frame
3535
frame = av.VideoFrame( imageDesc )
@@ -77,8 +77,8 @@ def testSetAudioFrame():
7777
ouputFile.beginWrap()
7878
transcoder.preProcessCodecLatency()
7979

80-
# process 255 frames
81-
for i in range(0,255):
80+
# process 10 frames
81+
for i in range(0, 10):
8282
transcoder.processFrame()
8383
# set video frame
8484
frame = av.AudioFrame( audioDesc )

0 commit comments

Comments
 (0)