Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] Added support for MB_INFO
Date: Fri, 24 Jun 2022 11:14:34 +0200
Message-ID: <DB6PR0101MB2214F95EBC692A81AE3EE6D58FB49@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <165599568445.12703.13879461885645668680@lain.khirnov.net>

Anton Khirnov:
> Quoting Andreas Rheinhardt (2022-06-23 16:21:18)
>> Anton Khirnov:
>>> Quoting Carotti, Elias (2022-06-21 10:48:07)
>>>> Hi,
>>>>
>>>> extending AVVideoEncParams was the first hypothesis I made but it
>>>> didn't seem it was the proper place to add the mb_info flags.
>>>>
>>>> I may be wrong but my impression is that AVVideoEncParams is used to
>>>> carry encoding parameters read from the bitstream at the decoder side
>>>> while here were going the other direction, i.e., were passing
>>>> information from the application to the encoder.
>>>>
>>>> Secondly, mb_info can't be strictly considered encoding parameters and
>>>> it's not present in the bitstream at all. 
>>>> It's just a way to give hints to the libx264 encoder on which
>>>> macroblock we know have not changed since the previous frame and could
>>>> be coded as P_SKIPs. Libx264 however, may or may not oblige according
>>>> to its logic, and this specific information is not transmitted in the
>>>> bitstream nor can be recovered at the decoder.
>>>
>>> Right, seems I was too hasty in reading your patch.
>>>
>>> But then I have to wonder whether this really needs a new installed
>>> header, with a struct and a destructor, given that it's specific to a
>>> single encoder for a single codec that is about 20 years old now.
>>>
>>> Wouldn't AV_FRAME_DATA_X264_MBINFO that would be just a raw array of
>>> uint8_t serve your needs just as fine? You could even get custom buffer
>>> management by using AVFrameSideData.buf.
>>>
>>
>> There is one problem though: libx264's free functions don't accept an
>> opaque parameter, so one can't easily create a reference for libx264 to
>> unref. I don't see a way around duplicating this buffer in the encoder.
>> (Or is there a way to know when libx264 is done with using this buffer?)
> 
> An ugly, but workable hack could be
> - user allocates the AVBuffer with extra space at the end
> - lavc/libx264.c checks that there is extra space AND the buffer is
>   writable (so the same side data wasn't passed to multiple encoders),
>   then stores its AVBufferRef* in there
> 

Ugly? Certainly. Workable? Questionable: Depending upon how the user
uses the API the frame might not be writable when it reaches the encode
callback of our libx264 wrapper even if the user actually supplies
writable frames to avcodec_send_frame(). The reason is that if said
callback is called in avcodec_send_frame(), both the user's AVFrame as
well as the newly created reference to it (which is the frame that the
callback receives) will each own a reference to each side data.
The callback is called in avcodec_send_frame() if there is currently no
buffered packet ready to be forwarded to the user. This is true if the
user drains the encoder every time a frame has been sent. And that is
how we ordinarily use the API (our examples use this pattern as well as
ffmpeg.c). So I guess that this is the common way our API is used by
others as well.
(I think I once proposed adding a flag to muxers/encoders to select
whether an ownership transfer of the packet/frame is intended or not.)

- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      reply	other threads:[~2022-06-24  9:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10 10:11 Carotti, Elias
2022-06-17  8:41 ` Carotti, Elias
2022-06-17  9:40   ` Timo Rothenpieler
2022-06-17 10:15     ` Carotti, Elias
2022-06-17 10:34       ` Timo Rothenpieler
2022-06-17 10:59         ` Carotti, Elias
2022-06-17 15:10           ` Timo Rothenpieler
2022-06-17 15:30             ` Carotti, Elias
2022-06-17 23:41             ` Stefano Sabatini
2023-05-03 12:27             ` Carotti, Elias
2023-05-05  8:03               ` Carotti, Elias
2022-06-18 15:06   ` Anton Khirnov
2022-06-21  8:48     ` Carotti, Elias
2022-06-23 13:29       ` Anton Khirnov
2022-06-23 14:21         ` Andreas Rheinhardt
2022-06-23 14:48         ` Anton Khirnov
2022-06-24  9:14           ` Andreas Rheinhardt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB6PR0101MB2214F95EBC692A81AE3EE6D58FB49@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git