Fail to encode VideoFrame from <canvas>
Categories
(Core :: Audio/Video: Web Codecs, defect, P1)
Tracking
()
People
(Reporter: chunmin, Assigned: chunmin)
References
(Blocks 2 open bugs)
Details
Attachments
(7 files)
143.76 KB,
application/x-javascript
|
Details | |
4.68 KB,
text/html
|
Details | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
pascalc
:
approval-mozilla-beta+
|
Details | Review |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review |
Conversion error
will raise due to ConvertToI420
fails to get the DataSourceSurface
when encoding a VideoFrame
that captures the image from <canvas>. On my Ubuntu, this is because SourceSurfaceCanvasRecording::GetDataSurface
only works on main thread, while FFmpegeVideoEncoder is calling ConvertToI420
from non main thread.
Assignee | ||
Comment 1•4 months ago
|
||
Copyright (c) 2012. Telecom ParisTech/TSI/MM/GPAC Cyril Concolato
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Assignee | ||
Comment 2•4 months ago
•
|
||
Note that the encoding works if the VideoFrame is constructed from ImageBitmap instead of <canvas> (the mp4 mux in the demo has some problems, but the seek the video in Firefox should make it play).
async function encode(index) {
const img = await createImageBitmap(canvas);
const frame = new VideoFrame(/*canvas*/ img, {
timestamp: index * DURATION_PER_FRAME_US,
duration: DURATION_PER_FRAME_US,
});
let keyFrame = index % KEYFRAME_INDEX_INTERVAL == 0;
encoder.encode(frame, { keyFrame });
frame.close();
}
Assignee | ||
Comment 3•4 months ago
|
||
One way to solve this is to dispatch the GetDataSurface()
task to main thread like this, but it will block the encoder waiting for the response from main thread for every encode request. Additionally, I am not sure if the SourceSurfaceCanvasRecording
's DataSourceSurface
is thread-safe object.
Alternatively, since <canvas>
is always on the main thread, capturing the image data into a SourceSurfaceRawData
by CreateImageFromRawData
when VideoFrame is constructed seems a viable option, and encoder won't be blocked with this approach.
Assignee | ||
Updated•4 months ago
|
Assignee | ||
Comment 4•4 months ago
|
||
Depends on D218228
Assignee | ||
Comment 5•4 months ago
|
||
This patch enhances VideoFrame to capture an image from the <canvas>
element provided to its constructor, enabling VideoFrame instances
created with <canvas> to be encoded by VideoEncoder.
Previously, the underlying image in a VideoFrame constructed with
<canvas>. was held within SourceSurfaceCanvasRecording. The
GetDataSurface()
method, necessary to access the underlying image,
could only be called on the main thread, while encoding occurs on a
non-main thread.
A naive solution would be to dispatch the GetDataSurface()
task to the
main thread, but this would block the encoder while waiting for a
response from the main thread for every encode request. Additionally, it
is unclear if SourceSurfaceCanvasRecording
's DataSourceSurface
is
thread-safe.
This patch adopts an alternative approach by capturing the image from
the given <canvas> upon VideoFrame construction. This ensures that the
image is owned by the VideoFrame itself and can be processed on any
thread.
Depends on D218229
Updated•4 months ago
|
Assignee | ||
Comment 6•4 months ago
|
||
Assignee | ||
Comment 7•4 months ago
|
||
Depends on D218230
Assignee | ||
Comment 8•4 months ago
|
||
Depends on D218424
Comment 11•3 months ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/bb7125f9a984
https://hg.mozilla.org/mozilla-central/rev/aae4e1cc5e70
https://hg.mozilla.org/mozilla-central/rev/0ce48f0eca6a
https://hg.mozilla.org/mozilla-central/rev/8b47777d8edc
https://hg.mozilla.org/mozilla-central/rev/e89f3dfb5d8c
Assignee | ||
Comment 13•3 months ago
•
|
||
Comment on attachment 9417395 [details]
Bug 1910668 - Add a test case
Beta/Release Uplift Approval Request
- User impact if declined: webcodecs feature would be partially broken.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: Bug 1908572
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This patch is a small fix for an issue that blocks webcodecs's release, and it's totally separate from other media code. Since webcodec is aimed to be shipped in Firefox 130, so this stack [1] needs to be merged before the uplift request in bug 1908572 comment 6. Additionally, the webcodecs feature is behind a pref. Thus, the feature can be easily disabled if needed.
- String changes made/needed:
- Is Android affected?: No
[1]
https://hg.mozilla.org/mozilla-central/rev/bb7125f9a984
https://hg.mozilla.org/mozilla-central/rev/aae4e1cc5e70
https://hg.mozilla.org/mozilla-central/rev/0ce48f0eca6a
https://hg.mozilla.org/mozilla-central/rev/8b47777d8edc
https://hg.mozilla.org/mozilla-central/rev/e89f3dfb5d8c
Comment 14•3 months ago
|
||
Comment on attachment 9417395 [details]
Bug 1910668 - Add a test case
Approved for 130 beta 5, thanks.
Comment 15•3 months ago
|
||
uplift |
Updated•3 months ago
|
Description
•