[Ffmpeg-devel] turn ffmpeg.exe into library help!

Jaime inf220
Sat Dec 2 16:26:24 CET 2006


Hi,
i just wanted to turn the ffmpeg.exe code into a dynamic library (using 
the MingGW setup in windows) and changed only the part of the code to 
export the main(int, char **) just as is.(using latest rev 7204)
so you get a library which accepts command line parameters as well.

So far it works quite good. all functions are alright.
Except for one thing:
ffmpeg.exe seem not to clean after itself well.
when i try to call the main() more than once the second time will crash 
the whole program.
It crashes just after attempting to read the input.

It seems ffmpeg does not deallocate all of the static variables it 
allocated during the process. Well its not to blame for an executable 
application.
To fix this i wrote a "reseter" function which basically attempts to 
clean and deallocate all variables i declared at the beginning.
So far the program still crashes.
since ffmpeg is quite large i am not sure as what else to deallocate... 
could anybody help me on this?

here my reseter function sofar. It is basically a copy of the 
declarations at the top of he file.
I call it at the beginning of the main() so it deallocates any variable 
used by the precedent call.(maybe i should put it at the end...)
I use av_freep() since the code advices me to do so... but i also tried 
using av_free()...

Thanks for any insight!





void resetDLL(void){
//AVFormatContext *input_files[MAX_FILES];
//int64_t input_files_ts_offset[MAX_FILES];
nb_input_files = 0;

//AVFormatContext *output_files[MAX_FILES];
nb_output_files = 0;

//AVStreamMap stream_maps[MAX_FILES];
nb_stream_maps;

//AVMetaDataMap meta_data_maps[MAX_FILES];
//nb_meta_data_maps;

if (file_iformat)
av_freep(file_iformat);


if (oformat)
av_freep(oformat);


frame_width  = 0;
frame_height = 0;
frame_aspect_ratio = 0;
//enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
frame_padtop  = 0;
frame_padbottom = 0;
frame_padleft  = 0;
frame_padright = 0;
//padcolor[3] = {16,128,128}; /* default to black */
frame_topBand  = 0;
frame_bottomBand = 0;
frame_leftBand  = 0;
frame_rightBand = 0;
max_frames[0] = INT_MAX;
max_frames[1] = INT_MAX;
max_frames[2] = INT_MAX;
max_frames[3] = INT_MAX;


frame_rate = 25;
frame_rate_base = 1;
video_qscale = 0;
video_qdiff = 3;

if (intra_matrix)
av_freep(intra_matrix);
if (inter_matrix)
av_freep(inter_matrix);


#if 0 //experimental, (can be removed)
video_rc_qsquish=1.0;
video_rc_qmod_amp=0;
video_rc_qmod_freq=0;
#endif
if (video_rc_override_string)
av_freep(video_rc_override_string);

video_rc_eq="tex^qComp";
me_method = ME_EPZS;
video_disable = 0;
video_discard = 0;
video_codec_id = CODEC_ID_NONE;
video_codec_tag = 0;
same_quality = 0;
do_deinterlace = 0;
packet_size = 0;
strict = 0;
top_field_first = -1;
me_threshold = 0;
intra_dc_precision = 8;
loop_input = 0;
loop_output = AVFMT_NOOUTPUTLOOP;
qp_hist = 0;

intra_only = 0;
audio_sample_rate = 44100;
audio_bit_rate = 64000;
#define QSCALE_NONE -99999
audio_qscale = QSCALE_NONE;
audio_disable = 0;
audio_channels = 1;
audio_codec_id = CODEC_ID_NONE;
audio_codec_tag = 0;
if(audio_language)
	av_freep(audio_language);
subtitle_codec_id = CODEC_ID_NONE;

if(subtitle_language)
	av_freep(subtitle_language);

mux_preload= 0.5;
mux_max_delay= 0.7;

  recording_time = 0;
start_time = 0;
rec_timestamp = 0;
input_ts_offset = 0;
file_overwrite = 0;
//char *str_title = NULL;
//char *str_author = NULL;
//char *str_copyright = NULL;
//char *str_comment = NULL;
//char *str_album = NULL;
do_benchmark = 0;
do_hex_dump = 0;
do_pkt_dump = 0;
do_psnr = 0;
do_vstats = 0;
do_pass = 0;
if (pass_logfilename)
	av_freep(pass_logfilename);

audio_stream_copy = 0;
video_stream_copy = 0;
subtitle_stream_copy = 0;
video_sync_method= 1;
audio_sync_method= 0;
copy_ts= 0;
opt_shortest = 0; //
video_global_header = 0;

rate_emu = 0;

#ifdef CONFIG_BKTR
//const char *video_grab_format = "bktr";
#else
#ifdef CONFIG_VIDEO4LINUX2
//const char *video_grab_format = "video4linux2";
#else
//const char *video_grab_format = "video4linux";
#endif
#endif
if(video_device)
	av_freep(video_device);
if (grab_device)
	av_freep(grab_device);

video_channel = 0;
video_standard = "ntsc";

audio_grab_format = "audio_device";

if (audio_device )
	av_frep(audio_device);

audio_volume = 256;

using_stdin = 0;
using_vhook = 0;
verbose = 1;
thread_count= 1;
q_pressed = 0;
video_size = 0;
  audio_size = 0;
  extra_size = 0;
nb_frames_dup = 0;
nb_frames_drop = 0;
input_sync;
limit_filesize = 0; //

pgmyuv_compatibility_hack=0;
dts_delta_threshold = 10;

sws_flags = SWS_BICUBIC;

if (opt_names)
	av_freep(opt_names);
opt_name_count=0;

if (avctx_opts)
	av_freep(avctx_opts);
if (avformat_opts)
	av_freep(avformat_opts);
if (video_bitstream_filters)
	av_freep(video_bitstream_filters);
if (audio_bitstream_filters)
	av_freep(audio_bitstream_filters);

//AVBitStreamFilterContext *bitstream_filters[MAX_FILES][MAX_STREAMS];
}




More information about the ffmpeg-devel mailing list