[Libav-user] avcodec_send_packet speed

Ivan Lobanov iokunversion0 at gmail.com
Fri Mar 15 07:24:09 EET 2019


Yes video stream from my cameras decoded with H264.

Yu can see my connection code below

Few more questions:


   - What proper way to "share" videostream for example with my
recorder instead of adding packets in a loop?
   To implemend
   - *prerecord feature(*for motion detection record*)* should I use
AVFormatContext buffer or something else?
   - Also maybe somewhere to be some best practices of - *"record
video stream by time partitions"*


# # # # # # # # #

int CameraConnection::Connect(char *newVideoURI) {
    LOGD("Connect");
    AVCodec *streamCodec = nullptr; // *AV_CODEC_ID_H264*
    videoURI = newVideoURI;

    AVDictionary *inputOptionsDict = nullptr;
    av_dict_set(&inputOptionsDict, "rtsp_transport", "tcp", 0); //
working faster with TCP
    av_dict_set(&inputOptionsDict, "reorder_queue_size", "50", 0);
    av_dict_set(&inputOptionsDict, "buffer_size", buffer2sec, 0);
    if(avformat_open_input(&streamFormatContext, videoURI, nullptr,
&inputOptionsDict)!=0){
        LOGE("[%s] FAILED to open input", videoURI);
        return -1; // Couldn't open file
    }  // Open video file / RTSP

    if(avformat_find_stream_info(streamFormatContext, nullptr)<0){
        LOGE("[%s] FAILED to find stream info", videoURI);
        return -1; // Couldn't find stream information
    } // Retrieve stream information

    av_dump_format(streamFormatContext, 0, videoURI, 0); // Dump
information about file onto standard error

    videoStreamIdx = -1;
    audioStreamIdx = -1;
    int i;
    for(i=0; i<streamFormatContext->nb_streams; i++) { // Find the
first video stream
        AVMediaType codecType =
streamFormatContext->streams[i]->codecpar->codec_type;
        if(codecType == AVMEDIA_TYPE_VIDEO) {
            videoStreamIdx=i;
            break;
        }
        if(codecType == AVMEDIA_TYPE_AUDIO) {
            audioStreamIdx=i;
            break;
        }
    }

    if(videoStreamIdx==-1){
        LOGE("[%s] Didn't find a video stream", videoURI);
        return -1; // Didn't find a video stream
    }
    streamVideoCodecContext =
streamFormatContext->streams[videoStreamIdx]->codec; // Get a pointer
to the codec context for the video stream
    streamCodec =
avcodec_find_decoder(streamVideoCodecContext->codec_id); // Find the
decoder for the video stream
    if(streamCodec == nullptr) {
        LOGE("Unsupported codec");
        return -1; // Codec not found
    }

    if(avcodec_open2(streamVideoCodecContext, streamCodec, nullptr)<0){
        LOGE("Could not open codec");
        return -1; // Could not open codec
    }


    decodedFrame = av_frame_alloc(); // Allocate video frame
    if(decodedFrame == nullptr){
        LOGE("AVFrame could not be allocated 1");
        return -1;
    }

    isConnected = true;
    StartDecodeThread();
    return 0;
}


пт, 15 мар. 2019 г. в 04:31, Carl Eugen Hoyos <ceffmpeg at gmail.com>:

> 2019-03-14 14:26 GMT+01:00, Ivan Lobanov <iokunversion0 at gmail.com>:
> > I'm using libavcodec libreries for my android app.
> > To recive/decode/save/play RTSP video stream from cameras.
> > Everything work well but avcodec_send_packet() working a little bit slow
> > and cause video delay while try to play 1080p video stream.(no problem
> when
> > playing smaller video streams)
> > is there any way to speed up avcodec_send_packet() execution?
>
> You mean a decoder? Which one?
>
> The h264 decoder has seen recent speedups on arm64.
>
> Carl Eugen
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".



-- 
Best regards,
Lobanov Ivan
GDG Perm Leader
Red Distribution
Тел.: +7 961 759 89 71
Skype: ningen-des
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190315/7f804f49/attachment.html>


More information about the Libav-user mailing list