- printf("\n\nINPUT:Try to encode H264...\n");
- if (rc_mode != -1)
- printf("INPUT: RateControl : %s\n", rc_to_string(rc_mode));
- printf("INPUT: Resolution : %dx%dframes\n", frame_width, frame_height);
- printf("INPUT: FrameRate : %d\n", frame_rate);
- printf("INPUT: Bitrate : %d\n", frame_bitrate);
- printf("INPUT: Slieces : %d\n", frame_slices);
- printf("INPUT: IntraPeriod : %d\n", intra_period);
- printf("INPUT: IDRPeriod : %d\n", intra_idr_period);
- printf("INPUT: IpPeriod : %d\n", ip_period);
- printf("INPUT: Initial QP : %d\n", initial_qp);
- printf("INPUT: Min QP : %d\n", minimal_qp);
- printf("INPUT: Coded Clip : %s\n", coded_fn);
-
- printf("\n\n"); /* return back to startpoint */
-
- return 0;
-}
-
-
-//H264Encoder::H264Encoder(SDL_Window *window, SDL_GLContext context, int width, int height, const char *output_filename)
-H264Encoder::H264Encoder(QSurface *surface, int width, int height, const char *output_filename)
- : current_storage_frame(0), surface(surface)
- //: width(width), height(height), current_encoding_frame(0)
-{
- av_register_all();
- avctx = avformat_alloc_context();
- avctx->oformat = av_guess_format(NULL, output_filename, NULL);
- strcpy(avctx->filename, output_filename);
- if (avio_open2(&avctx->pb, output_filename, AVIO_FLAG_WRITE, &avctx->interrupt_callback, NULL) < 0) {
- fprintf(stderr, "%s: avio_open2() failed\n", output_filename);
- exit(1);
- }
- AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);
- avstream = avformat_new_stream(avctx, codec);
- if (avstream == nullptr) {
- fprintf(stderr, "%s: avformat_new_stream() failed\n", output_filename);
- exit(1);
- }
- avstream->time_base = AVRational{1, frame_rate};
- avstream->codec->width = width;
- avstream->codec->height = height;
- avstream->codec->time_base = AVRational{1, frame_rate};
- avstream->codec->ticks_per_frame = 1; // or 2?
-
- if (avformat_write_header(avctx, NULL) < 0) {
- fprintf(stderr, "%s: avformat_write_header() failed\n", output_filename);
+ AVCodec *codec_audio = avcodec_find_encoder(AUDIO_OUTPUT_CODEC);
+ context_audio = avcodec_alloc_context3(codec_audio);
+ context_audio->bit_rate = AUDIO_OUTPUT_BIT_RATE;
+ context_audio->sample_rate = OUTPUT_FREQUENCY;
+ context_audio->sample_fmt = AUDIO_OUTPUT_SAMPLE_FMT;
+ context_audio->channels = 2;
+ context_audio->channel_layout = AV_CH_LAYOUT_STEREO;
+ context_audio->time_base = AVRational{1, TIMEBASE};
+ if (avcodec_open2(context_audio, codec_audio, NULL) < 0) {
+ fprintf(stderr, "Could not open codec\n");