25 #include "libavcodec/avcodec.h" |
25 #include "libavcodec/avcodec.h" |
26 #include "libavformat/avformat.h" |
26 #include "libavformat/avformat.h" |
27 #include "libavutil/avutil.h" |
27 #include "libavutil/avutil.h" |
28 #include "libavutil/mathematics.h" |
28 #include "libavutil/mathematics.h" |
29 |
29 |
|
30 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
31 #include <libavcodec/bsf.h> |
|
32 #endif |
|
33 |
30 #if (defined _MSC_VER) |
34 #if (defined _MSC_VER) |
31 #define AVWRAP_DECL __declspec(dllexport) |
35 #define AVWRAP_DECL __declspec(dllexport) |
32 #elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun)) |
36 #elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun)) |
33 #define AVWRAP_DECL __attribute__((visibility("default"))) |
37 #define AVWRAP_DECL __attribute__((visibility("default"))) |
34 #else |
38 #else |
169 Log("Could not allocate audio stream\n"); |
173 Log("Could not allocate audio stream\n"); |
170 return; |
174 return; |
171 } |
175 } |
172 g_pAStream->id = 1; |
176 g_pAStream->id = 1; |
173 |
177 |
|
178 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
179 const AVCodec *audio_st_codec = avcodec_find_decoder(g_pAStream->codecpar->codec_id); |
|
180 g_pAudio = avcodec_alloc_context3(audio_st_codec); |
|
181 avcodec_parameters_to_context(g_pAudio, g_pAStream->codecpar); |
|
182 #else |
174 g_pAudio = g_pAStream->codec; |
183 g_pAudio = g_pAStream->codec; |
|
184 #endif |
175 |
185 |
176 avcodec_get_context_defaults3(g_pAudio, g_pACodec); |
186 avcodec_get_context_defaults3(g_pAudio, g_pACodec); |
177 g_pAudio->codec_id = g_pACodec->id; |
187 g_pAudio->codec_id = g_pACodec->id; |
178 |
188 |
179 // put parameters |
189 // put parameters |
277 { |
287 { |
278 g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
288 g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
279 if (!g_pVStream) |
289 if (!g_pVStream) |
280 return FatalError("Could not allocate video stream"); |
290 return FatalError("Could not allocate video stream"); |
281 |
291 |
|
292 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
293 const AVCodec *video_st_codec = avcodec_find_decoder(g_pVStream->codecpar->codec_id); |
|
294 g_pVideo = avcodec_alloc_context3(video_st_codec); |
|
295 avcodec_parameters_to_context(g_pVideo, g_pVStream->codecpar); |
|
296 #else |
282 g_pVideo = g_pVStream->codec; |
297 g_pVideo = g_pVStream->codec; |
|
298 #endif |
283 |
299 |
284 avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
300 avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
285 g_pVideo->codec_id = g_pVCodec->id; |
301 g_pVideo->codec_id = g_pVCodec->id; |
286 |
302 |
287 // put parameters |
303 // put parameters |
497 g_Height = Height; |
513 g_Height = Height; |
498 g_Framerate.num = FramerateNum; |
514 g_Framerate.num = FramerateNum; |
499 g_Framerate.den = FramerateDen; |
515 g_Framerate.den = FramerateDen; |
500 g_VQuality = VQuality; |
516 g_VQuality = VQuality; |
501 |
517 |
|
518 #if LIBAVCODEC_VERSION_MAJOR < 59 |
502 // initialize libav and register all codecs and formats |
519 // initialize libav and register all codecs and formats |
503 av_register_all(); |
520 av_register_all(); |
|
521 #endif |
504 |
522 |
505 // find format |
523 // find format |
506 g_pFormat = av_guess_format(pFormatName, NULL, NULL); |
524 g_pFormat = av_guess_format(pFormatName, NULL, NULL); |
507 if (!g_pFormat) |
525 if (!g_pFormat) |
508 return FatalError("Format \"%s\" was not found", pFormatName); |
526 return FatalError("Format \"%s\" was not found", pFormatName); |
520 // append extesnion to filename |
538 // append extesnion to filename |
521 char ext[16]; |
539 char ext[16]; |
522 strncpy(ext, g_pFormat->extensions, 16); |
540 strncpy(ext, g_pFormat->extensions, 16); |
523 ext[15] = 0; |
541 ext[15] = 0; |
524 ext[strcspn(ext,",")] = 0; |
542 ext[strcspn(ext,",")] = 0; |
|
543 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
544 snprintf(g_pContainer->url, sizeof(g_pContainer->url), "%s.%s", pFilename, ext); |
|
545 #else |
525 snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); |
546 snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); |
526 |
547 #endif |
527 // find codecs |
548 // find codecs |
528 g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
549 g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
529 g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
550 g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
530 |
551 |
531 // add audio and video stream to container |
552 // add audio and video stream to container |
558 |
579 |
559 if (!g_pAStream && !g_pVStream) |
580 if (!g_pAStream && !g_pVStream) |
560 return FatalError("No video, no audio, aborting..."); |
581 return FatalError("No video, no audio, aborting..."); |
561 |
582 |
562 // write format info to log |
583 // write format info to log |
|
584 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
585 av_dump_format(g_pContainer, 0, g_pContainer->url, 1); |
|
586 #else |
563 av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); |
587 av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); |
|
588 #endif |
564 |
589 |
565 // open the output file, if needed |
590 // open the output file, if needed |
566 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
591 if (!(g_pFormat->flags & AVFMT_NOFILE)) |
567 { |
592 { |
|
593 #if LIBAVCODEC_VERSION_MAJOR >= 59 |
|
594 if (avio_open(&g_pContainer->pb, g_pContainer->url, AVIO_FLAG_WRITE) < 0) |
|
595 return FatalError("Could not open output file (%s)", g_pContainer->url); |
|
596 #else |
568 if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
597 if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
569 return FatalError("Could not open output file (%s)", g_pContainer->filename); |
598 return FatalError("Could not open output file (%s)", g_pContainer->filename); |
|
599 #endif |
570 } |
600 } |
571 |
601 |
572 g_pVFrame->pts = -1; |
602 g_pVFrame->pts = -1; |
573 |
603 |
574 // write the stream header, if any |
604 // write the stream header, if any |