diff options
Diffstat (limited to 'src/plugins/thumbnailffmpeg_extractor.c')
-rw-r--r-- | src/plugins/thumbnailffmpeg_extractor.c | 79 |
1 files changed, 3 insertions, 76 deletions
diff --git a/src/plugins/thumbnailffmpeg_extractor.c b/src/plugins/thumbnailffmpeg_extractor.c index 9bed4ec..ef7a05f 100644 --- a/src/plugins/thumbnailffmpeg_extractor.c +++ b/src/plugins/thumbnailffmpeg_extractor.c | |||
@@ -195,14 +195,10 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
195 | pkt.size = 0; | 195 | pkt.size = 0; |
196 | int gotPacket; | 196 | int gotPacket; |
197 | #if USE_JPEG | 197 | #if USE_JPEG |
198 | #if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0) | ||
199 | if (NULL == (encoder_codec = avcodec_find_encoder (AV_CODEC_ID_MJPEG))) | 198 | if (NULL == (encoder_codec = avcodec_find_encoder (AV_CODEC_ID_MJPEG))) |
200 | #else | 199 | #else |
201 | if (NULL == (encoder_codec = avcodec_find_encoder (CODEC_ID_MJPEG))) | ||
202 | #endif | ||
203 | #else | ||
204 | if (NULL == (encoder_codec = avcodec_find_encoder_by_name ("png"))) | 200 | if (NULL == (encoder_codec = avcodec_find_encoder_by_name ("png"))) |
205 | #endif | 201 | #endif |
206 | { | 202 | { |
207 | #if DEBUG | 203 | #if DEBUG |
208 | fprintf (stderr, | 204 | fprintf (stderr, |
@@ -227,11 +223,7 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
227 | return 0; | 223 | return 0; |
228 | } | 224 | } |
229 | 225 | ||
230 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
231 | dst_frame = av_frame_alloc (); | 226 | dst_frame = av_frame_alloc (); |
232 | #else | ||
233 | dst_frame = avcodec_alloc_frame (); | ||
234 | #endif | ||
235 | if (NULL == dst_frame) | 227 | if (NULL == dst_frame) |
236 | { | 228 | { |
237 | #if DEBUG | 229 | #if DEBUG |
@@ -251,11 +243,7 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
251 | fprintf (stderr, | 243 | fprintf (stderr, |
252 | "Failed to allocate the destination image buffer\n"); | 244 | "Failed to allocate the destination image buffer\n"); |
253 | #endif | 245 | #endif |
254 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
255 | av_frame_free (&dst_frame); | 246 | av_frame_free (&dst_frame); |
256 | #else | ||
257 | avcodec_free_frame (&dst_frame); | ||
258 | #endif | ||
259 | sws_freeContext (scaler_ctx); | 247 | sws_freeContext (scaler_ctx); |
260 | return 0; | 248 | return 0; |
261 | } | 249 | } |
@@ -281,11 +269,7 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
281 | "Failed to allocate the encoder output buffer\n"); | 269 | "Failed to allocate the encoder output buffer\n"); |
282 | #endif | 270 | #endif |
283 | av_free (dst_buffer); | 271 | av_free (dst_buffer); |
284 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
285 | av_frame_free (&dst_frame); | 272 | av_frame_free (&dst_frame); |
286 | #else | ||
287 | avcodec_free_frame (&dst_frame); | ||
288 | #endif | ||
289 | sws_freeContext (scaler_ctx); | 273 | sws_freeContext (scaler_ctx); |
290 | return 0; | 274 | return 0; |
291 | } | 275 | } |
@@ -298,11 +282,7 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
298 | #endif | 282 | #endif |
299 | av_free (encoder_output_buffer); | 283 | av_free (encoder_output_buffer); |
300 | av_free (dst_buffer); | 284 | av_free (dst_buffer); |
301 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
302 | av_frame_free (&dst_frame); | 285 | av_frame_free (&dst_frame); |
303 | #else | ||
304 | avcodec_free_frame (&dst_frame); | ||
305 | #endif | ||
306 | sws_freeContext (scaler_ctx); | 286 | sws_freeContext (scaler_ctx); |
307 | return 0; | 287 | return 0; |
308 | } | 288 | } |
@@ -310,16 +290,8 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
310 | encoder_codec_ctx->height = dst_height; | 290 | encoder_codec_ctx->height = dst_height; |
311 | #if USE_JPEG | 291 | #if USE_JPEG |
312 | encoder_codec_ctx->bit_rate = pCodecCtx->bit_rate; | 292 | encoder_codec_ctx->bit_rate = pCodecCtx->bit_rate; |
313 | #if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0) | ||
314 | encoder_codec_ctx->codec_id = AV_CODEC_ID_MJPEG; | 293 | encoder_codec_ctx->codec_id = AV_CODEC_ID_MJPEG; |
315 | #else | ||
316 | encoder_codec_ctx->codec_id = CODEC_ID_MJPEG; | ||
317 | #endif | ||
318 | #if LIBAVCODEC_BUILD >= AV_VERSION_INT (53,35,0) | ||
319 | encoder_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO; | 294 | encoder_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO; |
320 | #else | ||
321 | encoder_codec_ctx->codec_type = CODEC_TYPE_VIDEO; | ||
322 | #endif | ||
323 | encoder_codec_ctx->time_base.num = pCodecCtx->time_base.num; | 295 | encoder_codec_ctx->time_base.num = pCodecCtx->time_base.num; |
324 | encoder_codec_ctx->time_base.den = pCodecCtx->time_base.den; | 296 | encoder_codec_ctx->time_base.den = pCodecCtx->time_base.den; |
325 | encoder_codec_ctx->pix_fmt = PIX_OUTPUT_FORMAT; | 297 | encoder_codec_ctx->pix_fmt = PIX_OUTPUT_FORMAT; |
@@ -337,11 +309,7 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
337 | avcodec_free_context (&encoder_codec_ctx); | 309 | avcodec_free_context (&encoder_codec_ctx); |
338 | av_free (encoder_output_buffer); | 310 | av_free (encoder_output_buffer); |
339 | av_free (dst_buffer); | 311 | av_free (dst_buffer); |
340 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
341 | av_frame_free (&dst_frame); | 312 | av_frame_free (&dst_frame); |
342 | #else | ||
343 | avcodec_free_frame (&dst_frame); | ||
344 | #endif | ||
345 | sws_freeContext (scaler_ctx); | 313 | sws_freeContext (scaler_ctx); |
346 | return 0; | 314 | return 0; |
347 | } | 315 | } |
@@ -364,7 +332,6 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
364 | dst_frame->quality = encoder_codec_ctx->global_quality; | 332 | dst_frame->quality = encoder_codec_ctx->global_quality; |
365 | #endif | 333 | #endif |
366 | 334 | ||
367 | #if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0) | ||
368 | err = avcodec_encode_video2 (encoder_codec_ctx, | 335 | err = avcodec_encode_video2 (encoder_codec_ctx, |
369 | &pkt, | 336 | &pkt, |
370 | dst_frame, &gotPacket); | 337 | dst_frame, &gotPacket); |
@@ -375,24 +342,12 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, | |||
375 | memcpy (encoder_output_buffer,pkt.data, pkt.size); | 342 | memcpy (encoder_output_buffer,pkt.data, pkt.size); |
376 | 343 | ||
377 | av_packet_unref (&pkt); | 344 | av_packet_unref (&pkt); |
378 | |||
379 | |||
380 | #else | ||
381 | err = avcodec_encode_video (encoder_codec_ctx, | ||
382 | encoder_output_buffer, | ||
383 | encoder_output_buffer_size, dst_frame); | ||
384 | |||
385 | #endif | ||
386 | cleanup: | 345 | cleanup: |
387 | av_dict_free (&opts); | 346 | av_dict_free (&opts); |
388 | avcodec_close (encoder_codec_ctx); | 347 | avcodec_close (encoder_codec_ctx); |
389 | avcodec_free_context (&encoder_codec_ctx); | 348 | avcodec_free_context (&encoder_codec_ctx); |
390 | av_free (dst_buffer); | 349 | av_free (dst_buffer); |
391 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
392 | av_frame_free (&dst_frame); | 350 | av_frame_free (&dst_frame); |
393 | #else | ||
394 | avcodec_free_frame (&dst_frame); | ||
395 | #endif | ||
396 | sws_freeContext (scaler_ctx); | 351 | sws_freeContext (scaler_ctx); |
397 | *output_data = encoder_output_buffer; | 352 | *output_data = encoder_output_buffer; |
398 | 353 | ||
@@ -448,11 +403,7 @@ calculate_thumbnail_dimensions (int src_width, | |||
448 | } | 403 | } |
449 | 404 | ||
450 | 405 | ||
451 | #if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0) | 406 | #define ENUM_CODEC_ID enum AVCodecID |
452 | #define ENUM_CODEC_ID enum AVCodecID | ||
453 | #else | ||
454 | #define ENUM_CODEC_ID enum CodecID | ||
455 | #endif | ||
456 | 407 | ||
457 | /** | 408 | /** |
458 | * Perform thumbnailing when the input is an image. | 409 | * Perform thumbnailing when the input is an image. |
@@ -505,11 +456,7 @@ extract_image (ENUM_CODEC_ID image_codec_id, | |||
505 | return; | 456 | return; |
506 | } | 457 | } |
507 | av_dict_free (&opts); | 458 | av_dict_free (&opts); |
508 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
509 | frame = av_frame_alloc (); | 459 | frame = av_frame_alloc (); |
510 | #else | ||
511 | frame = avcodec_alloc_frame (); | ||
512 | #endif | ||
513 | if (NULL == frame) | 460 | if (NULL == frame) |
514 | { | 461 | { |
515 | #if DEBUG | 462 | #if DEBUG |
@@ -541,11 +488,7 @@ extract_image (ENUM_CODEC_ID image_codec_id, | |||
541 | fprintf (stderr, | 488 | fprintf (stderr, |
542 | "Failed to decode a complete frame\n"); | 489 | "Failed to decode a complete frame\n"); |
543 | #endif | 490 | #endif |
544 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
545 | av_frame_free (&frame); | 491 | av_frame_free (&frame); |
546 | #else | ||
547 | avcodec_free_frame (&frame); | ||
548 | #endif | ||
549 | avcodec_close (codec_ctx); | 492 | avcodec_close (codec_ctx); |
550 | avcodec_free_context (&codec_ctx); | 493 | avcodec_free_context (&codec_ctx); |
551 | return; | 494 | return; |
@@ -591,11 +534,7 @@ extract_image (ENUM_CODEC_ID image_codec_id, | |||
591 | 534 | ||
592 | av_free (encoded_thumbnail); | 535 | av_free (encoded_thumbnail); |
593 | } | 536 | } |
594 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
595 | av_frame_free (&frame); | 537 | av_frame_free (&frame); |
596 | #else | ||
597 | avcodec_free_frame (&frame); | ||
598 | #endif | ||
599 | avcodec_close (codec_ctx); | 538 | avcodec_close (codec_ctx); |
600 | avcodec_free_context (&codec_ctx); | 539 | avcodec_free_context (&codec_ctx); |
601 | } | 540 | } |
@@ -698,11 +637,7 @@ extract_video (struct EXTRACTOR_ExtractContext *ec) | |||
698 | return; | 637 | return; |
699 | } | 638 | } |
700 | 639 | ||
701 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
702 | frame = av_frame_alloc (); | 640 | frame = av_frame_alloc (); |
703 | #else | ||
704 | frame = avcodec_alloc_frame (); | ||
705 | #endif | ||
706 | if (NULL == frame) | 641 | if (NULL == frame) |
707 | { | 642 | { |
708 | #if DEBUG | 643 | #if DEBUG |
@@ -766,11 +701,7 @@ extract_video (struct EXTRACTOR_ExtractContext *ec) | |||
766 | fprintf (stderr, | 701 | fprintf (stderr, |
767 | "Failed to decode a complete frame\n"); | 702 | "Failed to decode a complete frame\n"); |
768 | #endif | 703 | #endif |
769 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
770 | av_frame_free (&frame); | 704 | av_frame_free (&frame); |
771 | #else | ||
772 | avcodec_free_frame (&frame); | ||
773 | #endif | ||
774 | avcodec_close (codec_ctx); | 705 | avcodec_close (codec_ctx); |
775 | avformat_close_input (&format_ctx); | 706 | avformat_close_input (&format_ctx); |
776 | av_free (io_ctx); | 707 | av_free (io_ctx); |
@@ -813,11 +744,7 @@ extract_video (struct EXTRACTOR_ExtractContext *ec) | |||
813 | #endif | 744 | #endif |
814 | av_free (encoded_thumbnail); | 745 | av_free (encoded_thumbnail); |
815 | } | 746 | } |
816 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1) | ||
817 | av_frame_free (&frame); | 747 | av_frame_free (&frame); |
818 | #else | ||
819 | avcodec_free_frame (&frame); | ||
820 | #endif | ||
821 | avcodec_close (codec_ctx); | 748 | avcodec_close (codec_ctx); |
822 | avformat_close_input (&format_ctx); | 749 | avformat_close_input (&format_ctx); |
823 | av_free (io_ctx); | 750 | av_free (io_ctx); |