Reputation: 33
I'm streaming live video using DASH through FFmpeg. Everything's OK, fragments are generated, and the mpd file, but I wanted to have reproducible independent fragments. Video players won't open those fragments. I guess it's because they are mpd file dependant. My question would be: can those fragments be generated in a way that they are reproducible? I don't know if it has something to do to the frames I P B or just the way dash cuts video information, in a way that it only saves 'timeline' on the mpd...
My purpose is not only being able to reproduce them sepparately, but I need to insert information in a metadata tag of the video, and ffmpeg won't let me read those live streaming generated fragments.
FFmpeg input information command will behave like this:
input:
ffmpeg -i /path/video0-0-1.mp4
output:
ffmpeg version N-97777-g3b5a36c56d Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.59)
configuration: --enable-gpl --enable-libx264
libavutil 56. 45.100 / 56. 45.100
libavcodec 58. 84.100 / 58. 84.100
libavformat 58. 43.100 / 58. 43.100
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 81.100 / 7. 81.100
libswscale 5. 6.101 / 5. 6.101
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb324009400] could not find corresponding track id 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb324009400] could not find corresponding trex (id 1)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb324009400] could not find corresponding track id 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb324009400] trun track id unknown, no tfhd was found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb324009400] error reading header
/path/video0-0-1.mp4: Invalid data found when processing input
I execute this FFmpeg code using fluent-ffmpeg over JS to generate the fragments:
var ffmpeg = require('fluent-ffmpeg');
var grabacion = new ffmpeg();
grabacion.addInput('0')
.inputOptions(['-y -nostdin', '-f avfoundation', '-video_size 1280x720', '-pix_fmt nv12', '-framerate 30'])
.outputOptions(['-vcodec libx264', '-keyint_min 0', '-g 100', '-map 0:v', '-b:v 1000k', '-f dash',
'-use_template 1', '-use_timeline 0', '-init_seg_name video0-$RepresentationID$-$Number$.mp4',
'-media_seg_name video0-$RepresentationID$-$Number$.mp4', '-remove_at_exit 0', '-window_size 20', '-seg_duration 4'])
.output('/path/path/path/video.mpd')
.run();
So, the final purpose would be to be able to insert a tag like this:
ffmpeg -i video0-0-0.mp4 -movflags use_metadata_tags -metadata sample_tag=whateveryouwanttoadd video0-0-0-tagged.mp4
Is there any way to do it? Thank you in advance!
Upvotes: 3
Views: 6236
Reputation: 8254
Usually the first segment in DASH is an initialization segment containing the track information. All subsequent segments contain media samples. So if you want to decode an arbitrary segment you have to prefix it with the initialization segment.
cat /path/video0-0-init.mp4 /path/video0-0-1.mp4 > /path/video_can_be_decoded.mp4
ffmpeg -i /path/video_can_be_decoded.mp4
Upvotes: 2