Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (92)

  • Les formats acceptés

    28 janvier 2010, par

    Les commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
    ffmpeg -codecs ffmpeg -formats
    Les format videos acceptés en entrée
    Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
    Les formats vidéos de sortie possibles
    Dans un premier temps on (...)

  • Contribute to translation

    13 avril 2011

    You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
    To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
    MediaSPIP is currently available in French and English (...)

  • Keeping control of your media in your hands

    13 avril 2011, par

    The vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
    While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
    MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
    MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)

Sur d’autres sites (7059)

  • Resultant video stream unplayable

    29 novembre 2017, par Nikolai Linetskiy

    Currently I’m writing software for transcoding media files using ffmpeg libs. The problem is that in case of H264 QuickTime cannot play result stream and shows black screen. Audio streams work as expected. I have read that QuickTime can deal only with yuv420p pixel format and that is true for encoded video.

    I looked through the ffmpeg examples and ffmpeg source code and could not find anything find any clues where the problem might be. I would really appreciate any help.

    The only thing I managed to get from QuickTime is
    SeqAndPicParamSetFromCFDictionaryRef, bad config record message in console. Same thing is logged by AVPlayer from AVFoundation.

    Here is the initialization of output streams and encoders.

    int status;

    // avformat_alloc_output_context2()
    if ((status = formatContext.open(destFilename)) < 0) {
       return status;
    }

    AVDictionary *fmtOptions = nullptr;
    av_dict_set(&fmtOptions, "movflags", "faststart", 0);
    av_dict_set(&fmtOptions, "brand", "mp42", 0);

    streams.resize(input->getStreamsCount());
    for (int i = 0; i < input->getStreamsCount(); ++i) {
       AVStream *inputStream = input->getStreamAtIndex(i);
       CodecContext &decoderContext = input->getDecoderAtIndex(i);

       // retrieve output codec by codec id
       auto encoderCodecId = decoderContext.getCodecID();;
       if (decoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO || decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           int codecIdKey = decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO ? IPROC_KEY_INT(TargetAudioCodecID) : IPROC_KEY_INT(TargetVideoCodecID);
           auto codecIdParam = static_cast<avcodecid>(params[codecIdKey]);
           if (codecIdParam != AV_CODEC_ID_NONE) {
               encoderCodecId = codecIdParam;
           }
       }
       AVCodec *encoder = nullptr;
       if ((encoder = avcodec_find_encoder(encoderCodecId)) == nullptr) {
           status = AVERROR_ENCODER_NOT_FOUND;
           return status;
       }

       // create stream with specific codec and format
       AVStream *outputStream = nullptr;
       // avformat_new_stream()
       if ((outputStream = formatContext.newStream(encoder)) == nullptr) {
           return AVERROR(ENOMEM);
       }


       CodecContext encoderContext;
       // avcodec_alloc_context3()
       if ((status = encoderContext.init(encoder)) &lt; 0) {
           return status;
       }

       outputStream->disposition = inputStream->disposition;
       encoderContext.getRawCtx()->chroma_sample_location = decoderContext.getRawCtx()->chroma_sample_location;

       if (encoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           // prepare encoder context
           int targetWidth = params[IPROC_KEY_INT(TargetVideoWidth)];
           int targetHeight = params[IPROC_KEY_INT(TargetVideHeight)];



           encoderContext.width() = targetWidth > 0 ? targetWidth : decoderContext.width();
           encoderContext.height() = targetHeight > 0 ? targetHeight : decoderContext.height();
           encoderContext.pixelFormat() = encoder->pix_fmts ? encoder->pix_fmts[0] : decoderContext.pixelFormat();;
           encoderContext.timeBase() = decoderContext.timeBase();
           encoderContext.getRawCtx()->level = 31;
           encoderContext.getRawCtx()->gop_size = 25;

           double far = static_cast<double>(encoderContext.getRawCtx()->width) / encoderContext.getRawCtx()->height;
           double dar = static_cast<double>(decoderContext.width()) / decoderContext.height();
           encoderContext.sampleAspectRatio() = av_d2q(dar / far, 255);


           encoderContext.getRawCtx()->bits_per_raw_sample = FFMIN(decoderContext.getRawCtx()->bits_per_raw_sample,
                                                                   av_pix_fmt_desc_get(encoderContext.pixelFormat())->comp[0].depth);
           encoderContext.getRawCtx()->framerate = inputStream->r_frame_rate;
           outputStream->avg_frame_rate = encoderContext.getRawCtx()->framerate;

           VideoFilterGraphParameters params;
           params.height = encoderContext.height();
           params.width = encoderContext.width();
           params.pixelFormat = encoderContext.pixelFormat();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }

       } else if (encoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           encoderContext.sampleRate() = params[IPROC_KEY_INT(TargetAudioSampleRate)] ? : decoderContext.sampleRate();
           encoderContext.channels() = params[IPROC_KEY_INT(TargetAudioChannels)] ? : decoderContext.channels();
           auto paramChannelLayout = params[IPROC_KEY_INT(TargetAudioChannelLayout)];
           if (paramChannelLayout) {
               encoderContext.channelLayout() = paramChannelLayout;
           } else {
               encoderContext.channelLayout() = av_get_default_channel_layout(encoderContext.channels());
           }

           AVSampleFormat sampleFormatParam = static_cast<avsampleformat>(params[IPROC_KEY_INT(TargetAudioSampleFormat)]);
           if (sampleFormatParam != AV_SAMPLE_FMT_NONE) {
               encoderContext.sampleFormat() = sampleFormatParam;
           } else if (encoder->sample_fmts) {
               encoderContext.sampleFormat() = encoder->sample_fmts[0];
           } else {
               encoderContext.sampleFormat() = decoderContext.sampleFormat();
           }

           encoderContext.timeBase().num = 1;
           encoderContext.timeBase().den = encoderContext.sampleRate();

           AudioFilterGraphParameters params;
           params.channelLayout = encoderContext.channelLayout();
           params.channels = encoderContext.channels();
           params.format = encoderContext.sampleFormat();
           params.sampleRate = encoderContext.sampleRate();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }
       }

       // before using encoder, we should open it and update its parameters
       printf("Codec bits per sample %d\n", av_get_bits_per_sample(encoderCodecId));
       AVDictionary *options = nullptr;
       // avcodec_open2()
       if ((status = encoderContext.open(encoder, &amp;options)) &lt; 0) {
           return status;
       }
       if (streams[i].filterGraph) {
           streams[i].filterGraph.setOutputFrameSize(encoderContext.getFrameSize());
       }
       // avcodec_parameters_from_context()
       if ((status = encoderContext.fillParamters(outputStream->codecpar)) &lt; 0) {
           return status;
       }
       outputStream->codecpar->format = encoderContext.getRawCtx()->pix_fmt;

       if (formatContext.getRawCtx()->oformat->flags &amp; AVFMT_GLOBALHEADER) {
           encoderContext.getRawCtx()->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       if (encoderContext.getRawCtx()->nb_coded_side_data) {
           int i;

           for (i = 0; i &lt; encoderContext.getRawCtx()->nb_coded_side_data; i++) {
               const AVPacketSideData *sd_src = &amp;encoderContext.getRawCtx()->coded_side_data[i];
               uint8_t *dst_data;

               dst_data = av_stream_new_side_data(outputStream, sd_src->type, sd_src->size);
               if (!dst_data)
                   return AVERROR(ENOMEM);
               memcpy(dst_data, sd_src->data, sd_src->size);
           }
       }

       /*
        * Add global input side data. For now this is naive, and copies it
        * from the input stream's global side data. All side data should
        * really be funneled over AVFrame and libavfilter, then added back to
        * packet side data, and then potentially using the first packet for
        * global side data.
        */
       for (int i = 0; i &lt; inputStream->nb_side_data; i++) {
           AVPacketSideData *sd = &amp;inputStream->side_data[i];
           uint8_t *dst = av_stream_new_side_data(outputStream, sd->type, sd->size);
           if (!dst)
               return AVERROR(ENOMEM);
           memcpy(dst, sd->data, sd->size);
       }

       // copy timebase while removing common factors
       if (outputStream->time_base.num &lt;= 0 || outputStream->time_base.den &lt;= 0) {
           outputStream->time_base = av_add_q(encoderContext.timeBase(), (AVRational){0, 1});
       }

       // copy estimated duration as a hint to the muxer
       if (outputStream->duration &lt;= 0 &amp;&amp; inputStream->duration > 0) {
           outputStream->duration = av_rescale_q(inputStream->duration, inputStream->time_base, outputStream->time_base);
       }

       streams[i].codecType = encoderContext.getRawCtx()->codec_type;
       streams[i].codec = std::move(encoderContext);
       streams[i].streamIndex = i;
    }

    // avio_open() and avformat_write_header()
    if ((status = formatContext.writeHeader(fmtOptions)) &lt; 0) {
       return status;
    }

    formatContext.dumpFormat();
    </avsampleformat></double></double></avcodecid>

    Reading from stream.

    int InputProcessor::performStep() {
       int status;

       Packet nextPacket;
       if ((status = input->getFormatContext().readFrame(nextPacket)) &lt; 0) {
           return status;
       }
       ++streams[nextPacket.getStreamIndex()].readPackets;
       int streamIndex = nextPacket.getStreamIndex();
       CodecContext &amp;decoder = input->getDecoderAtIndex(streamIndex);
       AVStream *inputStream = input->getStreamAtIndex(streamIndex);

       if (streams[nextPacket.getStreamIndex()].readPackets == 1) {
           for (int i = 0; i &lt; inputStream->nb_side_data; ++i) {
               AVPacketSideData *src_sd = &amp;inputStream->side_data[i];
               uint8_t *dst_data;

               if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX) {
                   continue;
               }
               if (av_packet_get_side_data(nextPacket.getRawPtr(), src_sd->type, nullptr)) {
                   continue;
               }
               dst_data = av_packet_new_side_data(nextPacket.getRawPtr(), src_sd->type, src_sd->size);
               if (!dst_data) {
                   return AVERROR(ENOMEM);
               }
               memcpy(dst_data, src_sd->data, src_sd->size);
           }
       }

       nextPacket.rescaleTimestamps(inputStream->time_base, decoder.timeBase());

       status = decodePacket(&amp;nextPacket, nextPacket.getStreamIndex());
       if (status &lt; 0 &amp;&amp; status != AVERROR(EAGAIN)) {
           return status;
       }
       return 0;
    }

    Here is decoding/encoding code.

    int InputProcessor::decodePacket(Packet *packet, int streamIndex) {
       int status;
       int sendStatus;

       auto &amp;decoder = input->getDecoderAtIndex(streamIndex);

       do {
           if (packet == nullptr) {

               sendStatus = decoder.flushDecodedFrames();
           } else {
               sendStatus = decoder.sendPacket(*packet);
           }

           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return sendStatus;
           }
           if (sendStatus == 0 &amp;&amp; packet) {
               ++streams[streamIndex].decodedPackets;
           }

           Frame decodedFrame;
           while (true) {
               if ((status = decoder.receiveFrame(decodedFrame)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].decodedFrames;
               if ((status = filterAndWriteFrame(&amp;decodedFrame, streamIndex)) &lt; 0) {
                   break;
               }
               decodedFrame.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

    return status;
    }

    int InputProcessor::encodeAndWriteFrame(Frame *frame, int streamIndex) {
       assert(input->isValid());
       assert(formatContext);

       int status = 0;
       int sendStatus;

       Packet packet;

       CodecContext &amp;encoderContext = streams[streamIndex].codec;

       do {
           if (frame) {
               sendStatus = encoderContext.sendFrame(*frame);
           } else {
               sendStatus = encoderContext.flushEncodedPackets();
           }
           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return status;
           }
           if (sendStatus == 0 &amp;&amp; frame) {
               ++streams[streamIndex].encodedFrames;
           }

           while (true) {
               if ((status = encoderContext.receivePacket(packet)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].encodedPackets;
               packet.setStreamIndex(streamIndex);
               auto sourceTimebase = encoderContext.timeBase();
               auto dstTimebase = formatContext.getStreams()[streamIndex]->time_base;
               packet.rescaleTimestamps(sourceTimebase, dstTimebase);
               if ((status = formatContext.writeFrameInterleaved(packet)) &lt; 0) {
                   return status;
               }
               packet.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

       if (status != AVERROR(EAGAIN)) {
           return status;
       }

       return 0;
    }

    FFprobe output for original video.

    Input #0, matroska,webm, from 'testvideo':
     Metadata:
       title           : TestVideo
       encoder         : libebml v1.3.0 + libmatroska v1.4.0
       creation_time   : 2014-12-23T03:38:05.000000Z
     Duration: 00:02:29.25, start: 0.000000, bitrate: 79549 kb/s
       Stream #0:0(rus): Video: h264 (High 4:4:4 Predictive), yuv444p10le(pc, bt709, progressive), 2048x858 [SAR 1:1 DAR 1024:429], 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
       Stream #0:1(rus): Audio: pcm_s24le, 48000 Hz, 6 channels, s32 (24 bit), 6912 kb/s (default)

    Transcoded :

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '123.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf57.71.100
     Duration: 00:02:29.27, start: 0.000000, bitrate: 4282 kb/s
       Stream #0:0(rus): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 192:143 DAR 1024:429], 3940 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 96 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(rus): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 336 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
  • Transcoded video stream unplayable in QuickTime player

    30 novembre 2017, par Nikolai Linetskiy

    Currently I’m writing software for transcoding media files using ffmpeg libs. The problem is that in case of H264 QuickTime cannot play result stream and shows black screen. Audio streams work as expected. I have read that QuickTime can deal only with yuv420p pixel format and that is true for encoded video.

    I looked through the ffmpeg examples and ffmpeg source code and could not find anything find any clues where the problem might be. I would really appreciate any help.

    The only thing I managed to get from QuickTime is
    SeqAndPicParamSetFromCFDictionaryRef, bad config record message in console. Same thing is logged by AVPlayer from AVFoundation.

    Here is the initialization of output streams and encoders.

    int status;

    // avformat_alloc_output_context2()
    if ((status = formatContext.open(destFilename)) &lt; 0) {
       return status;
    }

    AVDictionary *fmtOptions = nullptr;
    av_dict_set(&amp;fmtOptions, "movflags", "faststart", 0);
    av_dict_set(&amp;fmtOptions, "brand", "mp42", 0);

    streams.resize(input->getStreamsCount());
    for (int i = 0; i &lt; input->getStreamsCount(); ++i) {
       AVStream *inputStream = input->getStreamAtIndex(i);
       CodecContext &amp;decoderContext = input->getDecoderAtIndex(i);

       // retrieve output codec by codec id
       auto encoderCodecId = decoderContext.getCodecID();;
       if (decoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO || decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           int codecIdKey = decoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO ? IPROC_KEY_INT(TargetAudioCodecID) : IPROC_KEY_INT(TargetVideoCodecID);
           auto codecIdParam = static_cast<avcodecid>(params[codecIdKey]);
           if (codecIdParam != AV_CODEC_ID_NONE) {
               encoderCodecId = codecIdParam;
           }
       }
       AVCodec *encoder = nullptr;
       if ((encoder = avcodec_find_encoder(encoderCodecId)) == nullptr) {
           status = AVERROR_ENCODER_NOT_FOUND;
           return status;
       }

       // create stream with specific codec and format
       AVStream *outputStream = nullptr;
       // avformat_new_stream()
       if ((outputStream = formatContext.newStream(encoder)) == nullptr) {
           return AVERROR(ENOMEM);
       }


       CodecContext encoderContext;
       // avcodec_alloc_context3()
       if ((status = encoderContext.init(encoder)) &lt; 0) {
           return status;
       }

       outputStream->disposition = inputStream->disposition;
       encoderContext.getRawCtx()->chroma_sample_location = decoderContext.getRawCtx()->chroma_sample_location;

       if (encoderContext.getCodecType() == AVMEDIA_TYPE_VIDEO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           // prepare encoder context
           int targetWidth = params[IPROC_KEY_INT(TargetVideoWidth)];
           int targetHeight = params[IPROC_KEY_INT(TargetVideHeight)];



           encoderContext.width() = targetWidth > 0 ? targetWidth : decoderContext.width();
           encoderContext.height() = targetHeight > 0 ? targetHeight : decoderContext.height();
           encoderContext.pixelFormat() = encoder->pix_fmts ? encoder->pix_fmts[0] : decoderContext.pixelFormat();;
           encoderContext.timeBase() = decoderContext.timeBase();
           encoderContext.getRawCtx()->level = 31;
           encoderContext.getRawCtx()->gop_size = 25;

           double far = static_cast<double>(encoderContext.getRawCtx()->width) / encoderContext.getRawCtx()->height;
           double dar = static_cast<double>(decoderContext.width()) / decoderContext.height();
           encoderContext.sampleAspectRatio() = av_d2q(dar / far, 255);


           encoderContext.getRawCtx()->bits_per_raw_sample = FFMIN(decoderContext.getRawCtx()->bits_per_raw_sample,
                                                                   av_pix_fmt_desc_get(encoderContext.pixelFormat())->comp[0].depth);
           encoderContext.getRawCtx()->framerate = inputStream->r_frame_rate;
           outputStream->avg_frame_rate = encoderContext.getRawCtx()->framerate;

           VideoFilterGraphParameters params;
           params.height = encoderContext.height();
           params.width = encoderContext.width();
           params.pixelFormat = encoderContext.pixelFormat();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }

       } else if (encoderContext.getCodecType() == AVMEDIA_TYPE_AUDIO) {
           auto lang = av_dict_get(input->getStreamAtIndex(i)->metadata, "language", nullptr, 0);
           if (lang) {
               av_dict_set(&amp;outputStream->metadata, "language", lang->value, 0);
           }

           encoderContext.sampleRate() = params[IPROC_KEY_INT(TargetAudioSampleRate)] ? : decoderContext.sampleRate();
           encoderContext.channels() = params[IPROC_KEY_INT(TargetAudioChannels)] ? : decoderContext.channels();
           auto paramChannelLayout = params[IPROC_KEY_INT(TargetAudioChannelLayout)];
           if (paramChannelLayout) {
               encoderContext.channelLayout() = paramChannelLayout;
           } else {
               encoderContext.channelLayout() = av_get_default_channel_layout(encoderContext.channels());
           }

           AVSampleFormat sampleFormatParam = static_cast<avsampleformat>(params[IPROC_KEY_INT(TargetAudioSampleFormat)]);
           if (sampleFormatParam != AV_SAMPLE_FMT_NONE) {
               encoderContext.sampleFormat() = sampleFormatParam;
           } else if (encoder->sample_fmts) {
               encoderContext.sampleFormat() = encoder->sample_fmts[0];
           } else {
               encoderContext.sampleFormat() = decoderContext.sampleFormat();
           }

           encoderContext.timeBase().num = 1;
           encoderContext.timeBase().den = encoderContext.sampleRate();

           AudioFilterGraphParameters params;
           params.channelLayout = encoderContext.channelLayout();
           params.channels = encoderContext.channels();
           params.format = encoderContext.sampleFormat();
           params.sampleRate = encoderContext.sampleRate();
           if ((status = generateGraph(decoderContext, encoderContext, params, streams[i].filterGraph)) &lt; 0) {
               return status;
           }
       }

       // before using encoder, we should open it and update its parameters
       printf("Codec bits per sample %d\n", av_get_bits_per_sample(encoderCodecId));
       AVDictionary *options = nullptr;
       // avcodec_open2()
       if ((status = encoderContext.open(encoder, &amp;options)) &lt; 0) {
           return status;
       }
       if (streams[i].filterGraph) {
           streams[i].filterGraph.setOutputFrameSize(encoderContext.getFrameSize());
       }
       // avcodec_parameters_from_context()
       if ((status = encoderContext.fillParamters(outputStream->codecpar)) &lt; 0) {
           return status;
       }
       outputStream->codecpar->format = encoderContext.getRawCtx()->pix_fmt;

       if (formatContext.getRawCtx()->oformat->flags &amp; AVFMT_GLOBALHEADER) {
           encoderContext.getRawCtx()->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       if (encoderContext.getRawCtx()->nb_coded_side_data) {
           int i;

           for (i = 0; i &lt; encoderContext.getRawCtx()->nb_coded_side_data; i++) {
               const AVPacketSideData *sd_src = &amp;encoderContext.getRawCtx()->coded_side_data[i];
               uint8_t *dst_data;

               dst_data = av_stream_new_side_data(outputStream, sd_src->type, sd_src->size);
               if (!dst_data)
                   return AVERROR(ENOMEM);
               memcpy(dst_data, sd_src->data, sd_src->size);
           }
       }

       /*
        * Add global input side data. For now this is naive, and copies it
        * from the input stream's global side data. All side data should
        * really be funneled over AVFrame and libavfilter, then added back to
        * packet side data, and then potentially using the first packet for
        * global side data.
        */
       for (int i = 0; i &lt; inputStream->nb_side_data; i++) {
           AVPacketSideData *sd = &amp;inputStream->side_data[i];
           uint8_t *dst = av_stream_new_side_data(outputStream, sd->type, sd->size);
           if (!dst)
               return AVERROR(ENOMEM);
           memcpy(dst, sd->data, sd->size);
       }

       // copy timebase while removing common factors
       if (outputStream->time_base.num &lt;= 0 || outputStream->time_base.den &lt;= 0) {
           outputStream->time_base = av_add_q(encoderContext.timeBase(), (AVRational){0, 1});
       }

       // copy estimated duration as a hint to the muxer
       if (outputStream->duration &lt;= 0 &amp;&amp; inputStream->duration > 0) {
           outputStream->duration = av_rescale_q(inputStream->duration, inputStream->time_base, outputStream->time_base);
       }

       streams[i].codecType = encoderContext.getRawCtx()->codec_type;
       streams[i].codec = std::move(encoderContext);
       streams[i].streamIndex = i;
    }

    // avio_open() and avformat_write_header()
    if ((status = formatContext.writeHeader(fmtOptions)) &lt; 0) {
       return status;
    }

    formatContext.dumpFormat();
    </avsampleformat></double></double></avcodecid>

    Reading from stream.

    int InputProcessor::performStep() {
       int status;

       Packet nextPacket;
       if ((status = input->getFormatContext().readFrame(nextPacket)) &lt; 0) {
           return status;
       }
       ++streams[nextPacket.getStreamIndex()].readPackets;
       int streamIndex = nextPacket.getStreamIndex();
       CodecContext &amp;decoder = input->getDecoderAtIndex(streamIndex);
       AVStream *inputStream = input->getStreamAtIndex(streamIndex);

       if (streams[nextPacket.getStreamIndex()].readPackets == 1) {
           for (int i = 0; i &lt; inputStream->nb_side_data; ++i) {
               AVPacketSideData *src_sd = &amp;inputStream->side_data[i];
               uint8_t *dst_data;

               if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX) {
                   continue;
               }
               if (av_packet_get_side_data(nextPacket.getRawPtr(), src_sd->type, nullptr)) {
                   continue;
               }
               dst_data = av_packet_new_side_data(nextPacket.getRawPtr(), src_sd->type, src_sd->size);
               if (!dst_data) {
                   return AVERROR(ENOMEM);
               }
               memcpy(dst_data, src_sd->data, src_sd->size);
           }
       }

       nextPacket.rescaleTimestamps(inputStream->time_base, decoder.timeBase());

       status = decodePacket(&amp;nextPacket, nextPacket.getStreamIndex());
       if (status &lt; 0 &amp;&amp; status != AVERROR(EAGAIN)) {
           return status;
       }
       return 0;
    }

    Here is decoding/encoding code.

    int InputProcessor::decodePacket(Packet *packet, int streamIndex) {
       int status;
       int sendStatus;

       auto &amp;decoder = input->getDecoderAtIndex(streamIndex);

       do {
           if (packet == nullptr) {

               sendStatus = decoder.flushDecodedFrames();
           } else {
               sendStatus = decoder.sendPacket(*packet);
           }

           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return sendStatus;
           }
           if (sendStatus == 0 &amp;&amp; packet) {
               ++streams[streamIndex].decodedPackets;
           }

           Frame decodedFrame;
           while (true) {
               if ((status = decoder.receiveFrame(decodedFrame)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].decodedFrames;
               if ((status = filterAndWriteFrame(&amp;decodedFrame, streamIndex)) &lt; 0) {
                   break;
               }
               decodedFrame.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

    return status;
    }

    int InputProcessor::encodeAndWriteFrame(Frame *frame, int streamIndex) {
       assert(input->isValid());
       assert(formatContext);

       int status = 0;
       int sendStatus;

       Packet packet;

       CodecContext &amp;encoderContext = streams[streamIndex].codec;

       do {
           if (frame) {
               sendStatus = encoderContext.sendFrame(*frame);
           } else {
               sendStatus = encoderContext.flushEncodedPackets();
           }
           if (sendStatus &lt; 0 &amp;&amp; sendStatus != AVERROR(EAGAIN) &amp;&amp; sendStatus != AVERROR_EOF) {
               return status;
           }
           if (sendStatus == 0 &amp;&amp; frame) {
               ++streams[streamIndex].encodedFrames;
           }

           while (true) {
               if ((status = encoderContext.receivePacket(packet)) &lt; 0) {
                   break;
               }
               ++streams[streamIndex].encodedPackets;
               packet.setStreamIndex(streamIndex);
               auto sourceTimebase = encoderContext.timeBase();
               auto dstTimebase = formatContext.getStreams()[streamIndex]->time_base;
               packet.rescaleTimestamps(sourceTimebase, dstTimebase);
               if ((status = formatContext.writeFrameInterleaved(packet)) &lt; 0) {
                   return status;
               }
               packet.unref();
           }
       } while (sendStatus == AVERROR(EAGAIN));

       if (status != AVERROR(EAGAIN)) {
           return status;
       }

       return 0;
    }

    FFprobe output for original video.

    Input #0, matroska,webm, from 'testvideo':
     Metadata:
       title           : TestVideo
       encoder         : libebml v1.3.0 + libmatroska v1.4.0
       creation_time   : 2014-12-23T03:38:05.000000Z
     Duration: 00:02:29.25, start: 0.000000, bitrate: 79549 kb/s
       Stream #0:0(rus): Video: h264 (High 4:4:4 Predictive), yuv444p10le(pc, bt709, progressive), 2048x858 [SAR 1:1 DAR 1024:429], 24 fps, 24 tbr, 1k tbn, 48 tbc (default)
       Stream #0:1(rus): Audio: pcm_s24le, 48000 Hz, 6 channels, s32 (24 bit), 6912 kb/s (default)

    Transcoded :

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '123.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf57.71.100
     Duration: 00:02:29.27, start: 0.000000, bitrate: 4282 kb/s
       Stream #0:0(rus): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 192:143 DAR 1024:429], 3940 kb/s, 24.01 fps, 24 tbr, 12288 tbn, 96 tbc (default)
       Metadata:
         handler_name    : VideoHandler
       Stream #0:1(rus): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 336 kb/s (default)
       Metadata:
         handler_name    : SoundHandler
  • Accessing RTSP Server hosted on AWS over internet

    27 juillet 2018, par Kishor V

    I am trying to access my EC2 Ubuntu instance from AWS using gaminganywhere (gaminganywhere.org). The security group policy is to allow all connections, but couldn’t connect to the server. Here is the log from the client and server.

    Client

    # [7860] 1522686205.894230 # include: config/common/controller.conf
    # [7860] 1522686205.894569 # include: config/common/video-x264.conf
    # [7860] 1522686205.894755 # include: config/common/audio-lame.conf
    # [7860] 1522686205.895002 # RTSP[config]: using 'udp' for RTP flows.
    # [7860] 1522686205.895012 # RTSP[config]: controller port = 8555
    # [7860] 1522686205.895016 # RTSP[config]: controller via 'udp' protocol.
    # [7860] 1522686205.895058 # RTSP[config]: video-encoder = libx264 (libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
    # [7860] 1522686205.895071 # RTSP[config]: audio-encoder = libmp3lame (libmp3lame MP3 (MPEG audio layer 3))
    # [7860] 1522686205.895101 # RTSP[config]: video specific option: threads = auto
    Remote server @ 18.188.161.135[18.188.161.135]:8554
    # [7860] 1522686205.971505 SDL: prefer opengl hardware renderer.
    # [7860] 1522686205.971532 controller queue: initialized size=32708 (481 units)
    # [7860] 1522686205.971693 controller socket: socket address [18.188.161.135:8555]
    # [7860] 1522686205.971727 controller client-thread started: tid=7863.
    watchdog: launched, waiting for audio/video frames ...
    # [7860] 1522686205.971813 rtspclient: max tolerable video delay disabled.
    *** SAVEFILE: YUV image saved to 'NULL'; timestamp saved to 'NULL'.
    RTP reordering threshold = 300000
    # [7860] 1522686205.971959 qos-measurement: initialized.
    Opening connection to 18.188.161.135, port 8554...
    ...remote connection opened
    Sending request: DESCRIBE rtsp://18.188.161.135:8554/desktop RTSP/1.0
    CSeq: 2
    User-Agent: RTSP Client (LIVE555 Streaming Media v2014.05.27)
    Accept: application/sdp


    Received 619 new bytes of response data.
    Received a complete DESCRIBE response:
    RTSP/1.0 200 OK
    CSeq: 2
    Date: Mon, Apr 02 2018 16:23:26 GMT
    Content-Base: rtsp://10.0.0.73:8554/desktop/
    Content-Type: application/sdp
    Content-Length: 456

    v=0
    o=- 1522685876960515 1 IN IP4 10.0.0.73
    s=GamingAnywhere Server
    i=desktop
    t=0 0
    a=tool:LIVE555 Streaming Media v2014.05.27
    a=type:broadcast
    a=control:*
    a=range:npt=0-
    a=x-qt-text-nam:GamingAnywhere Server
    a=x-qt-text-inf:desktop
    m=video 0 RTP/AVP 96
    c=IN IP4 0.0.0.0
    b=AS:3000
    a=rtpmap:96 H264/90000
    a=fmtp:96 packetization-mode=1;profile-level-id=4D4020;sprop-parameter-sets=Z01AILaAUAIGhAAAAwAEAAADAMI8YMqA,aO88gA==
    a=control:track1

    [URL:"rtsp://10.0.0.73:8554/desktop/"]: Got a SDP description:
    v=0
    o=- 1522685876960515 1 IN IP4 10.0.0.73
    s=GamingAnywhere Server
    i=desktop
    t=0 0
    a=tool:LIVE555 Streaming Media v2014.05.27
    a=type:broadcast
    a=control:*
    a=range:npt=0-
    a=x-qt-text-nam:GamingAnywhere Server
    a=x-qt-text-inf:desktop
    m=video 0 RTP/AVP 96
    c=IN IP4 0.0.0.0
    b=AS:3000
    a=rtpmap:96 H264/90000
    a=fmtp:96 packetization-mode=1;profile-level-id=4D4020;sprop-parameter-sets=Z01AILaAUAIGhAAAAwAEAAADAMI8YMqA,aO88gA==
    a=control:track1

    # [7860] 1522686206.581278 qos-measurement: source #0 added, prefix=-281002320
    video decoder: use decoder h264
    video decoder(0): sprop configured with 'Z01AILaAUAIGhAAAAwAEAAADAMI8YMqA,aO88gA==', decoded-size=36
    SPROP = [ 00 00 00 01 67 4d 40 20 b6 80 50 02 06 84 00 00 03 00 04 00 00 03 00 c2 3c 60 ca 80 00 00 00 01 68 ef 3c 80 ]
    video decoder(0): codec h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
    video decoder(0) initialized (client port 44578)
    [URL:"rtsp://10.0.0.73:8554/desktop/"]: Initiated the "video/H264" subsession (client ports 44578-44579)
    Sending request: SETUP rtsp://10.0.0.73:8554/desktop/track1 RTSP/1.0
    CSeq: 3
    User-Agent: RTSP Client (LIVE555 Streaming Media v2014.05.27)
    Transport: RTP/AVP;unicast;client_port=44578-44579


    Received 212 new bytes of response data.
    Received a complete SETUP response:
    RTSP/1.0 200 OK
    CSeq: 3
    Date: Mon, Apr 02 2018 16:23:26 GMT
    Transport: RTP/AVP;unicast;destination=117.206.20.30;source=10.0.0.73;client_port=44578-44579;server_port=6970-6971
    Session: CBA2E074;timeout=65


    [URL:"rtsp://10.0.0.73:8554/desktop/"]: Set up the "video/H264" subsession (client ports 44578-44579)
    [URL:"rtsp://10.0.0.73:8554/desktop/"]: Created a data sink for the "video/H264" subsession
    Receiver buffer increased to 2097152
    NAT hole punching: fd=11, local-port=44578/44578 server-port=6970
    Sending request: PLAY rtsp://10.0.0.73:8554/desktop/ RTSP/1.0
    CSeq: 4
    User-Agent: RTSP Client (LIVE555 Streaming Media v2014.05.27)
    Session: CBA2E074
    Range: npt=0.000-


    watchdog: initialized, but no frames received ...
    Received 184 new bytes of response data.
    Received a complete PLAY response:
    RTSP/1.0 200 OK
    CSeq: 4
    Date: Mon, Apr 02 2018 16:23:27 GMT
    Range: npt=0.000-
    Session: CBA2E074
    RTP-Info: url=rtsp://10.0.0.73:8554/desktop/track1;seq=32456;rtptime=2677630715


    [URL:"rtsp://10.0.0.73:8554/desktop/"]: Started playing session...
    watchdog: initialized, but no frames received ...
    watchdog: initialized, but no frames received ...
    watchdog: initialized, but no frames received ...
    watchdog: initialized, but no frames received ...
    watchdog: initialized, but no frames received ...
    watchdog: initialized, but no frames received ...

    Server

    # [4432] 1522685876.873593 # include: config/common/server-common.conf
    # [4432] 1522685876.873731 # include: config/common/controller.conf
    # [4432] 1522685876.873810 # include: config/common/video-x264.conf
    # [4432] 1522685876.873882 # include: config/common/video-x264-param.conf
    # [4432] 1522685876.873974 # include: config/common/audio-lame.conf
    # [4432] 1522685876.874060 # RTSP[config]: using 'udp' for RTP flows.
    # [4432] 1522685876.874100 # RTSP[config]: controller port = 8555
    # [4432] 1522685876.874131 # RTSP[config]: controller via 'udp' protocol.
    # [4432] 1522685876.874189 # RTSP[config]: video-encoder = libx264 (libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
    # [4432] 1522685876.874230 # RTSP[config]: audio-encoder = libmp3lame (libmp3lame MP3 (MPEG audio layer 3))
    # [4432] 1522685876.874281 # RTSP[config]: video specific option: b = 3000000
    # [4432] 1522685876.874316 # RTSP[config]: video specific option: g = 48
    # [4432] 1522685876.874348 # RTSP[config]: video specific option: intra-refresh = 1
    # [4432] 1522685876.874378 # RTSP[config]: video specific option: me_method = dia
    # [4432] 1522685876.874410 # RTSP[config]: video specific option: me_range = 16
    # [4432] 1522685876.874440 # RTSP[config]: video specific option: preset = faster
    # [4432] 1522685876.874471 # RTSP[config]: video specific option: profile = main
    # [4432] 1522685876.874501 # RTSP[config]: video specific option: refs = 1
    # [4432] 1522685876.874532 # RTSP[config]: video specific option: slices = 4
    # [4432] 1522685876.874563 # RTSP[config]: video specific option: threads = 4
    # [4432] 1522685876.874594 # RTSP[config]: video specific option: tune = zerolatency
    # [4432] 1522685876.874625 *** Crop disabled.
    # [4432] 1522685876.878908 sink server: live555-rtsp-server registered
    # [4432] 1522685876.878957 key-blocking initialized: 0+0 keys blocked.
    # [4432] 1522685876.879015 sdl_replayer: sizeof(sdlmsg) = 64
    # [4432] 1522685876.879465 sdl replayer: Replay using XTest (version 2.2) for display :0 screen 0, size=1280x1024.
    # [4432] 1522685876.879793 XShm extention version 1.2 with shared pixmaps
    # [4432] 1522685876.879832 X-Window-init: dimension: 1280x1024x8 @ 0/1
    # [4432] 1522685876.879917 dpipe: 'video-0' initialized, 8 frames, framesize = 16384092
    # [4432] 1522685876.913130 video-source: video-0 initialized max-curr-out = (2560x1600)-(1280x1024)-(1280x1024)
    # [4432] 1522685876.914241 Frame converter created: from (1280,1024)[30] -> (1280,1024)[0]
    # [4432] 1522685876.914343 dpipe: 'filter-0' initialized, 8 frames, framesize = 16384092
    # [4432] 1522685876.948463 video encoder: video source #0 from 'filter-0' (1280x1024).
    # [4432] 1522685876.948720 vencoder-init: option b = 3000000
    # [4432] 1522685876.948755 vencoder-init: option g = 48
    # [4432] 1522685876.948783 vencoder-init: option intra-refresh = 1
    # [4432] 1522685876.948811 vencoder-init: option me_method = dia
    # [4432] 1522685876.948839 vencoder-init: option me_range = 16
    # [4432] 1522685876.948867 vencoder-init: option preset = faster
    # [4432] 1522685876.948894 vencoder-init: option profile = main
    # [4432] 1522685876.948921 vencoder-init: option refs = 1
    # [4432] 1522685876.948949 vencoder-init: option slices = 4
    # [4432] 1522685876.948977 vencoder-init: option threads = 4
    # [4432] 1522685876.949004 vencoder-init: option tune = zerolatency
    [libx264 @ 0x9518b40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
    [libx264 @ 0x9518b40] profile Main, level 3.2
    [libx264 @ 0x9518b40] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=dia subme=4 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=1 keyint=48 keyint_min=4 scenecut=40 intra_refresh=1 rc=abr mbtree=0 bitrate=3000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    # [4432] 1522685876.958913 video encoder: initialized.
    # [4432] 1522685876.959008 video encoder: ffmpeg-video-encoder registered
    # [4432] 1522685876.959137 RGB2YUV filter[4443]: pipe#0 from 'video-0' to 'filter-0' (output-resolution=1280x1024)
    # [4432] 1522685876.959229 video source thread started: tid=4442
    # [4432] 1522685876.959290 controller socket: socket address [0.0.0.0:8555]
    # [4432] 1522685876.959337 controller server started: tid=4441.
    # [4432] 1522685876.960458 encoder: packet queue initialized (3x3145728 bytes)
    # [4432] 1522685876.960516 qos-measurement: initialized.
    # [4432] 1522685876.960587 (Use port 8000 for optional RTSP-over-HTTP tunneling.)
    # [4432] 1522685983.386797 video encdoer: all started (1)
    # [4432] 1522685983.386926 encoder client registered: total 1 clients.
    # [4432] 1522685983.386990 encoder: pktqueue #0 callback registered (0xf55a88a0)
    # [4432] 1522685983.387065 video encoder: h.264/found sps@4(24); pps@32(4)
    # [4432] 1522685983.387118 GAMediaSubsession: video/H264 SPS=0xdcfc346c(24); PPS=0xdcfc356c(4); profile_level_id=4d4020
    # [4432] 1522685983.387191 qos: add sink#1 for H.264, rtpsink=0xdc6061f8
    # [4432] 1522685983.387255 encoder client unregistered: 0 clients left.
    # [4432] 1522685983.387290 encoder: no more clients, quitting ...
    # [4432] 1522685983.387355 video encoding started: tid=4445 1280x1024@24fps, nalbuf_size=15828640, pic_in_size=1966080.
    # [4432] 1522685983.387402 video encoder: thread terminated (tid=4445).
    # [4432] 1522685983.387446 video encdoer: all stopped (1)
    [libx264 @ 0x9518b40] final ratefactor: 23.57
    # [4432] 1522685983.388265 video encoder: deinitialized.
    # [4432] 1522685983.741415 video encoder: video source #0 from 'filter-0' (1280x1024).
    # [4432] 1522685983.741772 vencoder-init: option b = 3000000
    # [4432] 1522685983.741819 vencoder-init: option g = 48
    # [4432] 1522685983.741870 vencoder-init: option intra-refresh = 1
    # [4432] 1522685983.741926 vencoder-init: option me_method = dia
    # [4432] 1522685983.741975 vencoder-init: option me_range = 16
    # [4432] 1522685983.742020 vencoder-init: option preset = faster
    # [4432] 1522685983.742086 vencoder-init: option profile = main
    # [4432] 1522685983.742123 vencoder-init: option refs = 1
    # [4432] 1522685983.742154 vencoder-init: option slices = 4
    # [4432] 1522685983.742188 vencoder-init: option threads = 4
    # [4432] 1522685983.742218 vencoder-init: option tune = zerolatency
    [libx264 @ 0xdc605f40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
    [libx264 @ 0xdc605f40] profile Main, level 3.2
    [libx264 @ 0xdc605f40] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=dia subme=4 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 slices=4 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=1 keyint=48 keyint_min=4 scenecut=40 intra_refresh=1 rc=abr mbtree=0 bitrate=3000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    # [4432] 1522685983.749123 video encoder: initialized.
    # [4432] 1522685983.749175 video encdoer: all started (1)
    # [4432] 1522685983.749209 encoder client registered: total 1 clients.
    # [4432] 1522685983.749241 encoder: pktqueue #0 callback registered (0xf55a88a0)
    # [4432] 1522685983.749301 video encoder: h.264/found sps@4(24); pps@32(4)
    # [4432] 1522685983.749336 GAMediaSubsession: video/H264 SPS=0xdcfc353c(24); PPS=0xdcfc363c(4); profile_level_id=4d4020
    # [4432] 1522685983.749385 qos: add sink#1 for H.264, rtpsink=0xe3471b60
    # [4432] 1522685983.749480 video encoding started: tid=4454 1280x1024@24fps, nalbuf_size=15828640, pic_in_size=1966080.
    # [4432] 1522685983.775570 first video frame written (pts=0)
    # [4432] 1522686049.085120 encoder client unregistered: 0 clients left.
    # [4432] 1522686049.085221 encoder: no more clients, quitting ...
    # [4432] 1522686049.102929 video encoder: thread terminated (tid=4454).
    # [4432] 1522686049.103052 video encdoer: all stopped (1)
    [libx264 @ 0xdc605f40] frame I:1     Avg QP: 7.00  size:   447
    [libx264 @ 0xdc605f40] frame P:1568  Avg QP: 0.01  size:   216
    [libx264 @ 0xdc605f40] mb I  I16..4: 99.9%  0.0%  0.1%
    [libx264 @ 0xdc605f40] mb P  I16..4:  3.2%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:96.8%
    [libx264 @ 0xdc605f40] final ratefactor: -29.32
    [libx264 @ 0xdc605f40] coded y,uvDC,uvAC intra: 0.0% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
    [libx264 @ 0xdc605f40] i16 v,h,dc,p: 94%  0%  6%  0%
    [libx264 @ 0xdc605f40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  0%  0% 100%  0%  0%  0%  0%  0%  0%
    [libx264 @ 0xdc605f40] i8c dc,h,v,p: 100%  0%  0%  0%
    [libx264 @ 0xdc605f40] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0xdc605f40] kb/s:41.58
    # [4432] 1522686049.104181 video encoder: deinitialized.

    I think the IP address in RTSP header is the LAN IP of the device which is causing the making the connection to fail. The same software works fine from the LAN. Any help is appreciated.