summaryrefslogtreecommitdiff
path: root/libavcodec/mjpegenc_common.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-30 04:07:51 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-04-01 16:12:14 +0200
commit9b3279b20198a46aae08c29c3b4c4ce75ff637ff (patch)
treeb6744f3ddae395b8dfb8318bddfa8a99e9cd8c9b /libavcodec/mjpegenc_common.c
parentf7d44804a6fe5c3ce29464553411e184eea6461a (diff)
avcodec/mjpegenc: Fix files with slices > 1, but threads == 1
In the aforementioned case mpegvideo_enc.c calls ff_mjpeg_encode_stuffing() at the end of every line which pads the output to byte-alignment and escapes it; yet it does not write the restart-markers (and also not the DRI marker when writing the header) and so the output files are broken. Fix this by writing these markers depending upon the number of slices and not the number of threads in use; this also makes the output of the encoder reproducible given a slice count and is therefore important if encoder tests that actually use -threads auto are added in the future. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mjpegenc_common.c')
-rw-r--r--libavcodec/mjpegenc_common.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 7b82644763..4143a372bb 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -61,7 +61,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
ScanTable *intra_scantable,
uint16_t luma_intra_matrix[64],
uint16_t chroma_intra_matrix[64],
- int hsample[3])
+ int hsample[3], int use_slices)
{
int i, j, size;
uint8_t *ptr;
@@ -92,7 +92,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
}
}
- if(avctx->active_thread_type & FF_THREAD_SLICE){
+ if (use_slices) {
put_marker(p, DRI);
put_bits(p, 16, 4);
put_bits(p, 16, (avctx->width-1)/(8*hsample[0]) + 1);
@@ -217,7 +217,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
MJpegContext *m,
ScanTable *intra_scantable, int pred,
uint16_t luma_intra_matrix[64],
- uint16_t chroma_intra_matrix[64])
+ uint16_t chroma_intra_matrix[64],
+ int use_slices)
{
const int lossless = !m;
int hsample[4], vsample[4];
@@ -237,7 +238,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
jpeg_put_comments(avctx, pb);
jpeg_table_header(avctx, pb, m, intra_scantable,
- luma_intra_matrix, chroma_intra_matrix, hsample);
+ luma_intra_matrix, chroma_intra_matrix, hsample,
+ use_slices);
switch (avctx->codec_id) {
case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break;