JNIEXPORT void JNICALL Java_com_parizene_streamer_Streamer_deinit(JNIEnv *env, jobject obj) { LOGD("deinit()"); /* get the delayed frames */ for (got_output = 1; got_output; count++) { if (avcodec_encode_video2(codecContext, &packet, NULL, &got_output) < 0) { LOGE("couldn't encode frame"); exit(1); } if (got_output) { // LOGI("write frame %3d (size=%5d)", count, packet.size); fwrite(packet.data, 1, packet.size, file); av_free_packet(&packet); } } uint8_t endcode[] = { 0, 0, 1, 0xb7 }; /* add sequence end code to have a real mpeg file */ fwrite(endcode, 1, sizeof(endcode), file); fclose(file); avcodec_close(codecContext); av_free(codecContext); av_freep(&frame->data[0]); avcodec_free_frame(&frame); avcodec_free_frame(&tmpFrame); }
void AndCodec_EasyDecoderClose(dec) { and_log_writeline_simple(0, LOG_INFO, "AndCodec_EasyDecoderClose()"); easy_decoder_handle* handle = (easy_decoder_handle *)dec; and_log_writeline_easy(0, LOG_INFO, "decoder handle %x", handle); if(handle->dec_frame) avcodec_free_frame(&handle->dec_frame); if(handle->pic_trans && handle->out_frame) avcodec_free_frame(&handle->out_frame); if(handle->dec_ctx) { avcodec_close(handle->dec_ctx); av_free(handle->dec_ctx); } pthread_mutex_destroy(&handle->mutex); and_fifo_close(&handle->fifo); and_queue_close(&handle->queue); and_sysutil_free(handle); and_log_close(); }
video_recording_state_t::~video_recording_state_t(void) { if (video_frame_raw) avcodec_free_frame(&video_frame_raw); if (video_frame) avcodec_free_frame(&video_frame); if (audio_frame) avcodec_free_frame(&audio_frame); if (output_context) avformat_free_context(output_context); }
void PacketReceiver::destroyFrames() { av_free(frameBGRBuffer); frameBGRBuffer = NULL; avcodec_free_frame(&frameReceived); //av_frame_free(&frameReceived); avcodec_free_frame(&frameBGR); }
void convert_close(struct cvt_handle *handle) { av_free(handle->dst_buffer); avcodec_free_frame(&handle->dst_frame); av_free(handle->src_buffer); avcodec_free_frame(&handle->src_frame); sws_freeContext(handle->sws_ctx); free(handle); printf("+++ Convert Closed\n"); }
void cleanup_ffmpeg_simple_data (struct ffmpeg_simple_data *d) { sws_freeContext(d->img_convert_ctx); av_free_packet(&d->packet); avcodec_free_frame(&d->frame); avcodec_free_frame(&d->frameRGB); if (d->videoStream) { avcodec_close(d->videoStream->codec); } if (d->pFormatCtx) { avformat_close_input(&d->pFormatCtx); } }
static void close_file( void *private_stuff ) { libav_handler_t *hp = (libav_handler_t *)private_stuff; if( !hp ) return; if( hp->vdh.frame_buffer ) avcodec_free_frame( &hp->vdh.frame_buffer ); if( hp->adh.frame_buffer ) avcodec_free_frame( &hp->adh.frame_buffer ); if( hp->lwh.file_path ) free( hp->lwh.file_path ); free( hp ); }
void InputHandler::Close() { if(video_dec_ctx) avcodec_close(video_dec_ctx); //if(pCodecCtx) avcodec_close(pCodecCtx); //if(bsf) av_bitstream_filter_close(bsf); //if(out_ctx) avformat_free_context(out_ctx); if(fmt_ctx) avformat_close_input(&fmt_ctx); if(sws_ctx) sws_freeContext(sws_ctx); if(bsf) av_bitstream_filter_close(bsf); if(sdp_desc) av_free(sdp_desc); if(io_buffer) av_free(io_buffer); if(m_PictureBuffer) delete m_PictureBuffer; avcodec_free_frame(&frame); avcodec_free_frame(&frameRGB); }
int naFinish(JNIEnv *pEnv, jobject pObj, jobject pBitmap) { VideoDisplayUtil* vdu = gvdu; //free RGBA images AndroidBitmap_unlockPixels(pEnv, pBitmap); avcodec_free_frame(&vdu->pFrameRGBA); VideoState* vs = gvs; avcodec_free_frame(&vs->frame); //close codec avcodec_close(vs->pVideoStream->codec); //close video file avformat_close_input(&vs->pFormatCtx); av_free(vs); return 0; }
void FFmpegEncoderClose(struct FFmpegEncoder* encoder) { if (!encoder->context) { return; } av_write_trailer(encoder->context); avio_close(encoder->context->pb); if (encoder->audioCodec) { av_free(encoder->postaudioBuffer); if (encoder->audioBuffer) { av_free(encoder->audioBuffer); } #if LIBAVCODEC_VERSION_MAJOR >= 55 av_frame_free(&encoder->audioFrame); #else avcodec_free_frame(&encoder->audioFrame); #endif avcodec_close(encoder->audio); if (encoder->resampleContext) { #ifdef USE_LIBAVRESAMPLE avresample_close(encoder->resampleContext); #else swr_free(&encoder->resampleContext); #endif } if (encoder->absf) { #ifdef FFMPEG_USE_NEW_BSF av_bsf_free(&encoder->absf); #else av_bitstream_filter_close(encoder->absf); encoder->absf = 0; #endif } } #if LIBAVCODEC_VERSION_MAJOR >= 55 av_frame_free(&encoder->videoFrame); #else avcodec_free_frame(&encoder->videoFrame); #endif avcodec_close(encoder->video); sws_freeContext(encoder->scaleContext); encoder->scaleContext = NULL; avformat_free_context(encoder->context); encoder->context = 0; }
void del_aubio_source_avcodec(aubio_source_avcodec_t * s){ if (!s) return; if (s->output != NULL) { av_free(s->output); } if (s->avr != NULL) { avresample_close( s->avr ); av_free ( s->avr ); } s->avr = NULL; if (s->avFrame != NULL) { avcodec_free_frame( &(s->avFrame) ); } s->avFrame = NULL; if (s->avCodecCtx != NULL) { avcodec_close ( s->avCodecCtx ); } s->avCodecCtx = NULL; if (s->avFormatCtx != NULL) { avformat_close_input ( &(s->avFormatCtx) ); } s->avFrame = NULL; s->avFormatCtx = NULL; AUBIO_FREE(s); }
static void write_audio_frame(AVFormatContext *oc, AVStream *st) { AVCodecContext *c; AVPacket pkt = { 0 }; // data and size must be 0; AVFrame *frame = avcodec_alloc_frame(); int got_packet; av_init_packet(&pkt); c = st->codec; get_audio_frame(samples, audio_input_frame_size, c->channels); frame->nb_samples = audio_input_frame_size; avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, (uint8_t *)samples, audio_input_frame_size * av_get_bytes_per_sample(c->sample_fmt) * c->channels, 1); avcodec_encode_audio2(c, &pkt, frame, &got_packet); if (!got_packet) return; pkt.stream_index = st->index; /* Write the compressed frame to the media file. */ if (av_interleaved_write_frame(oc, &pkt) != 0) { fprintf(stderr, "Error while writing audio frame\n"); exit(1); } avcodec_free_frame(&frame); }
AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_index) { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) AVFrame *pFrame = av_frame_alloc(); #else AVFrame *pFrame = avcodec_alloc_frame(); #endif AVPacket packet; int frame_finished = 0; while(!frame_finished && av_read_frame(pFormatCtx, &packet)>=0) { if(packet.stream_index == frame_stream_index) { avcodec_decode_video2(codec_ctx, pFrame, &frame_finished, &packet); } #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,7,0) av_packet_unref(&packet); #else av_free_packet(&packet); #endif } if(frame_finished) { return pFrame; } else { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) av_frame_free(&pFrame); #else avcodec_free_frame(&pFrame); #endif return NULL; } }
void FFMPEG_Wrapper::shutdown() { boost::mutex::scoped_lock lock(frame_mutex_); if (init_) { // give ffmpeg enough time to initialize before shutdown boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration diff = now - time_started_; unsigned int milisec_used = std::max(100u,(unsigned int)diff.total_milliseconds()); if (milisec_used < MILLISEC_FOR_FFMPEG_INIT) { // if encoder worked faster than the desired frame rate -> go sleeping boost::this_thread::sleep(boost::posix_time::milliseconds(MILLISEC_FOR_FFMPEG_INIT - milisec_used)); } // Close the codec if (ffmpeg_codec_context_) { boost::mutex::scoped_lock lock(codec_mutex_); avcodec_close(ffmpeg_codec_context_); } if (ffmpeg_frame_) avcodec_free_frame(&ffmpeg_frame_); if (ffmpeg_format_context_) { /* Free the streams. */ /* for (i = 0; i < ffmpeg_format_context_->nb_streams; i++) { avcodec_close(ffmpeg_format_context_->streams[i]->codec); av_freep(&ffmpeg_format_context_->streams[i]->metadata); av_freep(&ffmpeg_format_context_->streams[i]->codec->extradata); av_freep(&ffmpeg_format_context_->streams[i]->codec); av_freep(&ffmpeg_format_context_->streams[i]); }*/ avformat_free_context(ffmpeg_format_context_); } // av_free(ffmpeg_src_picture_->data[0]); if (ffmpeg_src_picture_) av_free(ffmpeg_src_picture_); // av_free(ffmpeg_dst_picture_->data[0]); if (ffmpeg_dst_picture_) av_free(ffmpeg_dst_picture_); if (ffmpeg_sws_ctx_) sws_freeContext(ffmpeg_sws_ctx_); init_ = false; } }
int CAudioMuxer::WriteFileDataImpl() { AVCodecContext *c = m_pAudioStream->codec; AVPacket pkt = { 0 }; // data and size must be 0; AVFrame *frame = avcodec_alloc_frame(); int nGotPacket; av_init_packet(&pkt); frame->nb_samples = m_nFrameSize; avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, m_pSamples, m_nBufSize, 1); avcodec_encode_audio2(c, &pkt, frame, &nGotPacket); if (!nGotPacket) { return E_FAIL; } pkt.stream_index = m_pAudioStream->index; /* Write the compressed frame to the media file. */ if (av_interleaved_write_frame(m_pCtx, &pkt) != 0) { Log("Error while writing audio frame\n"); return E_FAIL; } avcodec_free_frame(&frame); return S_OK; }
LibavStreamer::~LibavStreamer() { if (codec_context_) avcodec_close(codec_context_); if (frame_) { #if (LIBAVCODEC_VERSION_MAJOR < 54) av_free(frame_); frame_ = NULL; #else avcodec_free_frame(&frame_); #endif } if (format_context_) avformat_free_context(format_context_); if (picture_) { avpicture_free(picture_); delete picture_; picture_ = NULL; } if (tmp_picture_) { delete tmp_picture_; tmp_picture_ = NULL; } if (sws_context_) sws_freeContext(sws_context_); }
QByteArray AVDecoder::getThumbnail(int &width, int &height) { QByteArray data; if(!loadCodec(CODEC_VIDEO)) { return data; } AVFrame *pFrame = getDecodedFrame(pCodecCtx, stream_index); if(pFrame != NULL) { calculate_thumbnail_dimensions(pCodecCtx->width, pCodecCtx->height, pCodecCtx->sample_aspect_ratio.num, pCodecCtx->sample_aspect_ratio.den, width, height); data = WriteJPEG(pCodecCtx, pFrame, width, height); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) av_frame_free(&pFrame); #else avcodec_free_frame(&pFrame); #endif } return data; }
static void uninit(sh_audio_t *sh) { sh->codecname = NULL; struct priv *ctx = sh->context; if (!ctx) return; AVCodecContext *lavc_context = ctx->avctx; if (lavc_context) { if (avcodec_close(lavc_context) < 0) mp_tmsg(MSGT_DECVIDEO, MSGL_ERR, "Could not close codec.\n"); av_freep(&lavc_context->extradata); av_freep(&lavc_context); } #ifdef CONFIG_LIBAVRESAMPLE avresample_free(&ctx->avr); #endif #if LIBAVCODEC_VERSION_INT >= (54 << 16 | 28 << 8) avcodec_free_frame(&ctx->avframe); #else av_free(ctx->avframe); #endif talloc_free(ctx); sh->context = NULL; }
AVFormatWriter::~AVFormatWriter() { QMutexLocker locker(avcodeclock); if (m_ctx) { (void)av_write_trailer(m_ctx); avio_closep(&m_ctx->pb); for(unsigned int i = 0; i < m_ctx->nb_streams; i++) { av_freep(&m_ctx->streams[i]); } av_freep(&m_ctx); } if (m_audioInBuf) av_freep(&m_audioInBuf); if (m_audioInPBuf) av_freep(&m_audioInPBuf); if (m_audPicture) avcodec_free_frame(&m_audPicture); Cleanup(); av_frame_free(&m_picture); }
/* * Wrapper functions for FFMPEG API which * allows to compile and use exteplayer3 * with old ffmpeg libs */ static void wrapped_frame_free(void *param) { #if (LIBAVCODEC_VERSION_MAJOR >= 55) av_frame_free(param); #else avcodec_free_frame(param); #endif }
Decoder::~Decoder() { if (frame) avcodec_free_frame(&frame); if (codec_context) { avcodec_close(codec_context); av_free(codec_context); } }
int AudioDecoder::closeDecoder(){ if (aDecoderContext_!=NULL){ avcodec_close(aDecoderContext_); } if (dFrame_!=NULL){ avcodec_free_frame(&dFrame_); } return 0; }
AVFrameWrapper::~AVFrameWrapper() { #if SSR_USE_AV_FRAME_FREE av_frame_free(&m_frame); #elif SSR_USE_AVCODEC_FREE_FRAME avcodec_free_frame(&m_frame); #else av_free(m_frame); #endif }
void MediaConverter::uninitializeInput() { if (NULL != mInputFramePtr) { //av_free(mInputFramePtr); avcodec_free_frame(&mInputFramePtr); mInputFramePtr = NULL; } }
int Pixel_to_JPG(const unsigned char *pixelBuff, int pixelSize, int pixelFmt, int pixelWidth, int pixelHeight, unsigned char *jpgBuff, int *jpgSize) { AVFormatContext *formatContext; AVOutputFormat *outputFormat; AVIOContext *ioContext; AVStream *stream; AVCodecContext *codecContext; AVCodec *codec; AVFrame *frame; AVPacket packet; int ioRet; int codecRet; int gotPacket; int pixelSizeMin; int result = -1; av_register_all(); formatContext = avformat_alloc_context(); outputFormat = av_guess_format("mjpeg", NULL, NULL); ioContext = avio_alloc_context(jpgBuff, *jpgSize, 0, NULL, NULL, NULL, NULL); formatContext->oformat = outputFormat; formatContext->pb = ioContext; stream = av_new_stream(formatContext, 0); codecContext = stream->codec; codecContext->codec_id = outputFormat->video_codec; codecContext->codec_type = AVMEDIA_TYPE_VIDEO; codecContext->pix_fmt = (enum AVPixelFormat)PF(pixelFmt); codecContext->width = pixelWidth; codecContext->height = pixelHeight; codecContext->time_base.num = 1; codecContext->time_base.den = 25; codec = avcodec_find_encoder(codecContext->codec_id); avcodec_open2(codecContext, codec, NULL); avformat_write_header(formatContext, NULL); pixelSizeMin = avpicture_get_size(codecContext->pix_fmt, codecContext->width, codecContext->height); if (pixelSizeMin <= pixelSize) { av_new_packet(&packet, pixelSizeMin); frame = avcodec_alloc_frame(); avpicture_fill((AVPicture *)frame, pixelBuff, codecContext->pix_fmt, codecContext->width, codecContext->height); codecRet = avcodec_encode_video2(codecContext, &packet, frame, &gotPacket); if (0 <= codecRet && 1 == gotPacket) { av_write_frame(formatContext, &packet); if (packet.size <= *jpgSize) { *jpgSize = packet.size; result = *jpgSize; } } avcodec_free_frame(&frame); av_free_packet(&packet); } av_write_trailer(formatContext); av_free(ioContext); avcodec_close(codecContext); avformat_free_context(formatContext); return result; }
int AudioEncoder::closeEncoder (){ if (aCoderContext_!=NULL){ avcodec_close(aCoderContext_); } if (aFrame_!=NULL){ avcodec_free_frame(&aFrame_); } return 0; }
int TFFmpegVideoDecoder::Free(FF_VIDEO_FRAME *frame) { int ret = FF_OK; if (frame->frame) avcodec_free_frame(&frame->frame); if (frame->buffer) av_free(frame->buffer); return ret; }
static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp) { void *outbuffer = NULL; int success = 0; AVFrame *pic = NULL; struct AVCodec *codec = avcodec_find_encoder(ctx->writer->lavc_codec); AVCodecContext *avctx = NULL; if (!codec) goto print_open_fail; avctx = avcodec_alloc_context3(codec); if (!avctx) goto print_open_fail; avctx->time_base = AV_TIME_BASE_Q; avctx->width = image->w; avctx->height = image->h; avctx->pix_fmt = imgfmt2pixfmt(image->imgfmt); if (ctx->writer->lavc_codec == CODEC_ID_PNG) avctx->compression_level = ctx->opts->png_compression; if (avcodec_open2(avctx, codec, NULL) < 0) { print_open_fail: mp_msg(MSGT_CPLAYER, MSGL_INFO, "Could not open libavcodec encoder" " for saving images\n"); goto error_exit; } size_t outbuffer_size = image->w * image->h * 3 * 2; outbuffer = malloc(outbuffer_size); if (!outbuffer) goto error_exit; pic = avcodec_alloc_frame(); if (!pic) goto error_exit; avcodec_get_frame_defaults(pic); for (int n = 0; n < 4; n++) { pic->data[n] = image->planes[n]; pic->linesize[n] = image->stride[n]; } int size = avcodec_encode_video(avctx, outbuffer, outbuffer_size, pic); if (size < 1) goto error_exit; fwrite(outbuffer, size, 1, fp); success = 1; error_exit: if (avctx) avcodec_close(avctx); av_free(avctx); avcodec_free_frame(&pic); free(outbuffer); return success; }
static int write_lavc(struct image_writer_ctx *ctx, mp_image_t *image, FILE *fp) { int success = 0; AVFrame *pic = NULL; AVPacket pkt = {0}; int got_output = 0; av_init_packet(&pkt); struct AVCodec *codec = avcodec_find_encoder(ctx->writer->lavc_codec); AVCodecContext *avctx = NULL; if (!codec) goto print_open_fail; avctx = avcodec_alloc_context3(codec); if (!avctx) goto print_open_fail; avctx->time_base = AV_TIME_BASE_Q; avctx->width = image->w; avctx->height = image->h; avctx->pix_fmt = imgfmt2pixfmt(image->imgfmt); if (ctx->writer->lavc_codec == AV_CODEC_ID_PNG) { avctx->compression_level = ctx->opts->png_compression; avctx->prediction_method = ctx->opts->png_filter; } if (avcodec_open2(avctx, codec, NULL) < 0) { print_open_fail: mp_msg(MSGT_CPLAYER, MSGL_INFO, "Could not open libavcodec encoder" " for saving images\n"); goto error_exit; } pic = avcodec_alloc_frame(); if (!pic) goto error_exit; avcodec_get_frame_defaults(pic); for (int n = 0; n < 4; n++) { pic->data[n] = image->planes[n]; pic->linesize[n] = image->stride[n]; } int ret = avcodec_encode_video2(avctx, &pkt, pic, &got_output); if (ret < 0) goto error_exit; fwrite(pkt.data, pkt.size, 1, fp); success = !!got_output; error_exit: if (avctx) avcodec_close(avctx); av_free(avctx); avcodec_free_frame(&pic); av_free_packet(&pkt); return success; }
Encoder::~Encoder() { if (frame) { av_freep(&frame->data[0]); avcodec_free_frame(&frame); } if (codec_context) { avcodec_close(codec_context); av_free(codec_context); } }