void v4l2_close(struct camera *cam) { stop_capturing(cam); uninit_camera(cam); close_camera(cam); free(cam); close_file(); close_encoder(); }
int uninit_video_encoder(video_encoder_t *videoencoder) { if(videoencoder == NULL) { fprintf(stderr ,"libvideoencoder: Error paraments..\n"); return -1; } videoencoder_instanse *p_instanse = (videoencoder_instanse *)videoencoder; free(p_instanse->outbf); free(p_instanse->enc_buf); free(p_instanse); close_encoder(); return 0; }
int main(void) { AVCodec *enc = NULL, *dec = NULL; AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL; uint64_t channel_layouts[] = {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1_BACK, AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_STEREO_DOWNMIX}; int sample_rates[] = {8000, 44100, 48000, 192000}; int cl, sr; avcodec_register_all(); enc = avcodec_find_encoder(AV_CODEC_ID_FLAC); if (!enc) { av_log(NULL, AV_LOG_ERROR, "Can't find encoder\n"); return 1; } dec = avcodec_find_decoder(AV_CODEC_ID_FLAC); if (!dec) { av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n"); return 1; } for (cl = 0; cl < FF_ARRAY_ELEMS(channel_layouts); cl++) { for (sr = 0; sr < FF_ARRAY_ELEMS(sample_rates); sr++) { if (init_encoder(enc, &enc_ctx, channel_layouts[cl], sample_rates[sr]) != 0) return 1; if (init_decoder(dec, &dec_ctx, channel_layouts[cl]) != 0) return 1; if (run_test(enc, dec, enc_ctx, dec_ctx) != 0) return 1; close_encoder(&enc_ctx); close_decoder(&dec_ctx); } } return 0; }
static void split_video(const char *infilename, const char *outfmt, int gop_size, int chunk_size, int skip, long long length, AVDictionary *_opt) { DecoderContext *dc; EncoderContext *ec; AVFrame *frame; int width, height; long long frame_count = 0, out_frame_num = 0; int chunk_count = 0; char outfilename[MAX_FILENAME_LEN]; AVDictionary *opt = NULL; AVRational framerate; enum AVPixelFormat pix_fmt; av_dict_copy(&opt, _opt, 0); // Initialize the decoder dc = init_decoder(infilename); // Extract parms needed by encoder width = dc->codecCtx->width; height = dc->codecCtx->height; framerate = dc->codecCtx->framerate; pix_fmt = dc->codecCtx->pix_fmt; // Skip input frames if (skip > 0) fprintf(stderr, "Skipping %d frames\n", skip); while (skip > 0) { // TODO: I'd rather not decode the frames, but this will take some work to // refactor if (!read_frame(dc)) { fprintf(stderr, "No more frames available, skip = %d\n", skip); exit(0); } --skip; } // Initialize output fprintf(stderr, "\rWriting chunk %05d", chunk_count); fflush(stderr); snprintf(outfilename, MAX_FILENAME_LEN, outfmt, chunk_count++); ec = init_encoder(outfilename, gop_size, width, height, framerate, pix_fmt, opt); while (length <= 0 || frame_count < length) { frame = read_frame(dc); if (!frame) break; if (out_frame_num == chunk_size) { close_encoder(ec); fprintf(stderr, "\rWriting chunk %05d", chunk_count); fflush(stderr); snprintf(outfilename, MAX_FILENAME_LEN, outfmt, chunk_count++); ec = init_encoder(outfilename, gop_size, width, height, framerate, pix_fmt, opt); out_frame_num = 0; } set_pict_type(frame, gop_size, out_frame_num); frame->pts = out_frame_num++; frame_count++; write_video_frame(ec, frame); } close_encoder(ec); close_decoder(dc); fprintf(stderr, "\nRead %lld frames\n", frame_count); fprintf(stderr, "Wrote %d chunks of %d frames each (last chunk: %lld frames)\n", chunk_count, chunk_size, out_frame_num); fprintf(stderr, " for a total of %lld frames\n", (chunk_count-1) * chunk_size + out_frame_num); }