[FFmpeg-devel] [PATCH] Added rap flag to libx265 to insert VPS/SPS/PPS before each key frame.
Michael Niedermayer
michaelni at gmx.at
Fri Mar 14 22:56:30 CET 2014
On Fri, Mar 14, 2014 at 06:52:24PM +0100, Marcus Gustafsson wrote:
> Hi all,
>
> my first post here.
> I've made a patch in order to be able to play streamed H.265 streams
> regardless where in the stream you start decoding.
> Use "-rap=1" to enable it as a video encoder argument.
>
> Best regards
> Marcus Gustafsson
>
> ---
> libavcodec/libx265.c | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index 2aceac7..291692a 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -42,6 +42,7 @@ typedef struct libx265Context {
> int header_size;
>
> char *preset;
> + int rap;
> char *tune;
> char *x265_opts;
> } libx265Context;
> @@ -247,10 +248,17 @@ static int libx265_encode_frame(AVCodecContext
> *avctx, AVPacket *pkt,
> if (!nnal)
> return 0;
>
> - for (i = 0; i < nnal; i++)
> + for (i = 0; i < nnal; i++) {
> payload += nal[i].sizeBytes;
> -
> - payload += ctx->header_size;
> + if (is_keyframe(nal[i].type)) {
> + pkt->flags |= AV_PKT_FLAG_KEY;
> + if (ctx->rap) {
> + payload += ctx->header_size;
> + }
> + }
> + }
> + if (!ctx->rap)
> + payload += ctx->header_size;
this looks wrong, it adds the header size multiple times
>
> ret = ff_alloc_packet(pkt, payload);
> if (ret < 0) {
> @@ -259,7 +267,7 @@ static int libx265_encode_frame(AVCodecContext *avctx,
> AVPacket *pkt,
> }
> dst = pkt->data;
>
> - if (ctx->header) {
> + if (ctx->header && !ctx->rap) {
> memcpy(dst, ctx->header, ctx->header_size);
> dst += ctx->header_size;
>
> @@ -267,14 +275,17 @@ static int libx265_encode_frame(AVCodecContext
> *avctx, AVPacket *pkt,
> ctx->header_size = 0;
> }
>
> +
> for (i = 0; i < nnal; i++) {
> + if (is_keyframe(nal[i].type)) {
> + if (ctx->header && ctx->rap) {
> + memcpy(dst, ctx->header, ctx->header_size);
> + dst += ctx->header_size;
> + }
> + }
and this adds the headers multiple times
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140314/1c5f3b95/attachment.asc>
More information about the ffmpeg-devel
mailing list