In muxing example in link am attempting to use avcodec_send_frame()
and avcodec_receive_packet()
instead of avcodec_encode_audio2()
/avcodec_encode_video2()
as they are deprecated. In
352 ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
353 if (ret < 0) {
354 fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
355 exit(1);
356 }
357
358 if (got_packet) {
359 ret = write_frame(oc, &c->time_base, ost->st, &pkt);
360 if (ret < 0) {
361 fprintf(stderr, "Error while writing audio frame: %s\n",
362 av_err2str(ret));
363 exit(1);
364 }
365 }
366
367 return (frame || got_packet) ? 0 : 1;
and in
522 ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
523 if (ret < 0) {
524 fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
525 exit(1);
526 }
527
528 if (got_packet) {
529 ret = write_frame(oc, &c->time_base, ost->st, &pkt);
530 } else {
531 ret = 0;
532 }
533
534 if (ret < 0) {
535 fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret));
536 exit(1);
537 }
538
539 return (frame || got_packet) ? 0 : 1;
What to assign got_packet
variable with when using avcodec_send_frame()
and avcodec_receive_packet()
functions and how to change the code if I do?. I have tried this so far
ret = avcodec_send_frame(c, frame);
if (ret < 0) {
fprintf(stderr, "Error sending the frame to the audio encoder\n");
exit(1);
}
if (ret = 0) {
got_packet = avcodec_receive_packet(c, &pkt);
if (got_packet == AVERROR(EAGAIN) || got_packet == AVERROR_EOF){
fprintf(stderr, "Error receiving packet\n");
return -1;}
else if (got_packet < 0) {
fprintf(stderr, "Error encoding audio frame\n");
exit(1);
}
ret1 = write_frame(oc, &c->time_base, ost->st, &pkt);
if (ret1 < 0) {
fprintf(stderr, "Error while writing audio frame: %s\n",
av_err2str(ret1));
exit(1);
}
av_packet_unref(&pkt);
}
return (frame || got_packet) ? 0 : 1;
but isn't working and am having hard time getting it to work.