diff options
author | jstebbins <[email protected]> | 2014-05-29 19:59:57 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2014-05-29 19:59:57 +0000 |
commit | c50cf79a313ab76473a69f6ed8625afcb1a2c40b (patch) | |
tree | f4f33d97d109481c6e41d7290eb73572d9edc03c /libhb | |
parent | 0340cdc16c3cf51f24a2ddfcb40cd8d3b7257e17 (diff) |
libhb: Fix decoding avi with palette
... and probably other formats that use a palette.
The palette is stored in AVPacket side data which we did not read. So
read the side data and stash it in hb_buffer_t so that it can be used
later by the decoder.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6207 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/decavcodec.c | 18 | ||||
-rw-r--r-- | libhb/internal.h | 4 | ||||
-rw-r--r-- | libhb/scan.c | 21 | ||||
-rw-r--r-- | libhb/stream.c | 10 |
4 files changed, 46 insertions, 7 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 9b7be6702..bfa5f221d 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -86,6 +86,7 @@ struct hb_work_private_s AVCodecContext *context; AVCodecParserContext *parser; AVFrame *frame; + hb_buffer_t *palette; int threads; int video_codec_opened; hb_list_t *list; @@ -1175,6 +1176,18 @@ static int decodeFrame( hb_work_object_t *w, uint8_t *data, int size, int sequen avp.size = size; avp.pts = pts; avp.dts = dts; + + if (pv->palette != NULL) + { + uint8_t * palette; + int size; + palette = av_packet_new_side_data(&avp, AV_PKT_DATA_PALETTE, + AVPALETTE_SIZE); + size = MIN(pv->palette->size, AVPALETTE_SIZE); + memcpy(palette, pv->palette->data, size); + hb_buffer_close(&pv->palette); + } + /* * libav avcodec_decode_video2() needs AVPacket flagged with AV_PKT_FLAG_KEY * for some codecs. For example, sequence of PNG in a mov container. @@ -1882,6 +1895,11 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in, pv->dxva2->input_dts = dts; } #endif + if (in->palette != NULL) + { + pv->palette = in->palette; + in->palette = NULL; + } decodeVideo( w, in->data, in->size, in->sequence, pts, dts, in->s.frametype ); hb_buffer_close( &in ); *buf_out = link_buf_list( pv ); diff --git a/libhb/internal.h b/libhb/internal.h index 5255c6fac..e3b81cd0c 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -130,6 +130,10 @@ struct hb_buffer_s enum { HOST, DEVICE } buffer_location; } cl; + // libav may attach AV_PKT_DATA_PALETTE side data to some AVPackets + // Store this data here when read and pass to decoder. + hb_buffer_t * palette; + // PICTURESUB subtitle packets: // Video packets (after processing by the hb_sync_video work-object): diff --git a/libhb/scan.c b/libhb/scan.c index 0e601bb1d..5d8666592 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -554,13 +554,20 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) } else if (data->stream) { - /* we start reading streams at zero rather than 1/11 because - * short streams may have only one sequence header in the entire - * file and we need it to decode any previews. */ - if (!hb_stream_seek(data->stream, (float) i / ( data->preview_count + 1.0 ) ) ) - { - continue; - } + /* we start reading streams at zero rather than 1/11 because + * short streams may have only one sequence header in the entire + * file and we need it to decode any previews. + * + * Also, seeking to position 0 loses the palette of avi files + * so skip initial seek */ + if (i != 0) + { + if (!hb_stream_seek(data->stream, + (float)i / (data->preview_count + 1.0))) + { + continue; + } + } } hb_deep_log( 2, "scan: preview %d", i + 1 ); diff --git a/libhb/stream.c b/libhb/stream.c index 7f411a297..2b551e7ca 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -5639,6 +5639,16 @@ hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream ) } buf = hb_buffer_init( stream->ffmpeg_pkt->size ); memcpy( buf->data, stream->ffmpeg_pkt->data, stream->ffmpeg_pkt->size ); + + const uint8_t *palette; + int size; + palette = av_packet_get_side_data(stream->ffmpeg_pkt, + AV_PKT_DATA_PALETTE, &size); + if (palette != NULL) + { + buf->palette = hb_buffer_init( size ); + memcpy( buf->palette->data, palette, size ); + } } buf->s.id = stream->ffmpeg_pkt->stream_index; |