equal
deleted
inserted
replaced
24 |
24 |
25 static FILE* g_pSoundFile; |
25 static FILE* g_pSoundFile; |
26 static int16_t* g_pSamples; |
26 static int16_t* g_pSamples; |
27 static int g_NumSamples; |
27 static int g_NumSamples; |
28 |
28 |
|
29 static char g_Filename[1024]; |
|
30 |
29 /* |
31 /* |
30 Initially I wrote code for latest ffmpeg, but on Linux (Ubuntu) |
32 Initially I wrote code for latest ffmpeg, but on Linux (Ubuntu) |
31 only older version is available from repository. That's why you see here |
33 only older version is available from repository. That's why you see here |
32 all of this #if LIBAVCODEC_VERSION_MAJOR < 54. |
34 all of this #if LIBAVCODEC_VERSION_MAJOR < 54. |
33 Actually, it may be possible to remove code for newer version |
35 Actually, it may be possible to remove code for newer version |
80 AddFileLogRaw(Buffer); |
82 AddFileLogRaw(Buffer); |
81 } |
83 } |
82 |
84 |
83 static void AddAudioStream() |
85 static void AddAudioStream() |
84 { |
86 { |
85 #if LIBAVCODEC_VERSION_MAJOR >= 54 |
87 #if LIBAVFORMAT_VERSION_MAJOR >= 54 |
86 g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); |
88 g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); |
87 #else |
89 #else |
88 g_pAStream = av_new_stream(g_pContainer, 1); |
90 g_pAStream = av_new_stream(g_pContainer, 1); |
89 #endif |
91 #endif |
90 if(!g_pAStream) |
92 if(!g_pAStream) |
181 } |
183 } |
182 |
184 |
183 // add a video output stream |
185 // add a video output stream |
184 static void AddVideoStream() |
186 static void AddVideoStream() |
185 { |
187 { |
186 #if LIBAVCODEC_VERSION_MAJOR >= 54 |
188 #if LIBAVFORMAT_VERSION_MAJOR >= 54 |
187 g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
189 g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
188 #else |
190 #else |
189 g_pVStream = av_new_stream(g_pContainer, 0); |
191 g_pVStream = av_new_stream(g_pContainer, 0); |
190 #endif |
192 #endif |
191 if (!g_pVStream) |
193 if (!g_pVStream) |
192 FatalError("Could not allocate video stream"); |
194 FatalError("Could not allocate video stream"); |
193 |
195 |
194 g_pVideo = g_pVStream->codec; |
196 g_pVideo = g_pVStream->codec; |
195 |
197 |
196 avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
198 avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
197 g_pVideo->codec_id = g_pVCodec->id; |
199 g_pVideo->codec_id = g_pVCodec->id; |
198 |
200 |
199 // put parameters |
201 // put parameters |
200 // resolution must be a multiple of two |
202 // resolution must be a multiple of two |
319 } |
321 } |
320 |
322 |
321 void AVWrapper_Init( |
323 void AVWrapper_Init( |
322 void (*pAddFileLogRaw)(const char*), |
324 void (*pAddFileLogRaw)(const char*), |
323 const char* pFilename, |
325 const char* pFilename, |
|
326 const char* pFinalFilename, |
324 const char* pSoundFile, |
327 const char* pSoundFile, |
325 const char* pFormatName, |
328 const char* pFormatName, |
326 const char* pVCodecName, |
329 const char* pVCodecName, |
327 const char* pACodecName, |
330 const char* pACodecName, |
328 const char* pVPreset, |
331 const char* pVPreset, |
358 FatalError("Could not allocate output context"); |
361 FatalError("Could not allocate output context"); |
359 |
362 |
360 g_pContainer->oformat = g_pFormat; |
363 g_pContainer->oformat = g_pFormat; |
361 |
364 |
362 // append extesnion to filename |
365 // append extesnion to filename |
363 snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), |
366 char ext[16]; |
364 "%s.%*s", |
367 strncpy(ext, g_pFormat->extensions, 16); |
365 pFilename, |
368 ext[15] = 0; |
366 strcspn(g_pFormat->extensions, ","), g_pFormat->extensions); |
369 ext[strcspn(ext,",")] = 0; |
|
370 snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); |
|
371 snprintf(g_Filename, sizeof(g_Filename), "%s.%s", pFinalFilename, ext); |
367 |
372 |
368 // find codecs |
373 // find codecs |
369 g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
374 g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
370 g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
375 g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
371 |
376 |
421 av_write_trailer(g_pContainer); |
426 av_write_trailer(g_pContainer); |
422 |
427 |
423 // close the output file |
428 // close the output file |
424 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
429 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
425 avio_close(g_pContainer->pb); |
430 avio_close(g_pContainer->pb); |
|
431 |
|
432 // move file to destination |
|
433 rename(g_pContainer->filename, g_Filename); |
426 |
434 |
427 // free everything |
435 // free everything |
428 if (g_pVStream) |
436 if (g_pVStream) |
429 { |
437 { |
430 avcodec_close(g_pVideo); |
438 avcodec_close(g_pVideo); |