@@ -17,7 +17,6 @@ namespace avtranscoder
17
17
OutputFile::OutputFile ( const std::string& filename )
18
18
: _formatContext ( NULL )
19
19
, _outputFormat ( NULL )
20
- , _stream ( NULL )
21
20
, _filename ( filename )
22
21
, _previousProcessedStreamDuration( 0.0 )
23
22
, _verbose ( false )
@@ -58,32 +57,32 @@ IOutputStream& OutputFile::addVideoStream( const VideoCodec& videoDesc )
58
57
{
59
58
assert ( _formatContext != NULL );
60
59
61
- if ( ( _stream = avformat_new_stream ( _formatContext, videoDesc.getAVCodec () ) ) == NULL )
60
+ AVStream* stream = avformat_new_stream ( _formatContext, videoDesc.getAVCodec () );
61
+ if ( stream == NULL )
62
62
{
63
63
throw std::runtime_error ( " unable to add new video stream" );
64
64
}
65
65
66
- _stream ->codec ->width = videoDesc.getAVCodecContext ()->width ;
67
- _stream ->codec ->height = videoDesc.getAVCodecContext ()->height ;
68
- _stream ->codec ->bit_rate = videoDesc.getAVCodecContext ()->bit_rate ;
69
- _stream ->codec ->pix_fmt = videoDesc.getAVCodecContext ()->pix_fmt ;
70
- _stream ->codec ->profile = videoDesc.getAVCodecContext ()->profile ;
71
- _stream ->codec ->level = videoDesc.getAVCodecContext ()->level ;
66
+ stream ->codec ->width = videoDesc.getAVCodecContext ()->width ;
67
+ stream ->codec ->height = videoDesc.getAVCodecContext ()->height ;
68
+ stream ->codec ->bit_rate = videoDesc.getAVCodecContext ()->bit_rate ;
69
+ stream ->codec ->pix_fmt = videoDesc.getAVCodecContext ()->pix_fmt ;
70
+ stream ->codec ->profile = videoDesc.getAVCodecContext ()->profile ;
71
+ stream ->codec ->level = videoDesc.getAVCodecContext ()->level ;
72
72
73
73
// need to set the time_base on the AVCodecContext and the AVStream
74
74
// compensating the frame rate with the ticks_per_frame and keeping
75
75
// a coherent reading speed.
76
76
av_reduce (
77
- &_stream ->codec ->time_base .num ,
78
- &_stream ->codec ->time_base .den ,
77
+ &stream ->codec ->time_base .num ,
78
+ &stream ->codec ->time_base .den ,
79
79
videoDesc.getAVCodecContext ()->time_base .num * videoDesc.getAVCodecContext ()->ticks_per_frame ,
80
80
videoDesc.getAVCodecContext ()->time_base .den ,
81
81
INT_MAX );
82
82
83
- _stream->time_base = _stream->codec ->time_base ;
84
-
85
- AvOutputStream* avOutputStream = new AvOutputStream ( *this , _formatContext->nb_streams - 1 );
83
+ stream->time_base = stream->codec ->time_base ;
86
84
85
+ AvOutputStream* avOutputStream = new AvOutputStream ( *this , _formatContext->nb_streams - 1 );
87
86
_outputStreams.push_back ( avOutputStream );
88
87
89
88
return *_outputStreams.back ();
@@ -93,14 +92,15 @@ IOutputStream& OutputFile::addAudioStream( const AudioCodec& audioDesc )
93
92
{
94
93
assert ( _formatContext != NULL );
95
94
96
- if ( ( _stream = avformat_new_stream ( _formatContext, audioDesc.getAVCodec () ) ) == NULL )
95
+ AVStream* stream = avformat_new_stream ( _formatContext, audioDesc.getAVCodec () );
96
+ if ( stream == NULL )
97
97
{
98
98
throw std::runtime_error ( " unable to add new audio stream" );
99
99
}
100
100
101
- _stream ->codec ->sample_rate = audioDesc.getAVCodecContext ()->sample_rate ;
102
- _stream ->codec ->channels = audioDesc.getAVCodecContext ()->channels ;
103
- _stream ->codec ->sample_fmt = audioDesc.getAVCodecContext ()->sample_fmt ;
101
+ stream ->codec ->sample_rate = audioDesc.getAVCodecContext ()->sample_rate ;
102
+ stream ->codec ->channels = audioDesc.getAVCodecContext ()->channels ;
103
+ stream ->codec ->sample_fmt = audioDesc.getAVCodecContext ()->sample_fmt ;
104
104
105
105
AvOutputStream* avOutputStream = new AvOutputStream ( *this , _formatContext->nb_streams - 1 );
106
106
_outputStreams.push_back ( avOutputStream );
@@ -112,7 +112,8 @@ IOutputStream& OutputFile::addDataStream( const DataCodec& dataDesc )
112
112
{
113
113
assert ( _formatContext != NULL );
114
114
115
- if ( ( _stream = avformat_new_stream ( _formatContext, dataDesc.getAVCodec () ) ) == NULL )
115
+ AVStream* stream = avformat_new_stream ( _formatContext, dataDesc.getAVCodec () );
116
+ if ( stream == NULL )
116
117
{
117
118
throw std::runtime_error ( " unable to add new data stream" );
118
119
}
0 commit comments