| | 7 | |
| | 8 | The actual transcoding loop that runs 24/7: |
| | 9 | |
| | 10 | |
| | 11 | {{{ |
| | 12 | while (av_read_frame(ctx, input_packet) == 0) |
| | 13 | { |
| | 14 | int response = avcodec_send_packet(decctx, input_packet); |
| | 15 | while (response >= 0) |
| | 16 | { |
| | 17 | response = avcodec_receive_frame(decctx, input_frame); |
| | 18 | if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) |
| | 19 | { |
| | 20 | av_frame_unref(input_frame); |
| | 21 | av_packet_unref(input_packet); |
| | 22 | goto read_input; |
| | 23 | } |
| | 24 | else if (response < 0) |
| | 25 | { |
| | 26 | return response; |
| | 27 | } |
| | 28 | if (response >= 0) |
| | 29 | { |
| | 30 | input_frame->pts = in_pts; |
| | 31 | in_pts += input_frame->nb_samples; |
| | 32 | response = av_buffersrc_add_frame(src, input_frame); |
| | 33 | if (response < 0) |
| | 34 | { |
| | 35 | fprintf(stderr, "Cannot send frame to afilter:"); |
| | 36 | av_frame_unref(input_frame); |
| | 37 | av_packet_unref(input_packet); |
| | 38 | goto read_input; |
| | 39 | } |
| | 40 | while ((response = av_buffersink_get_frame(sink, out_frame)) >= 0) |
| | 41 | { |
| | 42 | out_frame->pts = out_pts; |
| | 43 | out_pts += out_frame->nb_samples; |
| | 44 | encode(ofmt_ctx, istream, ostream, encctx, audio_stream_index, out_frame); |
| | 45 | av_frame_unref(out_frame); |
| | 46 | } |
| | 47 | av_frame_unref(input_frame); |
| | 48 | } |
| | 49 | } |
| | 50 | av_packet_unref(input_packet); |
| | 51 | } |
| | 52 | }}} |
| | 53 | |
| | 54 | |