Hi Guys,

I'm working on the segmenter from Chase Douglas, because the File isn't exactly 
split at the key frame. It is split when the keyframe arrives - but there the 
audio packets for the video frames with a lower DTS residing in the 
packet_buffer haven't arrived, so there are always some p frames which normally 
belong to the last keyframe and which are in the new segment. Therefore I did 
some additions: Here is a source snippet:

    do {
        double segment_time;
        AVPacket packet;
        AVPacketList *liste;

        decode_done = av_read_frame(ic, &packet);
        if (decode_done < 0) {
            break;
        }

        if (av_dup_packet(&packet) < 0) {
            fprintf(stderr, "Could not duplicate packet");
            av_free_packet(&packet);
            break;
        }
                // Keyframe was found
        if (packet.stream_index == video_index && (packet.flags & 
PKT_FLAG_KEY)) {
            segment_time = (double)video_st->pts.val * video_st->time_base.num 
/ video_st->time_base.den;
            liste= oc->packet_buffer;
            keyDTS = packet.dts;
            while(liste != 0 && liste->next != 0){
                prevPackPos = liste->pkt.pos;
                liste = liste->next;
            }
        }
        else if (video_index < 0) {
            segment_time = (double)audio_st->pts.val * audio_st->time_base.num 
/ audio_st->time_base.den;
        }
        else {
            segment_time = prev_segment_time;
        }
        ret = av_interleaved_write_frame(oc, &packet);
        if (ret < 0) {
            fprintf(stderr, "Warning: Could not write frame of stream\n");
        }
        else if (ret > 0) {
            fprintf(stderr, "End of stream requested\n");
            av_free_packet(&packet);
            break;
        }
        av_free_packet(&packet);

        if (segment_time - prev_segment_time >= segment_duration) {
            char *puff;
            int size=0;

                        // The following loop reads the all frames into the 
packet_buffer until the last element in the packet Buffer is the Key frame
            do{
                AVPacket pack1;
                decode_done = av_read_frame(ic, &pack1);
                if (decode_done < 0) {
                    break;
                }

                if (av_dup_packet(&pack1) < 0) {
                    fprintf(stderr, "Could not duplicate packet");
                    av_free_packet(&packet);
                    break;
                }
                    ret = av_interleaved_write_frame(oc, &pack1);
                if (ret < 0) {
                    fprintf(stderr, "Warning: Could not write frame of 
stream\n");
                }
                else if (ret > 0) {
                    fprintf(stderr, "End of stream requested\n");
                    av_free_packet(&pack1);
                    break;
                }    
                    size = pack1.size;
                    av_free_packet(&pack1);
            }while(oc->packet_buffer->pkt.dts < keyDTS );

                        put_flush_packet(oc->pb);
            url_fclose(oc->pb);
            snprintf(output_filename, strlen(output_prefix) + 15, "%s-%u.ts", 
output_prefix, output_index++);
            if (url_fopen(&oc->pb, output_filename, URL_WRONLY) < 0) {
                fprintf(stderr, "Could not open '%s'\n", output_filename);
                break;
            }
            prev_segment_time = segment_time;
        }


    } while (!decode_done);


I'm currently having Problems starting at part 2 of the File. There only the 
audio Stream is recognized. (segmenting process doenst work properly) I Think 
the problem is the following: The last arriving packet before leaving the loop 
is a packet containing audio. Because the the DTS of this packet is greater 
than the "pre-key" video frame (The frame before the key frame residing in the 
packet_buffer) this frame is written. But then the IOBuffer is closed and with 
it the audio Data which at least partly belongs already to the keyframe. Do you 
have any idea what to do? I already triead get_buffer from the oc->pb - but i 
have no idea about how many bytes to copy.

Thanks in advance,

Peter
-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to