简体   繁体   中英

input parameters for av_read_frame() method

I want to read and open a video in encoded domain without decoding. I have written the code up to now and it works without errors. But the output of the method av_read_frame() just gives number of zeros and same negative integer value is repeating. I'm not sure whether I passed the parameters correctly to the method. Please help.

void CFfmpegmethods::VideoRead(){
av_register_all();

    const char *url = "H:\\Sanduni_projects\\ad_1.mp4";
    AVDictionary *options = NULL;
    AVFormatContext *s = avformat_alloc_context(); //NULL;
    //AVFormatContext *avfmt = NULL;
    //avformat_alloc_context();

    AVPacket pkt;

    //AVFormatContext *avformat_alloc_context();
    //AVIOContext *avio_alloc_context();

    //open an input stream and read the header
    int ret = avformat_open_input(&s, url, NULL, NULL); 

    //avformat_find_stream_info(s, &options); //finding the missing information 

    if (ret < 0)
        abort();

    av_dict_set(&options, "video_size", "640x480", 0);
    av_dict_set(&options, "pixel_format", "rgb24", 0);

    if (avformat_open_input(&s, url, NULL, &options) < 0){
        abort();
    }

    av_dict_free(&options);

    AVDictionaryEntry *e;

    if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
        fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key);
        abort();
    }
    //int i = 0;
    while (1){
        //Split what is stored in the file into frames and return one for each call
        //returns the next frame of the stream
        int frame = av_read_frame(s, &pkt);
        //cout <<i << " " << frame << endl;
        waitKey(30);
        //i++;
    }

    //make the packet free
    av_packet_unref(&pkt);

    //Close the file after reading
    avformat_close_input(&s);

}

Method av_read_frame() output zeros while reading the packets and after that gives negative values. In my code loop runs infinitely. Therefore gives infinite number of negative values.

This is the modified code

while (1){
            //Split what is stored in the file into frames and return one for each call
            //returns the next frame of the stream
            int frame = av_read_frame(s, pkt);

        duration = pkt->duration;
        size = pkt->size;

        total_size = total_size + size;
        total_duration = total_duration + duration;

        i++;
        if (frame < 0) break;

        cout << "frame" << i << " " << size << " "<< duration << endl;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM