[FFmpeg-user] Carrying arbitrary data track from TS to mp4
Sid Sethupathi
sid.sethupathi at gmail.com
Fri Jan 5 20:23:38 EET 2024
Hi Carl, thanks for the suggestion.
Here are the outputs. First one is the good extraction from the TS sample.
Second one is converting TS to MP4. Third one is the bad extraction from
the MP4 sample. I've also saved them in this gist if that's easier to read:
https://gist.github.com/sidsethupathi/61e365e255e6a503c563fc8e869e4946
May be worth noting that the source of the video is not from a GoPro, so
I'm not sure where that GoPro metadata label is coming from.
Extracting the binary from the TS sample
```
ssethupathi at 062237-MAC ~ ffmpeg -i sample.ts -map d:0 -c copy -f data ts.bin
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0_1 --enable-shared
--enable-pthreads --enable-version3 --cc=clang --host-cflags=
--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d
--enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e
--enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt
--enable-libsvtav1 --enable-libtesseract --enable-libtheora
--enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype
--enable-frei0r --enable-libass --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex
--enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack
--disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
[mpegts @ 0x7fbc60b04280] start time for stream 5 is not set in
estimate_timings_from_pts
Input #0, mpegts, from 'sample.ts':
Duration: 00:00:08.39, start: 1.400000, bitrate: 2278 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps,
29.97 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:2[0x102](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:3[0x103](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:4[0x104](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:5[0x105]: Data: bin_data ([6][0][0][0] / 0x0006)
Output #0, data, to 'ts.bin':
Metadata:
encoder : Lavf60.3.100
Stream #0:0: Data: bin_data ([6][0][0][0] / 0x0006)
Stream mapping:
Stream #0:5 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 206kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:206kB global headers:0kB
muxing overhead: 0.000000%
```
Converting TS to MP4
```
ssethupathi at 062237-MAC ~ ffmpeg -y -i sample.ts -map 0 sample.mp4
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0_1 --enable-shared
--enable-pthreads --enable-version3 --cc=clang --host-cflags=
--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d
--enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e
--enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt
--enable-libsvtav1 --enable-libtesseract --enable-libtheora
--enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype
--enable-frei0r --enable-libass --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex
--enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack
--disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
[mpegts @ 0x7fa97ff052c0] start time for stream 5 is not set in
estimate_timings_from_pts
Input #0, mpegts, from 'sample.ts':
Duration: 00:00:08.39, start: 1.400000, bitrate: 2278 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps,
29.97 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:2[0x102](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:3[0x103](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:4[0x104](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 384 kb/s
Stream #0:5[0x105]: Data: bin_data ([6][0][0][0] / 0x0006)
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (mp2 (native) -> aac (native))
Stream #0:2 -> #0:2 (mp2 (native) -> aac (native))
Stream #0:3 -> #0:3 (mp2 (native) -> aac (native))
Stream #0:4 -> #0:4 (mp2 (native) -> aac (native))
Stream #0:5 -> #0:5 (copy)
Press [q] to stop, [?] for help
[libx264 @ 0x7fa98100bc40] using SAR=1/1
[libx264 @ 0x7fa98100bc40] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fa98100bc40] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x7fa98100bc40] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC
codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options:
cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1
psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1
cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=22
lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25
scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'sample.mp4':
Metadata:
encoder : Lavf60.3.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709,
progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 30k tbn
Metadata:
encoder : Lavc60.3.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s (default)
Metadata:
encoder : Lavc60.3.100 aac
Stream #0:2(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Metadata:
encoder : Lavc60.3.100 aac
Stream #0:3(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Metadata:
encoder : Lavc60.3.100 aac
Stream #0:4(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Metadata:
encoder : Lavc60.3.100 aac
Stream #0:5: Data: bin_data (gpmd / 0x646D7067)
[mp4 @ 0x7fa98100af80] Timestamps are unset in a packet for stream 5. This
is deprecated and will stop working in the future. Fix your code to set the
timestamps properly
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.02 bitrate=
18.0kbits/s dup=1 drop=0 speed=0.539x
frame= 13 fps=0.0 q=29.0 size= 0kB time=00:00:02.56 bitrate=
0.1kbits/s dup=1 drop=0 speed=4.73x
frame= 170 fps=163 q=29.0 size= 0kB time=00:00:07.85 bitrate=
0.0kbits/s dup=1 drop=0 speed=7.54x
frame= 251 fps=223 q=-1.0 Lsize= 629kB time=00:00:08.29 bitrate=
620.9kbits/s dup=1 drop=0 speed=7.36x
video:11kB audio:392kB subtitle:0kB other streams:206kB global headers:0kB
muxing overhead: 3.276680%
[libx264 @ 0x7fa98100bc40] frame I:2 Avg QP:10.50 size: 214
[libx264 @ 0x7fa98100bc40] frame P:63 Avg QP:10.11 size: 46
[libx264 @ 0x7fa98100bc40] frame B:186 Avg QP:13.67 size: 38
[libx264 @ 0x7fa98100bc40] consecutive B-frames: 1.2% 0.0% 0.0% 98.8%
[libx264 @ 0x7fa98100bc40] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x7fa98100bc40] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0%
0.0% 0.0% 0.0% 0.0% skip:100.0%
[libx264 @ 0x7fa98100bc40] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.0%
0.0% 0.0% direct: 0.0% skip:100.0%
[libx264 @ 0x7fa98100bc40] 8x8 transform intra:0.0%
[libx264 @ 0x7fa98100bc40] coded y,uvDC,uvAC intra: 0.0% 0.0% 0.0% inter:
0.0% 0.0% 0.0%
[libx264 @ 0x7fa98100bc40] i16 v,h,dc,p: 98% 0% 2% 0%
[libx264 @ 0x7fa98100bc40] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 0x7fa98100bc40] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fa98100bc40] kb/s:9.86
[aac @ 0x7fa9813a4140] Qavg: 806.494
[aac @ 0x7fa97ff06980] Qavg: 1268.587
[aac @ 0x7fa97ff07c40] Qavg: 65536.000
[aac @ 0x7fa97ff08ec0] Qavg: 24934.430
```
Extracting the binary from the MP4 sample
```
ssethupathi at 062237-MAC ~ ffmpeg -y -i sample.mp4 -map d:0 -c copy -f data
mp4.bin
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.3 (clang-1403.0.22.14.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0_1 --enable-shared
--enable-pthreads --enable-version3 --cc=clang --host-cflags=
--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d
--enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e
--enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt
--enable-libsvtav1 --enable-libtesseract --enable-libtheora
--enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype
--enable-frei0r --enable-libass --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex
--enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack
--disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa8bd904300] All samples in data stream
index:id [5:6] have zero duration, stream set to be discarded by default.
Override using AVStream->discard or -discard for ffmpeg command.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.3.100
Duration: 00:00:08.38, start: 0.000000, bitrate: 615 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661),
yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 10 kb/s,
29.97 fps, 29.97 tbr, 30k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.3.100 libx264
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 127 kb/s
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:3[0x4](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 2 kb/s
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:4[0x5](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
stereo, fltp, 128 kb/s
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:5[0x6](und): Data: bin_data (gpmd / 0x646D7067)
Metadata:
handler_name : GoPro MET
Output #0, data, to 'mp4.bin':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.3.100
Stream #0:0(und): Data: bin_data (gpmd / 0x646D7067)
Metadata:
handler_name : GoPro MET
Stream mapping:
Stream #0:5 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.000000%
```
Sid
On Fri, Jan 5, 2024 at 12:31 PM Carl Zwanzig <cpz at tuunq.com> wrote:
> Please include the complete & unedited ffmpeg command output in the email,
> that'll show everyone info about the stream(s) in question as well as the
> ffmpeg version.
>
> Later,
>
> z!
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-user
mailing list