equal
deleted
inserted
replaced
88 #else |
88 #else |
89 g_pAStream = av_new_stream(g_pContainer, 1); |
89 g_pAStream = av_new_stream(g_pContainer, 1); |
90 #endif |
90 #endif |
91 if(!g_pAStream) |
91 if(!g_pAStream) |
92 { |
92 { |
93 Log("Could not allocate audio stream"); |
93 Log("Could not allocate audio stream\n"); |
94 return; |
94 return; |
95 } |
95 } |
96 g_pAStream->id = 1; |
96 g_pAStream->id = 1; |
97 |
97 |
98 g_pAudio = g_pAStream->codec; |
98 g_pAudio = g_pAStream->codec; |
119 g_pAudio->flags |= CODEC_FLAG_GLOBAL_HEADER; |
119 g_pAudio->flags |= CODEC_FLAG_GLOBAL_HEADER; |
120 |
120 |
121 // open it |
121 // open it |
122 if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) |
122 if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) |
123 { |
123 { |
124 Log("Could not open audio codec %s", g_pACodec->long_name); |
124 Log("Could not open audio codec %s\n", g_pACodec->long_name); |
125 return; |
125 return; |
126 } |
126 } |
127 |
127 |
128 #if LIBAVCODEC_VERSION_MAJOR >= 54 |
128 #if LIBAVCODEC_VERSION_MAJOR >= 54 |
129 if (g_pACodec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) |
129 if (g_pACodec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) |
135 g_NumSamples = g_pAudio->frame_size; |
135 g_NumSamples = g_pAudio->frame_size; |
136 g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); |
136 g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); |
137 g_pAFrame = avcodec_alloc_frame(); |
137 g_pAFrame = avcodec_alloc_frame(); |
138 if (!g_pAFrame) |
138 if (!g_pAFrame) |
139 { |
139 { |
140 Log("Could not allocate frame"); |
140 Log("Could not allocate frame\n"); |
141 return; |
141 return; |
142 } |
142 } |
143 } |
143 } |
144 |
144 |
145 // returns non-zero if there is more sound |
145 // returns non-zero if there is more sound |
398 fread(&g_Frequency, 4, 1, g_pSoundFile); |
398 fread(&g_Frequency, 4, 1, g_pSoundFile); |
399 fread(&g_Channels, 4, 1, g_pSoundFile); |
399 fread(&g_Channels, 4, 1, g_pSoundFile); |
400 AddAudioStream(); |
400 AddAudioStream(); |
401 } |
401 } |
402 else |
402 else |
403 Log("Could not open %s", pSoundFile); |
403 Log("Could not open %s\n", pSoundFile); |
404 } |
404 } |
405 else |
405 else |
406 Log("Audio codec \"%s\" was not found; audio will be ignored.\n", pACodecName); |
406 Log("Audio codec \"%s\" was not found; audio will be ignored.\n", pACodecName); |
407 |
407 |
408 if (!g_pAStream && !g_pVStream) |
408 if (!g_pAStream && !g_pVStream) |
413 |
413 |
414 // open the output file, if needed |
414 // open the output file, if needed |
415 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
415 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
416 { |
416 { |
417 if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
417 if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
418 FatalError("Could not open output file (%s)", pFilename); |
418 FatalError("Could not open output file (%s)", g_pContainer->filename); |
419 } |
419 } |
420 |
420 |
421 // write the stream header, if any |
421 // write the stream header, if any |
422 avformat_write_header(g_pContainer, NULL); |
422 avformat_write_header(g_pContainer, NULL); |
423 |
423 |