gavl_overlay_t * bg_ov_create_overlay(bg_ov_t * ov, int id) { gavl_overlay_t * ret; if(!(ov->flags & FLAG_EMULATE_OVL)) { LOCK(ov); ret = ov->plugin->create_overlay(ov->priv, id); UNLOCK(ov); return ret; } else { ret = gavl_video_frame_create(&ov->ovl_str[id].format); gavl_video_frame_clear(ret, &ov->ovl_str[id].format); return ret; } }
static void alloc_frames(gavl_video_converter_t * cnv) { gavl_video_convert_context_t * tmp_ctx; if(cnv->have_frames) return; tmp_ctx = cnv->first_context; while(tmp_ctx && tmp_ctx->next) { tmp_ctx->output_frame = gavl_video_frame_create(&tmp_ctx->output_format); gavl_video_frame_clear(tmp_ctx->output_frame, &tmp_ctx->output_format); tmp_ctx->next->input_frame = tmp_ctx->output_frame; tmp_ctx = tmp_ctx->next; } cnv->have_frames = 1; }
static char * save_image(bg_db_t * db, gavl_video_frame_t * in_frame, gavl_video_format_t * in_format, gavl_video_format_t * out_format, gavl_video_converter_t * cnv, int64_t id, const char * mimetype) { int result = 0; int do_convert; gavl_video_frame_t * output_frame = NULL; bg_image_writer_plugin_t * output_plugin; bg_plugin_handle_t * output_handle = NULL; const bg_plugin_info_t * plugin_info; iw_t iw; bg_iw_callbacks_t cb; char * out_file_base = bg_sprintf("gmerlin-db/thumbnails/%016"PRId64, id); out_file_base = bg_db_filename_to_abs(db, out_file_base); memset(&iw, 0, sizeof(iw)); memset(&cb, 0, sizeof(cb)); cb.create_output_file = create_file; cb.data = &iw; out_format->pixel_width = 1; out_format->pixel_height = 1; out_format->interlace_mode = GAVL_INTERLACE_NONE; out_format->frame_width = out_format->image_width; out_format->frame_height = out_format->image_height; plugin_info = bg_plugin_find_by_mimetype(db->plugin_reg, mimetype, BG_PLUGIN_IMAGE_WRITER); if(!plugin_info) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "No plugin for %s", mimetype); goto end; } output_handle = bg_plugin_load(db->plugin_reg, plugin_info); if(!output_handle) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Loading %s failed", plugin_info->long_name); goto end; } output_plugin = (bg_image_writer_plugin_t*)output_handle->plugin; output_plugin->set_callbacks(output_handle->priv, &cb); if(!output_plugin->write_header(output_handle->priv, out_file_base, out_format, NULL)) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Writing image header failed"); goto end; } /* Initialize video converter */ do_convert = gavl_video_converter_init(cnv, in_format, out_format); if(do_convert) { output_frame = gavl_video_frame_create(out_format); gavl_video_frame_clear(output_frame, out_format); gavl_video_convert(cnv, in_frame, output_frame); if(!output_plugin->write_image(output_handle->priv, output_frame)) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Writing image failed"); goto end; } } else { if(!output_plugin->write_image(output_handle->priv, in_frame)) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Writing image failed"); goto end; } } result = 1; end: if(output_frame) gavl_video_frame_destroy(output_frame); if(output_handle) bg_plugin_unref(output_handle); if(out_file_base) free(out_file_base); if(result) return iw.filename; if(iw.filename) free(iw.filename); return NULL; }
bool ReadMedia::initFormat() { const gavl_audio_format_t * open_audio_format; const gavl_video_format_t * open_video_format; // we use the m_vfifosize to see if the user app wants video or not // then, we set m_video_stream_count to 0 if he doesn't want video if (m_video_stream_count > 0 && m_vfifosize > 0) { open_video_format = bgav_get_video_format(m_file, 0); if (open_video_format->pixelformat == GAVL_PIXELFORMAT_NONE) { printf("!!!sorry, pixelformat is not recognized.\n"); return false; } // let's check to see if the formats are the same, if they are the same // there is no reason to recreate the fifo or frames if ( gavl_video_formats_equal( &m_video_format, open_video_format) == 0 ) { // the formats are different gavl_video_format_copy (&m_video_format, open_video_format); if (m_video_frame != NULL) gavl_video_frame_destroy(m_video_frame); m_video_frame = gavl_video_frame_create(&m_video_format); gavl_video_frame_clear( m_video_frame, &m_video_format); if (m_fifovideo != NULL) delete m_fifovideo; m_fifovideo= new FifoVideoFrames( m_vfifosize , &m_video_format); } } else { m_video_stream_count = 0; m_veof = true; } // we use the m_afifosize to see if the user app wants audio or not // then, we set m_audio_stream_count to 0 if he doesn't want audio if (m_audio_stream_count > 0 && m_afifosize > 0) { open_audio_format = bgav_get_audio_format(m_file, 0); // we can get audio formats that are unkown if ( open_audio_format->sample_format == GAVL_SAMPLE_NONE) { printf("sorry, this file has unsupported audio.\n"); return false; } if ( gavl_audio_formats_equal(&m_audio_format, open_audio_format) == 0 ) { // audio formats are different // save the old spf int spf = m_audio_format.samples_per_frame; gavl_audio_format_copy(&m_audio_format, open_audio_format); if (m_audio_frame != NULL) { gavl_audio_frame_destroy(m_audio_frame); } // set it back to original m_audio_format.samples_per_frame = spf ; m_audio_frame = gavl_audio_frame_create(&m_audio_format); gavl_audio_frame_mute( m_audio_frame, &m_audio_format); if( m_fifoaudio != NULL ) delete m_fifoaudio; m_fifoaudio = new FifoAudioFrames( m_afifosize , &m_audio_format); } } else { // user doesn't want audio m_audio_stream_count = 0; m_aeof=true; } m_length_in_gavltime = bgav_get_duration ( m_file, 0);; m_length_in_seconds = gavl_time_to_seconds( m_length_in_gavltime ); m_num_samples = 0; m_num_frames = 0; if (m_audio_stream_count) { if ( bgav_can_seek_sample(m_file) == 1 ) { m_num_samples= bgav_audio_duration ( m_file, 0) ; } else { m_num_samples= gavl_time_to_samples( m_audio_format.samplerate , bgav_get_duration ( m_file, 0) ); } } // set frames WE NEED TO take care here for non-constant frame-rates if(m_video_stream_count) { if ( bgav_can_seek_sample(m_file) == 1 && m_video_format.framerate_mode == GAVL_FRAMERATE_CONSTANT) { m_num_frames = bgav_video_duration ( m_file, 0)/ m_video_format.frame_duration; } else if ( bgav_can_seek_sample(m_file) == 1 && m_video_format.framerate_mode == GAVL_FRAMERATE_VARIABLE ) { // FIXME what to do with non constant frame rates? m_num_frames=0; } else { m_num_frames = gavl_time_to_frames( m_video_format.timescale, m_video_format.frame_duration , bgav_get_duration ( m_file, 0) ); } } // printf("m_num_frames =%lld, duration = %lld , vid_duration=%lld\n", // m_num_frames, bgav_get_duration ( m_file, 0), bgav_video_duration ( m_file, 0) ); // set seconds if ( bgav_can_seek_sample(m_file) == 1) { gavl_time_t atime=0,vtime=0; if ( m_audio_stream_count ) atime = gavl_samples_to_time( m_audio_format.samplerate, m_num_samples ); if (m_video_stream_count && m_video_format.frame_duration > 0) { vtime = gavl_frames_to_time( m_video_format.timescale, m_video_format.frame_duration, m_num_frames ); } else if ( m_video_stream_count ) { // non constant framerate vtime = bgav_video_duration( m_file, 0); } // else rely on audio time m_length_in_gavltime = atime > vtime ? atime :vtime; m_length_in_seconds = gavl_time_to_seconds( m_length_in_gavltime ); //printf("atime=%ld, vtime=%ld, l_in_sec=%f\n", atime, vtime, m_length_in_seconds); } m_pcm_seek = SEEK_NOTHING; m_frame_seek = SEEK_NOTHING; return true; }