Recherche avancée

Médias (1)

Mot : - Tags -/bug

Autres articles (87)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

Sur d’autres sites (9894)

  • Problems in my sample C code using FFmpeg API

    11 juillet 2019, par Tina J

    I’ve been trying to change an FFmpeg’s example code HERE to call other filters using its C APIs. Say the filter be freezedetect=n=-60dB:d=8 which normally runs like this :

    ffmpeg -i small.mp4 -vf "freezedetect=n=-60dB:d=8" -map 0:v:0 -f null -

    And prints outputs like this :

    [freezedetect @ 0x25b91c0] lavfi.freezedetect.freeze_start: 5.005
    [freezedetect @ 0x25b91c0] lavfi.freezedetect.freeze_duration: 2.03537
    [freezedetect @ 0x25b91c0] lavfi.freezedetect.freeze_end: 7.04037

    However, the original example displays frames, not these metadata information. How can I change the code to print this metadata information (and not the frames) ?

    I’ve been trying to change the display_frame function below into a display_metadata function. Looks like the frame variable has a metadata dictionary which looks promising, but my attempts failed to use it. I’m also new to C language.

    Original display_frame function :

    static void display_frame(const AVFrame *frame, AVRational time_base)
    {
       int x, y;
       uint8_t *p0, *p;
       int64_t delay;

       if (frame->pts != AV_NOPTS_VALUE) {
           if (last_pts != AV_NOPTS_VALUE) {
               /* sleep roughly the right amount of time;
                * usleep is in microseconds, just like AV_TIME_BASE. */
               delay = av_rescale_q(frame->pts - last_pts,
                                    time_base, AV_TIME_BASE_Q);
               if (delay > 0 && delay < 1000000)
                   usleep(delay);
           }
           last_pts = frame->pts;
       }

       /* Trivial ASCII grayscale display. */
       p0 = frame->data[0];
       puts("\033c");
       for (y = 0; y < frame->height; y++) {
           p = p0;
           for (x = 0; x < frame->width; x++)
               putchar(" .-+#"[*(p++) / 52]);
           putchar('\n');
           p0 += frame->linesize[0];
       }
       fflush(stdout);
    }

    My new display_metadata function that needs to be completed :

    static void display_metadata(const AVFrame *frame)
    {

    //    printf("%d\n",frame->height);

       AVDictionary* dic = frame->metadata;

       printf("%d\n",*(dic->count));

    //    fflush(stdout);
    }
  • FFmpeg wrong output duration after av_seek_frame

    18 septembre 2022, par Gogogo

    I try to transcode a video and also cut it, but in the output file, I get the wrong duration for the file(video duration is correct). It happens when I seek the video, as an example, if I try cut from 60000 to 63000 ms I will get :
Format : WebM
Format version : Version 2
File size : 17.6 KiB
Duration : 1 min 4 s
Overall bit rate : 2 232 b/s
Writing application : Lavf59.31.100
Writing library : Lavf59.31.100

    


    Video
ID : 1
Format : VP9
Codec ID : V_VP9
Duration : 2 s 961 ms
Width : 100 pixels
Height : 100 pixels
Display aspect ratio : 1.000
Frame rate mode : Constant
Frame rate : 24.000 FPS
Default : No
Forced : No

    


    Here is my code, what I am doing wrong ?

    


     namespace {&#xA;    &#xA;    constexpr auto maxDurationMs = 3000;&#xA;    constexpr auto maxFileSizeByte = 100000;&#xA;    &#xA;    struct StreamingParams {&#xA;      std::string output_extension;&#xA;      std::string muxer_opt_key;&#xA;      std::string muxer_opt_value;&#xA;      std::string video_codec;&#xA;      std::string codec_priv_key;&#xA;      std::string codec_priv_value;&#xA;    };&#xA;    &#xA;    struct StreamingContext {&#xA;      AVFormatContext* avfc = nullptr;&#xA;      AVCodec* video_avc = nullptr;&#xA;      AVStream* video_avs = nullptr;&#xA;      AVCodecContext* video_avcc = nullptr;&#xA;      int video_index = 0;&#xA;      std::string filename;&#xA;      ~StreamingContext() {}&#xA;    };&#xA;    &#xA;    struct StreamingContextDeleter {&#xA;      void operator()(StreamingContext* context) {&#xA;        if (context) {&#xA;          auto* avfc = &amp;context->avfc;&#xA;          auto* avcc = &amp;context->video_avcc;&#xA;          if (avfc)&#xA;            avformat_close_input(avfc);&#xA;          if (avcc)&#xA;            avcodec_free_context(avcc);&#xA;          if (context->avfc)&#xA;            avformat_free_context(context->avfc);&#xA;        }&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVFrameDeleter {&#xA;      void operator()(AVFrame* frame) {&#xA;        if (frame)&#xA;          av_frame_free(&amp;frame);&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVPacketDeleter {&#xA;      void operator()(AVPacket* packet) {&#xA;        if (packet)&#xA;          av_packet_free(&amp;packet);&#xA;      }&#xA;    };&#xA;    &#xA;    struct SwsContextDeleter {&#xA;      void operator()(SwsContext* context) {&#xA;        if (context)&#xA;          sws_freeContext(context);&#xA;      }&#xA;    };&#xA;    &#xA;    struct AVDictionaryDeleter {&#xA;      void operator()(AVDictionary* dictionary) {&#xA;        if (dictionary)&#xA;          av_dict_free(&amp;dictionary);&#xA;      }&#xA;    };&#xA;    &#xA;    int fill_stream_info(AVStream* avs, AVCodec** avc, AVCodecContext** avcc) {&#xA;      *avc = const_cast(avcodec_find_decoder(avs->codecpar->codec_id));&#xA;      if (!*avc) return -1;&#xA;&#xA;      *avcc = avcodec_alloc_context3(*avc);&#xA;      if (!*avcc)  return -1;&#xA;      if (avcodec_parameters_to_context(*avcc, avs->codecpar) &lt; 0) return -1;&#xA;      if (avcodec_open2(*avcc, *avc, nullptr) &lt; 0) return -1;&#xA;&#xA;      return 0;&#xA;    }&#xA;    &#xA;    int open_media(const char* in_filename, AVFormatContext** avfc) {&#xA;      *avfc = avformat_alloc_context();&#xA;      if (!*avfc) return -1;&#xA;      if (avformat_open_input(avfc, in_filename, nullptr, nullptr) != 0) return -1;&#xA;      if (avformat_find_stream_info(*avfc, nullptr) &lt; 0) return -1;&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int prepare_decoder(std::shared_ptr<streamingcontext> sc) {&#xA;      for (int i = 0; i &lt; sc->avfc->nb_streams; i&#x2B;&#x2B;) {&#xA;        if (sc->avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;          sc->video_avs = sc->avfc->streams[i];&#xA;          sc->video_index = i;&#xA;    &#xA;          if (fill_stream_info(sc->video_avs, &amp;sc->video_avc, &amp;sc->video_avcc)) return -1;&#xA;        }&#xA;      }&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int prepare_video_encoder(std::shared_ptr<streamingcontext> sc,&#xA;                              AVCodecContext* decoder_ctx,&#xA;                              AVRational input_framerate,&#xA;                              const StreamingParams&amp; sp) {&#xA;      sc->video_avs = avformat_new_stream(sc->avfc, nullptr);&#xA;    &#xA;      sc->video_avc = const_cast(&#xA;          avcodec_find_encoder_by_name(sp.video_codec.c_str()));&#xA;      if (!sc->video_avc) return -1;&#xA;    &#xA;      sc->video_avcc = avcodec_alloc_context3(sc->video_avc);&#xA;      if (!sc->video_avcc) return -1;&#xA;    &#xA;      av_opt_set(sc->video_avcc->priv_data, "preset", "fast", 0);&#xA;&#xA;      sc->video_avcc->height = 100;&#xA;      sc->video_avcc->width = 100;&#xA;      sc->video_avcc->sample_aspect_ratio = decoder_ctx->sample_aspect_ratio;&#xA;      if (sc->video_avc->pix_fmts)&#xA;        sc->video_avcc->pix_fmt = sc->video_avc->pix_fmts[0];&#xA;      else&#xA;        sc->video_avcc->pix_fmt = decoder_ctx->pix_fmt;&#xA;    &#xA;      constexpr int64_t maxBitrate = maxFileSizeByte / (maxDurationMs / 1000.0) - 1;&#xA;    &#xA;      sc->video_avcc->bit_rate = maxBitrate;&#xA;      sc->video_avcc->rc_buffer_size = decoder_ctx->rc_buffer_size;&#xA;      sc->video_avcc->rc_max_rate = maxBitrate;&#xA;      sc->video_avcc->rc_min_rate = maxBitrate;&#xA;      sc->video_avcc->time_base = av_inv_q(input_framerate);&#xA;      sc->video_avs->time_base = sc->video_avcc->time_base;&#xA;    &#xA;      if (avcodec_open2(sc->video_avcc, sc->video_avc, nullptr) &lt; 0) return -1;&#xA;      avcodec_parameters_from_context(sc->video_avs->codecpar, sc->video_avcc);&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    int encode_video(std::shared_ptr<streamingcontext> decoder,&#xA;                     std::shared_ptr<streamingcontext> encoder,&#xA;                     AVFrame* input_frame) {&#xA;      if (input_frame)&#xA;        input_frame->pict_type = AV_PICTURE_TYPE_NONE;&#xA;    &#xA;      AVPacket* output_packet = av_packet_alloc();&#xA;      if (!output_packet) return -1;&#xA;    &#xA;      int response = avcodec_send_frame(encoder->video_avcc, input_frame);&#xA;    &#xA;      while (response >= 0) {&#xA;        response = avcodec_receive_packet(encoder->video_avcc, output_packet);&#xA;        if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {&#xA;          break;&#xA;        } else if (response &lt; 0) return -1;&#xA;    &#xA;        output_packet->stream_index = decoder->video_index;&#xA;        output_packet->duration = encoder->video_avs->time_base.den /&#xA;                                  encoder->video_avs->time_base.num /&#xA;                                  decoder->video_avs->avg_frame_rate.num *&#xA;                                  decoder->video_avs->avg_frame_rate.den;&#xA;    &#xA;        av_packet_rescale_ts(output_packet, decoder->video_avs->time_base,&#xA;                             encoder->video_avs->time_base);&#xA;    &#xA;        response = av_interleaved_write_frame(encoder->avfc, output_packet);&#xA;        if (response != 0) return -1;&#xA;      }&#xA;      av_packet_unref(output_packet);&#xA;      av_packet_free(&amp;output_packet);&#xA;      return 0;&#xA;    }&#xA;    &#xA;    int transcode_video(std::shared_ptr<streamingcontext> decoder,&#xA;                        std::shared_ptr<streamingcontext> encoder,&#xA;                        AVPacket* input_packet,&#xA;                        AVFrame* input_frame) {&#xA;      int response = avcodec_send_packet(decoder->video_avcc, input_packet);&#xA;      if (response &lt; 0) return response;&#xA;&#xA;    &#xA;      while (response >= 0) {&#xA;        response = avcodec_receive_frame(decoder->video_avcc, input_frame);&#xA;        if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {&#xA;          break;&#xA;        } else if (response &lt; 0) return response;&#xA;    &#xA;        if (response >= 0) {&#xA;          if (encode_video(decoder, encoder, input_frame)) return -1;&#xA;        }&#xA;        av_frame_unref(input_frame);&#xA;      }&#xA;    &#xA;      return 0;&#xA;    }&#xA;    &#xA;    }  // namespace&#xA;    &#xA;    &#xA;    int VideoToGifConverter::convert(VideoProp input, QString output) {&#xA;      StreamingParams sp;&#xA;      sp.output_extension = ".webm";&#xA;      sp.video_codec = "libvpx-vp9";&#xA;    &#xA;      auto inputStd = input.path.toStdString();&#xA;      auto outputStd =&#xA;          (output &#x2B; &#x27;/&#x27; &#x2B; QUuid::createUuid().toString(QUuid::StringFormat::Id128))&#xA;              .toStdString() &#x2B;&#xA;          sp.output_extension;&#xA;    &#xA;      auto decoder = std::shared_ptr<streamingcontext>(new StreamingContext,&#xA;                                                       StreamingContextDeleter{});&#xA;      auto encoder = std::shared_ptr<streamingcontext>(new StreamingContext,&#xA;                                                       StreamingContextDeleter{});&#xA;    &#xA;      encoder->filename = std::move(outputStd);&#xA;      decoder->filename = std::move(inputStd);&#xA;    &#xA;      if (open_media(decoder->filename.c_str(), &amp;decoder->avfc))&#xA;        return -1;&#xA;      if (prepare_decoder(decoder))&#xA;        return -1;&#xA;    &#xA;      avformat_alloc_output_context2(&amp;encoder->avfc, nullptr, nullptr,&#xA;                                     encoder->filename.c_str());&#xA;      if (!encoder->avfc) return -1;&#xA;    &#xA;      AVRational input_framerate =&#xA;          av_guess_frame_rate(decoder->avfc, decoder->video_avs, nullptr);&#xA;      prepare_video_encoder(encoder, decoder->video_avcc, input_framerate, sp);&#xA;    &#xA;      if (encoder->avfc->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;        encoder->avfc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;      if (!(encoder->avfc->oformat->flags &amp; AVFMT_NOFILE)) {&#xA;        if (avio_open(&amp;encoder->avfc->pb, encoder->filename.c_str(),&#xA;                      AVIO_FLAG_WRITE) &lt; 0) return -1;&#xA;      }&#xA;    &#xA;      AVDictionary* muxer_opts = nullptr;&#xA;    &#xA;      if (!sp.muxer_opt_key.empty() &amp;&amp; !sp.muxer_opt_value.empty()) {&#xA;        av_dict_set(&amp;muxer_opts, sp.muxer_opt_key.c_str(),&#xA;                    sp.muxer_opt_value.c_str(), 0);&#xA;      }&#xA;    &#xA;      if (avformat_write_header(encoder->avfc, &amp;muxer_opts) &lt; 0) return -1;&#xA;    &#xA;      auto inputFrame = std::unique_ptr(av_frame_alloc());&#xA;      if (!inputFrame) return -1;&#xA;    &#xA;      auto inputPacket =&#xA;          std::unique_ptr(av_packet_alloc());&#xA;      if (!inputPacket) return -1;&#xA;    &#xA;      auto** streams = decoder->avfc->streams;&#xA;    &#xA;      const auto fps = static_cast<double>(&#xA;                           streams[inputPacket->stream_index]->avg_frame_rate.num) /&#xA;                       streams[inputPacket->stream_index]->avg_frame_rate.den;&#xA;      const size_t beginFrame = input.beginPosMs * fps / 1000;&#xA;      const size_t endFrame = input.endPosMs * fps / 1000;&#xA;      const auto totalFrames = endFrame - beginFrame;&#xA;    &#xA;      size_t count = 0;&#xA;    &#xA;      int64_t startTime =&#xA;          av_rescale_q(input.beginPosMs * AV_TIME_BASE / 1000, {1, AV_TIME_BASE},&#xA;                       decoder->video_avs->time_base);&#xA;    &#xA;      av_seek_frame(decoder->avfc, inputPacket->stream_index, startTime, 0);&#xA;      avcodec_flush_buffers(decoder->video_avcc);&#xA;    &#xA;      while (count &lt; totalFrames &amp;&amp;&#xA;             av_read_frame(decoder->avfc, inputPacket.get()) >= 0) {&#xA;        if (streams[inputPacket->stream_index]->codecpar->codec_type ==&#xA;            AVMEDIA_TYPE_VIDEO) {&#xA;          if (transcode_video(decoder, encoder, inputPacket.get(), inputFrame.get())) {&#xA;            return -1;&#xA;          }&#xA;          &#x2B;&#x2B;count;&#xA;        }&#xA;        av_packet_unref(inputPacket.get());&#xA;      }&#xA;    &#xA;      if (encode_video(decoder, encoder, nullptr, nullptr)) return -1;&#xA;        &#xA;      av_write_trailer(encoder->avfc);&#xA;    &#xA;      return 0;&#xA;    }&#xA;</double></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext></streamingcontext>

    &#xA;

  • Qt - H.264 video streaming using FFmpeg libraries

    9 juillet 2021, par franz

    I am trying to get my IP camera stream in my Qt Widget application. First, I connect to UDP port of IP camera. IP camera is streaming H.264 encoded video. After socket is bound, on each readyRead() signal, I am filling the buffer with received datagrams in order to get a full frame.

    &#xA;

    Variable initialization :

    &#xA;

    AVCodec *codec;&#xA;AVCodecContext *codecCtx;&#xA;AVFrame *frame;&#xA;AVPacket packet;&#xA;this->buffer.clear();&#xA;this->socket = new QUdpSocket(this);&#xA;&#xA;QObject::connect(this->socket, &amp;QUdpSocket::connected, this, &amp;H264VideoStreamer::connected);&#xA;QObject::connect(this->socket, &amp;QUdpSocket::disconnected, this, &amp;H264VideoStreamer::disconnected);&#xA;QObject::connect(this->socket, &amp;QUdpSocket::readyRead, this, &amp;H264VideoStreamer::readyRead);&#xA;QObject::connect(this->socket, &amp;QUdpSocket::hostFound, this, &amp;H264VideoStreamer::hostFound);&#xA;QObject::connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));&#xA;QObject::connect(this->socket, &amp;QUdpSocket::stateChanged, this, &amp;H264VideoStreamer::stateChanged);&#xA;&#xA;avcodec_register_all();&#xA;&#xA;codec = avcodec_find_decoder(AV_CODEC_ID_H264);&#xA;if (!codec){&#xA;   qDebug() &lt;&lt; "Codec not found";&#xA;   return;&#xA;}&#xA;&#xA;codecCtx = avcodec_alloc_context3(codec);&#xA;if (!codecCtx){&#xA;    qDebug() &lt;&lt; "Could not allocate video codec context";&#xA;    return;&#xA;}&#xA;&#xA;if (codec->capabilities &amp; CODEC_CAP_TRUNCATED)&#xA;      codecCtx->flags |= CODEC_FLAG_TRUNCATED;&#xA;&#xA;codecCtx->flags2 |= CODEC_FLAG2_CHUNKS;&#xA;&#xA;AVDictionary *dictionary = nullptr;&#xA;&#xA;if (avcodec_open2(codecCtx, codec, &amp;dictionary) &lt; 0) {&#xA;    qDebug() &lt;&lt; "Could not open codec";&#xA;    return;&#xA;}&#xA;

    &#xA;

    Algorithm is as follows :

    &#xA;

    void H264VideoImageProvider::readyRead() {&#xA;    QByteArray datagram;&#xA;    datagram.resize(this->socket->pendingDatagramSize());&#xA;    QHostAddress sender;&#xA;    quint16 senderPort;&#xA;&#xA;    this->socket->readDatagram(datagram.data(), datagram.size(), &amp;sender, &amp;senderPort);&#xA;&#xA;    QByteArray rtpHeader = datagram.left(12);&#xA;    datagram.remove(0, 12);&#xA;&#xA;    int nal_unit_type = datagram[0] &amp; 0x1F;&#xA;    bool start = (datagram[1] &amp; 0x80) != 0;&#xA;&#xA;    int seqNo = rtpHeader[3] &amp; 0xFF;&#xA;&#xA;    qDebug() &lt;&lt; "H264 video decoder::readyRead()"&#xA;             &lt;&lt; "from: " &lt;&lt; sender.toString() &lt;&lt; ":" &lt;&lt; QString::number(senderPort)&#xA;             &lt;&lt; "\n\tDatagram size: " &lt;&lt; QString::number(datagram.size())&#xA;             &lt;&lt; "\n\tH264 RTP header (hex): " &lt;&lt; rtpHeader.toHex()&#xA;             &lt;&lt; "\n\tH264 VIDEO data (hex): " &lt;&lt; datagram.toHex();&#xA;&#xA;    qDebug() &lt;&lt; "nal_unit_type = " &lt;&lt; nal_unit_type &lt;&lt; " - " &lt;&lt; getNalUnitTypeStr(nal_unit_type);&#xA;    if (start)&#xA;        qDebug() &lt;&lt; "START";&#xA;&#xA;    if (nal_unit_type == 7){&#xA;        this->sps = datagram;&#xA;        qDebug() &lt;&lt; "Sequence parameter found = " &lt;&lt; this->sps.toHex();&#xA;        return;&#xA;    } else if (nal_unit_type == 8){&#xA;        this->pps = datagram;&#xA;        qDebug() &lt;&lt; "Picture parameter found = " &lt;&lt; this->pps.toHex();&#xA;        return;&#xA;    }&#xA;&#xA;    //VIDEO_FRAME&#xA;    if (start){&#xA;        if (!this->buffer.isEmpty())&#xA;            decodeBuf();&#xA;&#xA;        this->buffer.clear();&#xA;        qDebug() &lt;&lt; "Initializing new buffer...";&#xA;&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x01));&#xA;&#xA;        this->buffer.append(this->sps);&#xA;&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x01));&#xA;&#xA;        this->buffer.append(this->pps);&#xA;&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x00));&#xA;        this->buffer.append(char(0x01));&#xA;    }&#xA;&#xA;    qDebug() &lt;&lt; "Appending buffer data...";&#xA;    this->buffer.append(datagram);&#xA;}&#xA;

    &#xA;

      &#xA;
    • first 12 bytes of datagram is RTP header

      &#xA;

    • &#xA;

    • everything else is VIDEO DATA

      &#xA;

    • &#xA;

    • last 5 bits of first VIDEO DATA byte, says which NAL unit type it is. I always get one of the following 4 values (1 - coded non-IDR slice, 5 code IDR slice, 7 SPS, 8 PPS)

      &#xA;

    • &#xA;

    • 5th bit in 2nd VIDEO DATA byte says if this datagram is START data in frame

      &#xA;

    • &#xA;

    • all VIDEO DATA is stored in buffer starting with START

      &#xA;

    • &#xA;

    • once new frame arrives - START is set, it is decoded and new buffer is generated

      &#xA;

    • &#xA;

    • frame for decoding is generated like this :

      &#xA;

       00 00 00 01&#xA; SPS&#xA; 00 00 00 01&#xA; PPS&#xA; 00 00 00 01&#xA;

      &#xA;

      concatenated VIDEO DATA

      &#xA;

    • &#xA;

    • decoding is made using avcodec_decode_video2() function from FFmpeg library

      &#xA;

       void H264VideoStreamer::decode() {&#xA;     av_init_packet(&amp;packet);&#xA;     av_new_packet(&amp;packet, this->buffer.size());&#xA;     memcpy(packet.data, this->buffer.data_ptr(), this->buffer.size());&#xA;     packet.size = this->buffer.size();    &#xA;     frame = av_frame_alloc();&#xA;     if(!frame){&#xA;         qDebug() &lt;&lt; "Could not allocate video frame";&#xA;         return;&#xA;     }&#xA;     int got_frame = 1;&#xA;     int len = avcodec_decode_video2(codecCtx, frame, &amp;got_frame, &amp;packet);&#xA;     if (len &lt; 0){&#xA;         qDebug() &lt;&lt; "Error while encoding frame.";&#xA;         return;&#xA;     }&#xA;     //if(got_frame > 0){ // got_frame is always 0&#xA;     //    qDebug() &lt;&lt; "Data decoded: " &lt;&lt; frame->data[0];&#xA;     //}&#xA;     char * frameData = (char *) frame->data[0];&#xA;     QByteArray decodedFrame;&#xA;     decodedFrame.setRawData(frameData, len);&#xA;     qDebug() &lt;&lt; "Data decoded: " &lt;&lt; decodedFrame;&#xA;     av_frame_unref(frame);&#xA;     av_free_packet(&amp;packet);&#xA;     emit imageReceived(decodedFrame);&#xA; }&#xA;

      &#xA;

    • &#xA;

    &#xA;

    My idea is in UI thread which receives imageReceived signal, convert decodedFrame directly in QImage and refresh it once new frame is decoded and sent to UI.

    &#xA;

    Is this good approach for decoding H.264 stream ? I am facing following problems :

    &#xA;

      &#xA;
    • avcodec_decode_video2() returns value that is the same like encoded buffer size. Is it possible that encoded and decoded date are always same size ?
    • &#xA;

    • got_frame is always 0, so it means that I never really received full frame in the result. What can be the reason ? Video frame incorrectly created ? Or video frame incorrectly converted from QByteArray to AVframe ?
    • &#xA;

    • How can I convert decoded AVframe back to QByteArray, and can it just be simply converted to QImage ?
    • &#xA;

    &#xA;