File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -86,24 +86,25 @@ void OutputFile::addVideoStream( const VideoDesc& videoDesc )
86
86
}
87
87
}
88
88
89
- bool OutputFile::addAudioStream ( )
89
+ void OutputFile::addAudioStream ( const AudioDesc& audioDesc )
90
90
{
91
- if ( formatContext == NULL )
92
- return false ;
93
-
94
- av_register_all (); // Warning: should be called only once
95
- AVCodec* codec = NULL ;
96
- AVStream* stream = NULL ;
97
-
98
- if ( ( codec = avcodec_find_encoder_by_name ( " wav" ) ) == NULL )
99
- return false ;
91
+ assert ( formatContext != NULL );
100
92
101
- if ( ( stream = avformat_new_stream ( formatContext, codec ) ) == NULL )
102
- return false ;
93
+ if ( ( stream = avformat_new_stream ( formatContext, audioDesc.getCodec () ) ) == NULL )
94
+ {
95
+ throw std::runtime_error ( " unable to add new audio stream" );
96
+ }
103
97
104
- // stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
98
+ stream->codec ->sample_rate = audioDesc.getCodecContext ()->sample_rate ;
99
+ stream->codec ->channels = audioDesc.getCodecContext ()->channels ;
100
+ stream->codec ->bit_rate = audioDesc.getCodecContext ()->bit_rate ;
101
+ stream->codec ->sample_fmt = audioDesc.getCodecContext ()->sample_fmt ;
105
102
106
- return true ;
103
+ // to move in endSetup
104
+ if ( avformat_write_header ( formatContext, NULL ) != 0 )
105
+ {
106
+ throw std::runtime_error ( " could not write header" );
107
+ }
107
108
}
108
109
109
110
bool OutputFile::wrap ( const DataStream& data, const size_t streamId )
Original file line number Diff line number Diff line change 4
4
#include " DatasStructures/Image.hpp"
5
5
#include " DatasStructures/DataStreamDesc.hpp"
6
6
#include " DatasStructures/VideoDesc.hpp"
7
+ #include " DatasStructures/AudioDesc.hpp"
7
8
8
9
#include < string>
9
10
#include < vector>
@@ -25,8 +26,7 @@ class AvExport OutputFile
25
26
bool setup ();
26
27
27
28
void addVideoStream ( const VideoDesc& videoDesc );
28
-
29
- bool addAudioStream ( );
29
+ void addAudioStream ( const AudioDesc& audioDesc );
30
30
31
31
bool wrap ( const DataStream& data, const size_t streamId );
32
32
You can’t perform that action at this time.
0 commit comments