- video.set_frame_callback(bind(video_frame_callback, &video, x264_encoder.get(), audio_encoder.get(), _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11));
- if (!global_flags.transcode_audio) {
- video.set_audio_callback(bind(audio_frame_callback, http_mux.get(), _1, _2));
+ if (global_flags.transcode_video) {
+ video.set_frame_callback(bind(video_frame_callback, &video, x264_encoder.get(), audio_encoder.get(), _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11));
+ } else {
+ video.set_video_callback(bind(raw_packet_callback, http_mux.get(), /*stream_index=*/0, _1, _2));
+ }
+ if (!global_flags.transcode_audio && global_flags.enable_audio) {
+ AVBSFContext *bsfctx = nullptr;
+ if (strcmp(oformat->name, "mp4") == 0 && strcmp(audio_encoder->get_codec()->name, "aac") == 0) {
+ // We need to insert the aac_adtstoasc filter, seemingly (or we will get warnings to do so).
+ const AVBitStreamFilter *filter = av_bsf_get_by_name("aac_adtstoasc");
+ int err = av_bsf_alloc(filter, &bsfctx);
+ if (err < 0) {
+ fprintf(stderr, "av_bsf_alloc() failed with %d\n", err);
+ exit(1);
+ }
+ }
+ if (bsfctx == nullptr) {
+ video.set_audio_callback(bind(raw_packet_callback, http_mux.get(), /*stream_index=*/1, _1, _2));
+ } else {
+ video.set_audio_callback(bind(filter_packet_callback, http_mux.get(), /*stream_index=*/1, bsfctx, _1, _2));
+ }