| 331 | } |
| 332 | |
| 333 | static int ffmpeg_encode_video(struct ffmpeg *ffmpeg) |
| 334 | { |
| 335 | #if ( MYFFVER >= 57041) |
| 336 | //ffmpeg version 3.1 and after |
| 337 | int retcd = 0; |
| 338 | char errstr[128]; |
| 339 | |
| 340 | retcd = avcodec_send_frame(ffmpeg->ctx_codec, ffmpeg->picture); |
| 341 | if (retcd < 0 ) { |
| 342 | av_strerror(retcd, errstr, sizeof(errstr)); |
| 343 | MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO |
| 344 | ,_("Error sending frame for encoding:%s"),errstr); |
| 345 | return -1; |
| 346 | } |
| 347 | retcd = avcodec_receive_packet(ffmpeg->ctx_codec, ffmpeg->pkt); |
| 348 | if (retcd == AVERROR(EAGAIN)) { |
| 349 | //Buffered packet. Throw special return code |
| 350 | av_strerror(retcd, errstr, sizeof(errstr)); |
| 351 | MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO |
| 352 | ,_("Receive packet threw EAGAIN returning -2 code :%s"),errstr); |
| 353 | ffmpeg_free_pkt(ffmpeg); |
| 354 | return -2; |
| 355 | } |
| 356 | if (retcd < 0 ) { |
| 357 | av_strerror(retcd, errstr, sizeof(errstr)); |
| 358 | MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO |
| 359 | ,_("Error receiving encoded packet video:%s"),errstr); |
| 360 | //Packet is freed upon failure of encoding |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M) { |
| 365 | if (ffmpeg_encode_nal(ffmpeg)) { |
| 366 | // Throw special return code |
| 367 | return -2; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return 0; |
| 372 | |
| 373 | #elif ( MYFFVER > 54006) |
| 374 | int retcd = 0; |
| 375 | char errstr[128]; |
| 376 | int got_packet_ptr; |
| 377 | |
| 378 | retcd = avcodec_encode_video2(ffmpeg->ctx_codec, ffmpeg->pkt, ffmpeg->picture, &got_packet_ptr); |
| 379 | if (retcd < 0 ) { |
| 380 | av_strerror(retcd, errstr, sizeof(errstr)); |
| 381 | MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video:%s"),errstr); |
| 382 | //Packet is freed upon failure of encoding |
| 383 | return -1; |
| 384 | } |
| 385 | if (got_packet_ptr == 0) { |
| 386 | //Buffered packet. Throw special return code |
| 387 | ffmpeg_free_pkt(ffmpeg); |
| 388 | return -2; |
| 389 | } |
| 390 |
no test coverage detected