Commit 3bcadf82 authored by James Almer's avatar James Almer

avformat/matroskaenc: write a CRC32 element on Info

Finishes implementing ticket #4347
Tested-by: 's avatarDave Rice <dave@dericed.com>
Tested-by: 's avatarJerome Martinez <jerome@mediaarea.net>
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 650e17d8
......@@ -109,6 +109,8 @@ typedef struct MatroskaMuxContext {
AVIOContext *dyn_bc;
AVIOContext *tags_bc;
ebml_master tags;
AVIOContext *info_bc;
ebml_master info;
ebml_master segment;
int64_t segment_offset;
ebml_master cluster;
......@@ -1603,7 +1605,7 @@ static int mkv_write_header(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
AVIOContext *pb = s->pb;
ebml_master ebml_header, segment_info;
ebml_master ebml_header;
AVDictionaryEntry *tag;
int ret, i, version = 2;
int64_t creation_time;
......@@ -1668,7 +1670,11 @@ static int mkv_write_header(AVFormatContext *s)
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, avio_tell(pb));
if (ret < 0) goto fail;
segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0);
ret = start_ebml_master_crc32(pb, &mkv->info_bc, &mkv->info, MATROSKA_ID_INFO, 0);
if (ret < 0)
return ret;
pb = mkv->info_bc;
put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000);
if ((tag = av_dict_get(s->metadata, "title", NULL, 0)))
put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value);
......@@ -1722,7 +1728,11 @@ static int mkv_write_header(AVFormatContext *s)
put_ebml_void(pb, 11); // assumes double-precision float to be written
}
}
end_ebml_master(pb, segment_info);
if (s->pb->seekable)
put_ebml_void(s->pb, avio_tell(pb) + ((mkv->mode != MODE_WEBM) ? 2 /* ebml id + data size */ + 4 /* CRC32 */ : 0));
else
end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, mkv->info);
pb = s->pb;
// initialize stream_duration fields
mkv->stream_durations = av_mallocz(s->nb_streams * sizeof(int64_t));
......@@ -2247,8 +2257,10 @@ static int mkv_write_trailer(AVFormatContext *s)
// update the duration
av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
currentpos = avio_tell(pb);
avio_seek(pb, mkv->duration_offset, SEEK_SET);
put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration);
avio_seek(mkv->info_bc, mkv->duration_offset, SEEK_SET);
put_ebml_float(mkv->info_bc, MATROSKA_ID_DURATION, mkv->duration);
avio_seek(pb, mkv->info.pos, SEEK_SET);
end_ebml_master_crc32(pb, &mkv->info_bc, mkv, mkv->info);
// update stream durations
if (mkv->stream_durations) {
......
cc45779160972ebab95412ba75f35d4c *tests/data/fate/rgb24-mkv.matroska
58351 tests/data/fate/rgb24-mkv.matroska
5f43d628c76d97e30791bf30674ee485 *tests/data/fate/rgb24-mkv.matroska
58357 tests/data/fate/rgb24-mkv.matroska
#tb 0: 1/10
#media_type 0: video
#codec_id 0: rawvideo
......
afd0c76b5fd8ca5ee47d12af7f92d024 *./tests/data/lavf/lavf.mka
43678 ./tests/data/lavf/lavf.mka
2d9722c0691e140237af0036e3a178b0 *./tests/data/lavf/lavf.mka
43684 ./tests/data/lavf/lavf.mka
./tests/data/lavf/lavf.mka CRC=0x3a1da17e
af35b4e2fdea37a8874dbfbf7a691011 *./tests/data/lavf/lavf.mkv
472923 ./tests/data/lavf/lavf.mkv
591d55099c938bd7560585da13874a4c *./tests/data/lavf/lavf.mkv
472929 ./tests/data/lavf/lavf.mkv
./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
9daaedc22e6580cf6c7364e486fd1ee0 *./tests/data/lavf/lavf.mkv
320593 ./tests/data/lavf/lavf.mkv
c1009a6b9b4ef7e0eb0775d227131415 *./tests/data/lavf/lavf.mkv
320599 ./tests/data/lavf/lavf.mkv
./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 824 size: 208
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 830 size: 208
ret: 0 st:-1 flags:0 ts:-1.000000
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret: 0 st:-1 flags:1 ts: 1.894167
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret: 0 st: 0 flags:0 ts: 0.788000
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret: 0 st: 0 flags:1 ts:-0.317000
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret:-1 st: 1 flags:0 ts: 2.577000
ret: 0 st: 1 flags:1 ts: 1.471000
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320307 size: 209
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320313 size: 209
ret: 0 st:-1 flags:0 ts: 0.365002
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147013 size: 27925
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147019 size: 27925
ret: 0 st:-1 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret:-1 st: 0 flags:0 ts: 2.153000
ret: 0 st: 0 flags:1 ts: 1.048000
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret: 0 st: 1 flags:0 ts:-0.058000
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 824 size: 208
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 830 size: 208
ret: 0 st: 1 flags:1 ts: 2.836000
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320307 size: 209
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320313 size: 209
ret:-1 st:-1 flags:0 ts: 1.730004
ret: 0 st:-1 flags:1 ts: 0.624171
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147013 size: 27925
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147019 size: 27925
ret: 0 st: 0 flags:0 ts:-0.482000
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret: 0 st: 0 flags:1 ts: 2.413000
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret:-1 st: 1 flags:0 ts: 1.307000
ret: 0 st: 1 flags:1 ts: 0.201000
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 824 size: 208
ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 830 size: 208
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret: 0 st:-1 flags:1 ts: 1.989173
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret: 0 st: 0 flags:0 ts: 0.883000
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292466 size: 27834
ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292472 size: 27834
ret: 0 st: 0 flags:1 ts:-0.222000
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
ret:-1 st: 1 flags:0 ts: 2.672000
ret: 0 st: 1 flags:1 ts: 1.566000
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320307 size: 209
ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 320313 size: 209
ret: 0 st:-1 flags:0 ts: 0.460008
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147013 size: 27925
ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 147019 size: 27925
ret: 0 st:-1 flags:1 ts:-0.645825
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1040 size: 27837
ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 1046 size: 27837
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment