FFmpeg
Loading...
Searching...
No Matches
libavcodec
bsf
jpegapp.c
Go to the documentation of this file.
1
/*
2
* Inject per-frame JPEG APP segments from a length-prefixed sidecar.
3
*
4
* Copyright (c) 2026 Reinhard Nißl
5
*
6
* This file is part of FFmpeg.
7
*
8
* FFmpeg is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
12
*
13
* FFmpeg is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with FFmpeg; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
*/
22
23
/**
24
* Sidecar format (big-endian), one record per encoded JPEG packet:
25
*
26
* u32be length
27
* u8 payload[length]
28
*
29
* Payload is zero or more complete JPEG APP segments (APP0..APP15),
30
* each ``FF En`` + 16-bit length (length includes those two bytes).
31
* A zero length leaves the packet unchanged.
32
*
33
* After SOI the payload is inserted. If it starts with APP0 and the
34
* two bytes immediately after SOI are an APP0 marker, that segment is
35
* dropped so the sidecar can replace it. An APP0 preceded by fill
36
* bytes or another segment is retained. An APP1-only payload keeps
37
* the encoder APP0: SOI, APP1, APP0, DQT, ...
38
*
39
* A sidecar read or validation error stops further record consumption
40
* for this filter context. Flushing does not clear that error.
41
*/
42
43
#include <errno.h>
44
#include <inttypes.h>
45
#include <
limits.h
>
46
#include <stdint.h>
47
#include <stdio.h>
48
#include <string.h>
49
50
#include "
libavutil/error.h
"
51
#include "
libavutil/file_open.h
"
52
#include "
libavutil/intreadwrite.h
"
53
#include "
libavutil/log.h
"
54
#include "
libavutil/mem.h
"
55
#include "
libavutil/opt.h
"
56
57
#include "
libavcodec/bsf.h
"
58
#include "
libavcodec/bsf_internal.h
"
59
#include "
libavcodec/bytestream.h
"
60
#include "
libavcodec/mjpeg.h
"
61
62
#define JPEGAPP_MAX_RECORD (16 * 1024 * 1024)
63
64
typedef
struct
JPEGAppContext
{
65
const
AVClass
*
class
;
66
GetByteContext
gb
;
67
uint8_t *
sidecar
;
68
int
sidecar_len
;
69
int
read_error
;
70