[FFmpeg-user] How to compress .MOV file compatible to Canon camera
Ulf Zibis
Ulf.Zibis at gmx.de
Tue Mar 31 03:25:09 EEST 2020
Am 14.03.20 um 20:39 schrieb Ted Park:
>
> Maybe you should consider the possibility that it isn’t a technical limitation of the decoder capability but something else introduced by proprietary metadata or implementation detail.
>
> There’s a huge user data box in the moov, upon a quick glance it has the camera model, firmware version, etc. I have to imagine it is used somehow. Try digging into it a bit, maybe you could reverse engineer it.
Here is the atom structure of the original file from the camera:
$ MP4Box -v MVI_1324.MOV
[iso file] Starting to parse a top-level box at position 0
[iso file] Read Box type ftyp size 24 start 0
[iso file] Starting to parse a top-level box at position 24
[iso file] Read Box type moov size 98280 start 24
[iso file] Read Box type udta size 65596 start 32
[iso file] Read Box type CNCV size 20 start 40
[iso file] Read Box type CNDM size 12 start 60
[iso file] Read Box type CNTH size 65552 start 72
[iso file] Read Box type CNDA size 9452 start 0
[iso file] Read Box type 4CF2D149 size 3078257872 start 9452
[iso file] Delete box type UNKN
[iso file] Delete box type UNKN
[iso file] Read Box type mvhd size 108 start 65628
[iso file] Read Box type trak size 7767 start 65736
[iso file] Read Box type tkhd size 92 start 65744
[iso file] Read Box type mdia size 7667 start 65836
[iso file] Read Box type mdhd size 32 start 65844
[iso file] Read Box type hdlr size 33 start 65876
[iso file] Read Box type minf size 7594 start 65909
[iso file] Read Box type vmhd size 20 start 65917
[iso file] Read Box type hdlr size 33 start 65937
[iso file] Read Box type dinf size 36 start 65970
[iso file] Read Box type dref size 28 start 65978
[iso file] Read Box type alis size 12 start 65994
[iso file] Read Box type stbl size 7497 start 66006
[iso file] Read Box type stsd size 173 start 66014
[iso file] Read Box type avc1 size 157 start 66030
[iso file] Read Box type colr size 18 start 66116
[iso file] Read Box type gama size 12 start 66134
[iso file] Read Box type avcC size 37 start 66146
[iso file] Read Box type stts size 24 start 66187
[iso file] Read Box type stss size 252 start 66211
[iso file] Read Box type stsc size 28 start 66463
[iso file] Read Box type stsz size 3508 start 66491
[iso file] Read Box type stco size 3504 start 69999
[iso file] Read Box type trak size 702 start 73503
[iso file] Read Box type tkhd size 92 start 73511
[iso file] Read Box type mdia size 602 start 73603
[iso file] Read Box type mdhd size 32 start 73611
[iso file] Read Box type hdlr size 33 start 73643
[iso file] Read Box type minf size 529 start 73676
[iso file] Read Box type smhd size 16 start 73684
[iso file] Read Box type hdlr size 33 start 73700
[iso file] Read Box type dinf size 36 start 73733
[iso file] Read Box type dref size 28 start 73741
[iso file] Read Box type alis size 12 start 73757
[iso file] Read Box type stbl size 436 start 73769
[iso file] Read Box type stsd size 92 start 73777
[iso file] Read Box type raw size 76 start 73793
[iso file] Read Box type chan size 24 start 73845
[iso file] Read Box type stts size 24 start 73869
[iso file] Read Box type stsc size 40 start 73893
[iso file] Read Box type stsz size 20 start 73933
[iso file] Read Box type stco size 252 start 73953
[iso file] Read Box type free size 24099 start 74205
[iso file] Unknown box type free in parent moov
[iso file] Starting to parse a top-level box at position 98304
[iso file] Read Box type mdat size 84830220 start 98304
[iso file] Delete box type ftyp
[iso file] Delete box type moov
[iso file] Delete box type udta
[iso file] Delete box type UNKN
[iso file] Delete box type UNKN
[iso file] Delete box type UNKN
[iso file] Delete box type mvhd
[iso file] Delete box type trak
[iso file] Delete box type tkhd
[iso file] Delete box type mdia
[iso file] Delete box type mdhd
[iso file] Delete box type hdlr
[iso file] Delete box type minf
[iso file] Delete box type vmhd
[iso file] Delete box type hdlr
[iso file] Delete box type dinf
[iso file] Delete box type dref
[iso file] Delete box type alis
[iso file] Delete box type stbl
[iso file] Delete box type stsd
[iso file] Delete box type avc1
[iso file] Delete box type colr
[iso file] Delete box type gama
[iso file] Delete box type avcC
[iso file] Delete box type stts
[iso file] Delete box type stss
[iso file] Delete box type stsc
[iso file] Delete box type stsz
[iso file] Delete box type stco
[iso file] Delete box type trak
[iso file] Delete box type tkhd
[iso file] Delete box type mdia
[iso file] Delete box type mdhd
[iso file] Delete box type hdlr
[iso file] Delete box type minf
[iso file] Delete box type smhd
[iso file] Delete box type hdlr
[iso file] Delete box type dinf
[iso file] Delete box type dref
[iso file] Delete box type alis
[iso file] Delete box type stbl
[iso file] Delete box type stsd
[iso file] Delete box type raw
[iso file] Delete box type chan
[iso file] Delete box type stts
[iso file] Delete box type stsc
[iso file] Delete box type stsz
[iso file] Delete box type stco
[iso file] Delete box type UNKN
[iso file] Delete box type mdat
Then I execute:
$ ~/Projects/ffmpeg/dev_2/ffmpeg -i MVI_1324.MOV -acodec copy -vcodec copy -movflags +faststart MVI_1324_copy_fast.mov
ffmpeg version N-96935-g34d7c8d942 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --enable-libx264 --enable-gpl
libavutil 56. 42.100 / 56. 42.100
libavcodec 58. 75.100 / 58. 75.100
libavformat 58. 41.100 / 58. 41.100
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 77.100 / 7. 77.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'MVI_1324.MOV':
Metadata:
major_brand : qt
minor_version : 537331968
compatible_brands: qt CAEP
creation_time : 2020-02-05T20:17:27.000000Z
Duration: 00:00:29.10, start: 0.000000, bitrate: 23351 kb/s
Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709), 1280x720, 23228 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 60k tbc (default)
Metadata:
creation_time : 2020-02-05T20:17:27.000000Z
Stream #0:1(eng): Audio: pcm_u8 (raw / 0x20776172), 12000 Hz, mono, u8, 96 kb/s (default)
Metadata:
creation_time : 2020-02-05T20:17:27.000000Z
File 'MVI_1324_copy_fast.mov' already exists. Overwrite? [y/N] y
Output #0, mov, to 'MVI_1324_copy_fast.mov':
Metadata:
major_brand : qt
minor_version : 537331968
compatible_brands: qt CAEP
encoder : Lavf58.41.100
Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709), 1280x720, q=2-31, 23228 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
Metadata:
creation_time : 2020-02-05T20:17:27.000000Z
Stream #0:1(eng): Audio: pcm_u8 (raw / 0x20776172), 12000 Hz, mono, u8, 96 kb/s (default)
Metadata:
creation_time : 2020-02-05T20:17:27.000000Z
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov @ 0x558d04680a40] Starting second pass: moving the moov atom to the beginning of the file
frame= 872 fps=182 q=-1.0 Lsize= 82855kB time=00:00:29.06 bitrate=23354.9kbits/s speed=6.06x
video:82501kB audio:341kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.015751%
Here is the atom structure of the result:
$ MP4Box -v MVI_1324_copy_fast.mov
[iso file] Starting to parse a top-level box at position 0
[iso file] Read Box type ftyp size 20 start 0
[iso file] Starting to parse a top-level box at position 20
[iso file] Read Box type moov size 13326 start 20
[iso file] Read Box type mvhd size 108 start 28
[iso file] Read Box type trak size 9892 start 136
[iso file] Read Box type tkhd size 92 start 144
[iso file] Read Box type edts size 36 start 236
[iso file] Read Box type elst size 28 start 244
[iso file] Read Box type mdia size 9756 start 272
[iso file] Read Box type mdhd size 32 start 280
[iso file] Read Box type hdlr size 45 start 312
[iso file] Read Box type minf size 9671 start 357
[iso file] Read Box type vmhd size 20 start 365
[iso file] Read Box type hdlr size 44 start 385
[iso file] Read Box type dinf size 36 start 429
[iso file] Read Box type dref size 28 start 437
[iso file] Read Box type url size 12 start 453
[iso file] Read Box type stbl size 9563 start 465
[iso file] Read Box type stsd size 139 start 473
[iso file] Read Box type avc1 size 123 start 489
[iso file] Read Box type avcC size 37 start 575
[iso file] Read Box type stts size 24 start 612
[iso file] Read Box type stss size 252 start 636
[iso file] Read Box type stsc size 4216 start 888
[iso file] Read Box type stsz size 3508 start 5104
[iso file] Read Box type stco size 1416 start 8612
[iso file] Read Box type trak size 3285 start 10028
[iso file] Read Box type tkhd size 92 start 10036
[iso file] Read Box type edts size 36 start 10128
[iso file] Read Box type elst size 28 start 10136
[iso file] Read Box type mdia size 3149 start 10164
[iso file] Read Box type mdhd size 32 start 10172
[iso file] Read Box type hdlr size 45 start 10204
[iso file] Read Box type minf size 3064 start 10249
[iso file] Read Box type smhd size 16 start 10257
[iso file] Read Box type hdlr size 44 start 10273
[iso file] Read Box type dinf size 36 start 10317
[iso file] Read Box type dref size 28 start 10325
[iso file] Read Box type url size 12 start 10341
[iso file] Read Box type stbl size 2960 start 10353
[iso file] Read Box type stsd size 76 start 10361
[iso file] Read Box type raw size 60 start 10377
[iso file] Read Box type chan size 24 start 10413
[iso file] Read Box type stts size 24 start 10437
[iso file] Read Box type stsc size 1420 start 10461
[iso file] Read Box type stsz size 20 start 11881
[iso file] Read Box type stco size 1412 start 11901
[iso file] Read Box type udta size 33 start 13313
[iso file] Read Box type A9737772 size 25 start 13321
[iso file] Starting to parse a top-level box at position 13346
[iso file] Read Box type wide size 8 start 13346
[iso file] Starting to parse a top-level box at position 13354
[iso file] Read Box type mdat size 84830220 start 13354
[iso file] Delete box type ftyp
[iso file] Delete box type moov
[iso file] Delete box type mvhd
[iso file] Delete box type trak
[iso file] Delete box type tkhd
[iso file] Delete box type edts
[iso file] Delete box type elst
[iso file] Delete box type mdia
[iso file] Delete box type mdhd
[iso file] Delete box type hdlr
[iso file] Delete box type minf
[iso file] Delete box type vmhd
[iso file] Delete box type hdlr
[iso file] Delete box type dinf
[iso file] Delete box type dref
[iso file] Delete box type url
[iso file] Delete box type stbl
[iso file] Delete box type stsd
[iso file] Delete box type avc1
[iso file] Delete box type avcC
[iso file] Delete box type stts
[iso file] Delete box type stss
[iso file] Delete box type stsc
[iso file] Delete box type stsz
[iso file] Delete box type stco
[iso file] Delete box type trak
[iso file] Delete box type tkhd
[iso file] Delete box type edts
[iso file] Delete box type elst
[iso file] Delete box type mdia
[iso file] Delete box type mdhd
[iso file] Delete box type hdlr
[iso file] Delete box type minf
[iso file] Delete box type smhd
[iso file] Delete box type hdlr
[iso file] Delete box type dinf
[iso file] Delete box type dref
[iso file] Delete box type url
[iso file] Delete box type stbl
[iso file] Delete box type stsd
[iso file] Delete box type raw
[iso file] Delete box type chan
[iso file] Delete box type stts
[iso file] Delete box type stsc
[iso file] Delete box type stsz
[iso file] Delete box type stco
[iso file] Delete box type udta
[iso file] Delete box type UNKN
[iso file] Delete box type wide
[iso file] Delete box type mdat
As you can see, I need to increase the ftyp box by 4 bytes to insert CEAP and to insert the udta box of the original at the bebinning of the moov box as a next step.
Is there a ffmpeg command to do this including the valid updating of the index data in the moov box?
-Ulf
More information about the ffmpeg-user
mailing list