If someone cares:

there is a fine example at libavformat/output-example.c

plus now working little test program from me at
http://sdr.tera-com.com/tmp/sdrlive_src_good.tar.bz2

On Tue, Apr 27, 2010 at 10:52 AM, Simon Desfarges
<[email protected]> wrote:
>
>
> Le 27/04/2010 00:03, Stoian Ivanov a écrit :
>>
>>   Hi All,
>>  I'm writing a video file splitter but I cant create a valid output
>> context. I get SIGSEGV at dump_format. What am I doing wrong? Is there
>> a simple tutorial to follow?
>>
>>
>> I use this (shortened) code:
>>
>>
>> AVStream *new_video_stream(AVFormatContext *oc,AVCodecContext *icc);
>> AVStream *new_audio_stream(AVFormatContext *oc,AVCodecContext *icc);
>> void copy_stream_params(AVFormatContext *oc, AVStream *ost, AVStream
>> *ist);
>> ......
>> ......
>> ......
>> //======== output file
>>
>>        #define OUTFILE "testout.avi"
>>        AVFormatContext *oc;
>>        AVStream *ovs=NULL,*oas=NULL;
>>
>>        oc = avformat_alloc_context();
>>
>>        AVOutputFormat *file_oformat;
>>        file_oformat = av_guess_format(NULL, OUTFILE, NULL);
>>
>>        oc->oformat=file_oformat;
>>        strncpy(oc->filename, OUTFILE, sizeof(oc->filename)-1);
>>
>>        ovs=new_video_stream(oc,pVCodecCtx);
>>        oas=new_audio_stream(oc,pACodecCtx);
>>
>>        iurl_fopen(&oc->pb, OUTFILE, URL_WRONLY) ;
>>
>>        copy_stream_params(oc,ovs,ic->streams[ivsi]);
>>        copy_stream_params(oc,oas,ic->streams[iasi]);
>>
>>        av_write_header(oc);
>>        dump_format(oc, 0, OUTFILE, 0);
>> .......
>> .......
>> .......
>> //this functions are based on ffmpeg.c
>> AVStream *new_video_stream(AVFormatContext *oc,AVCodecContext *icc)
>> {
>>        AVStream *st;
>>        AVCodecContext *video_enc;
>>
>>        st = av_new_stream(oc, oc->nb_streams);
>>        if (!st) {
>>                printf("N: new_video_stream(): Could not alloc stream\n");
>>                return NULL;
>>        }
>>        avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
>>
>>
>>        //SDR:this will not be needed?!
>>        //avcodec_thread_init(st->codec, 1);
>>
>>        video_enc = st->codec;
>>
>>        video_enc->codec_tag= icc->codec_tag;
>>        if (((icc->flags&&  CODEC_FLAG_GLOBAL_HEADER) ==
>> CODEC_FLAG_GLOBAL_HEADER ) || (oc->oformat->flags&
>> AVFMT_GLOBALHEADER)){
>>                video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
>>        }
>> /*
>>        if ((icc->flags2&&  CODEC_FLAG_GLOBAL_HEADER) ==
>> CODEC_FLAG_GLOBAL_HEADER ) {
>>                video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
>>        }*/
>>
>>
>>        st->stream_copy = 1;
>>        video_enc->codec_type = CODEC_TYPE_VIDEO;
>>        video_enc->sample_aspect_ratio = st->sample_aspect_ratio =
>> icc->sample_aspect_ratio;
>>
>>     return st;
>> }
>>
>>
>> AVStream *new_audio_stream(AVFormatContext *oc,AVCodecContext *icc)
>> {
>>        AVStream *st;
>>        AVCodecContext *audio_enc;
>>
>>        st = av_new_stream(oc, oc->nb_streams);
>>        if (!st) {
>>                printf("N: new_video_stream(): Could not alloc stream\n");
>>                return NULL;
>>        }
>>
>>        avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
>>
>>
>>        //SDR: do we need this?
>>        //avcodec_thread_init(st->codec, 1);
>>
>>        audio_enc = st->codec;
>>        audio_enc->codec_type = CODEC_TYPE_AUDIO;
>>
>>        audio_enc->codec_tag= icc->codec_tag;
>>
>>        if ((oc->oformat->flags&  AVFMT_GLOBALHEADER) || ((icc->flags&&
>> CODEC_FLAG_GLOBAL_HEADER)==CODEC_FLAG_GLOBAL_HEADER)) audio_enc->flags
>> |= CODEC_FLAG_GLOBAL_HEADER;
>>
>>
>>        st->stream_copy = 1;
>>        audio_enc->channels = icc->channels;
>>
>>        audio_enc->sample_rate = icc->sample_rate;
>>        audio_enc->time_base= icc->time_base;
>>        return st;
>> }
>>
>> void copy_stream_params(AVFormatContext *oc, AVStream *ost, AVStream
>> *ist){
>>
>>        AVCodecContext *codec = ost->codec;
>>        AVCodecContext *icodec = ist->codec;
>>
>>        ost->disposition = ist->disposition;
>>        codec->bits_per_raw_sample= icodec->bits_per_raw_sample;
>>        codec->chroma_sample_location = icodec->chroma_sample_location;
>>
>>        codec->codec_id = icodec->codec_id;
>>        codec->codec_type = icodec->codec_type;
>>
>>        codec->codec_tag = icodec->codec_tag;
>>
>>
>>        codec->bit_rate = icodec->bit_rate;
>>        codec->extradata= icodec->extradata;
>>        codec->extradata_size= icodec->extradata_size;
>>
>>        codec->time_base = ist->time_base;
>>
>>
>>        switch(codec->codec_type) {
>>                case CODEC_TYPE_AUDIO:
>>                        codec->channel_layout = icodec->channel_layout;
>>                        codec->sample_rate = icodec->sample_rate;
>>                        codec->channels = icodec->channels;
>>                        codec->frame_size = icodec->frame_size;
>>                        codec->block_align= icodec->block_align;
>>                        if(codec->block_align == 1&&  codec->codec_id ==
>> CODEC_ID_MP3)
>>                                codec->block_align= 0;
>>                        if(codec->codec_id == CODEC_ID_AC3)
>>                                codec->block_align= 0;
>>                        break;
>>                case CODEC_TYPE_VIDEO:
>>                        codec->pix_fmt = icodec->pix_fmt;
>>                        codec->width = icodec->width;
>>                        codec->height = icodec->height;
>>                        codec->has_b_frames = icodec->has_b_frames;
>>                        break;
>>                case CODEC_TYPE_SUBTITLE:
>>                        codec->width = icodec->width;
>>                        codec->height = icodec->height;
>>                        break;
>>                default:
>>                        ;
>>        }
>> }
>> _______________________________________________
>> libav-user mailing list
>> [email protected]
>> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
> Hi,
>
> you need to use :
>        dump_format(oc, 0, OUTFILE, 1);
>
> 1 is for dumping outfiles and 0 is for input files.
>
> regards,
>
> --
> Simon Desfarges
> Research Engineer
>
> LaBRI - COMET
> 351 Cours de la Libération,
> 33405 Talence Cedex, FRANCE
> Tel : +33 (0)5 56 84 23 87
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to