Hello everybody,

I want to cut and remux a transport stream recorded from a satellite receiver. 
The consists of an h.264 and an AC3 Stream. I develop my application under MAC 
OS 10.6 (Snow Leopard) with XCode and use the normal gcc-compiler.

My idea was to read at a key position via AVPacket the packets and give them to 
a new output stream. Here is the code:

-----------------------------------------> SNIP 
<-----------------------------------------
The "Muxer" part:
...
AVOutputFormat* outputFormat = guess_format("NULL", "test.ts", NULL);
AVFormatContext* formatContext = av_alloc_format_context();
if (!formatContext)
        return false;
formatContext->oformat = outputFormat;
        
// initializing Streams
m->videofile->VideoTrack->initOutputStream(formatContext, 
m->videofile->VideoTrack);
mlist_t* audiotracks = m->videofile->AudioTracks;
mlist_start(audiotracks);
while (audiotracks->current != NULL)
{
        tavtrack_t* at = (tavtrack_t*) audiotracks->current->element;
        at->initOutputStream(formatContext, at);
        mlist_inc(audiotracks);
}

// filename stuff
const char* filename = m->videofile->filename;
char outputFileName[255];
strcpy(outputFileName, filename);
strcpy(&outputFileName[strlen(filename)], "_svenali.ts");
snprintf(formatContext->filename, sizeof(formatContext->filename), "%s", 
outputFileName);
        
if (av_set_parameters(formatContext, NULL) < 0)
        return false;
        
dump_format(formatContext, 0, outputFileName, 1);
av_write_header(formatContext);
...
-----------------------------------------> SNAP 
<-----------------------------------------

The initOutputStream-function is a pointer at functions, which creating the 
AVStream-structure (shown in the following code). The following code shows the 
example of my video-configuration.

-----------------------------------------> SNIP 
<-----------------------------------------

void h264_initOutputStream(AVFormatContext* fc, tavtrack_t* track)
{
        track->streamContext = av_new_stream(fc, track->stream_idx);
        
        if (!track->streamContext)
        {
                return;
        }
        
        AVCodecContext* c = track->streamContext->codec;
        c->codec_id = track->codec_context->codec_id;
        c->codec_type = CODEC_TYPE_VIDEO;
        
        c->width = track->codec_context->width;
        c->height = track->codec_context->height;
        c->sample_aspect_ratio = track->codec_context->sample_aspect_ratio;
        
        c->time_base.den = track->codec_context->time_base.den;
        c->time_base.num = track->codec_context->time_base.num;
}
-----------------------------------------> SNAP 
<-----------------------------------------

Now the interesting part. I simply read packets, modifying the pts and dts 
values (shown in the next code) and get an Exception of EXC_ARITHMETIC. It 
seems a devide by zero-problem. But I don't know where it happens. 
-----------------------------------------> SNIP 
<-----------------------------------------
The "Muxer" part again:

do 
{
        av_read_frame(m->videofile->AVContext, &packet);
        av_dup_packet(&packet);

        if (packet.pts == stopIndex->KeyPTS)
                break;

        if (packet.pts != AV_NOPTS_VALUE)
        {
                packet.pts -= m->videofile->VideoTrack->pts_offset;
                packet.dts -= m->videofile->VideoTrack->dts_offset;
        }
                
        if (isVideoTrack(m, packet.stream_index) || isAudioTrack(m, 
packet.stream_index))
                av_interleaved_write_frame(formatContext, &packet);             
} while (true);
-----------------------------------------> SNAP 
<-----------------------------------------

Where is my problem? 

regards,
Sven
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to