FFmpeg streaming to Akamai like FMLE does - ffmpeg

I am trying to stream video from my webcam to AkamaiHD service using ffmpeg (like it is implemented in Flash Media Live Encoder)
ffmpeg -f dshow -i video="Webcam C110" -s 640x360 -aspect 16:9 -profile:v baseline - pix_fmt yuv420p -vcodec libx264 -f flv "rtmp://..."
...
Input #0, dshow, from 'video=Webcam C110':
Duration: N/A, start: 31296.194000, bitrate: N/A
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 30 tbr, 10000k tbn, 30 tbc
Output #0
Metadata:
encoder : Lavf55.8.102
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 1k tbn, 30 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo -> libx264)
....
The video is sreamed, but when I try to view it at http://mediapm.edgesuite.net/edgeflash/public/zeri/debug/Main.html?url=myplayback_url/manifest.f4m
it is not displayed.
I've found out that if the video is recorded using FMLE and restreamed to akamai, then HLS stream is played.
ffmpeg -re -i sample.f4v -c copy -f flv "rtmp://..."
....
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.f4v':
Metadata:
major_brand : f4v
minor_version : 0
compatible_brands: isommp42m4v
creation_time : 2018-10-06 09:23:33
Duration: 00:01:01.77, start: 0.460000, bitrate: 718 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 624 kb/s, 30 tbr, 1k tbn, 48 tbc
Metadata:
creation_time : 2018-10-06 09:23:33
handler_name : MainConcept
Output #0
Metadata:
major_brand : f4v
minor_version : 0
compatible_brands: isommp42m4v
encoder : Lavf55.8.102
Stream #0:0(eng): Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 624 kb/s, 1k tbn, 1k tbc
Metadata:
creation_time : 2018-10-06 09:23:33
handler_name : MainConcept
Stream mapping:
Stream #0:0 -> #0:0 (copy)
....
It seems that the problem is with h.264 codec configuration, but I have found no solution yet.
Could you please advice, how can I implement streaming like FMLE using ffmpeg?

I think for Akamai you need authentication for the RTMP entrypoint which I don't believe is supported in the librtmp used by ffmpeg.
Have a look at this thread over at Wowza for more information.
If you think it is a codec issue then instead of copy the codec you could try encoding it using -c:v libx264 as the video codec and -c:a libfaac for audio

Related

I try to reduce a MPEG-4 video's bitrate with GPU acceleration,but something is wrong

ffmpeg -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -c:v
mpeg4_cuvid -i "F:\dataset\celeb-df-v1\Celeb-real\id0_0002.mp4"
-vcodec mpeg4 -b:v 574k -y "F:\dataset\celeb-df-v1\compress\id0_0002.mp4"
It keeps reporting errors like:
Impossible to convert between the formats supported by the filter
'Parsed_null_0' and the filter 'auto_scaler_0' Error reinitializing
filters! Failed to inject frame into filter network: Function not
implemented Error while processing the decoded data for stream #0:0
Here is my video info
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'F:\dataset\celeb-df-v1\\Celeb-real\id0_0002.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.3.100
Duration: 00:00:11.67, start: 0.000000, bitrate: 1148 kb/s
Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 942x500 [SAR 1:1 DAR 471:250], 1146 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (mpeg4_cuvid) -> mpeg4 (native))
Press [q] to stop, [?] for help

ffmpeg: Extract unknown data stream from video container

I have a .MOV container which contains the following tracks:
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 100619 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2020-07-21T22:48:24.000000Z
handler_name : DJI.AVC
encoder : AVC encoder
Stream #0:1(eng): Data: none (priv / 0x76697270), 87 kb/s
Metadata:
creation_time : 2020-07-21T22:48:24.000000Z
handler_name : DJI.Meta
Stream #0:2(eng): Subtitle: mov_text (text / 0x74786574), 2 kb/s (default)
Metadata:
creation_time : 2020-07-21T22:48:24.000000Z
handler_name : DJI.Subtitle
As you can see, stream #0:1, called DJI.meta, is of an unknown data format. I just want to extract the raw data of this stream to a file. So that is the ffmpeg command I tried:
ffmpeg -i .\DJI_0001.MOV -map 0:1 metadata
But using this command results in the following error:
Unable to find a suitable output format for 'metadata'
metadata: Invalid argument
How can I tell ffmpeg that the data should not be formated, so that only the raw data is extracted?
Use
ffmpeg -i input -map 0:d -c copy -copy_unknown -f data raw.bin

ffmpeg - less frames getting extracted than expected

ffmpeg -i instagram.mp4 -vf fps=29.97 thumb%06d.jpg -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'instagram.mp4': Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.19.104 Duration: 00:00:13.61, start: 0.000000, bitrate: 1163 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x640 [SAR 1:1 DAR 1:1], 1099 kb/s, 29.97 fps,
29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
Metadata:
handler_name : SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native)) Press [q] to stop, [?] for help [swscaler # 0x55b2b53cf440] deprecated pixel format used, make sure
you did set range correctly Output #0, image2, to 'thumb%06d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 640x640 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc57.107.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 frame= 405 fps=231 q=24.8 Lsize=N/A time=00:00:13.51 bitrate=N/A speed=7.72x video:5961kB audio:0kB subtitle:0kB other streams:0kB
global headers:0kB muxing overhead: unknown
The video duration is 13.61 seconds and frame rate is 29.97. So I was expecting 13.61 * 29.97 = 407.8917 i.e. 407 frames. But have got 405 frames. I am new to ffmpeg, need help to correctly get all 407 frames.
I had also tried following command,
ffmpeg -i instagram.mp4 thumb%06d.jpg -hide_banner
but the output was same 405 frames.
Possibly the start 2 frames are missing.
I need to display the frames generated in the base video timeline. And on clicking on the frame I need to exactly seek the video to the frame position using HTML5 currentTime. Since the first 2 frames are not getting available, exact mapping is not getting possible.
Please guide.
have you try to use -vsync vfr or -vsync 0 disables the frame drop/dup behaviour?
#Gyan
Please refer to this question.
https://superuser.com/questions/1374584/why-does-ffmpeg-extracts-a-lot-more-frames-than-the-actual

ffmpeg. Concatenate two webm files with transparency

Could you help me to find my mistake. I am trying to concatenate two files (webm) which have transparent background. I do the following:
ffmpeg -i 1.webm -i 2.webm -filter_complex "[0:v:0] 1:v:0]concat=n=2:v=1[outv]" -map "[outv]" 3.webm
I get the concatenate video as i I expect. However the transparent background disappears. Instead the background is black. How to keep the transparency when i concatenate two videos?
The output of the above command is:
ffmpeg version 3.3.4-2 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7 (Ubuntu 7.2.0-8ubuntu2)
Input #0, matroska,webm, from '1.webm':
Metadata:
encoder : Lavf57.71.100
Duration: 00:00:04.35, start: 0.000000, bitrate: 293 kb/s
Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, progressive), 799x770, SAR 1:1 DAR 799:770, 23 fps, 23 tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
Input #1, matroska,webm, from '2.webm':
Metadata:
encoder : Lavf57.71.100
Duration: 00:00:04.35, start: 0.000000, bitrate: 303 kb/s
Stream #1:0(eng): Video: vp9 (Profile 0), yuv420p(tv, progressive), 799x770, SAR 1:1 DAR 799:770, 23 fps, 23 tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
File '3.webm' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 (vp9) -> concat:in0:v0
Stream #1:0 (vp9) -> concat:in1:v0
concat -> Stream #0:0 (libvpx-vp9)
Press [q] to stop, [?] for help
[libvpx-vp9 # 0x55f58406a540] v1.6.1
Output #0, webm, to '3.webm':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 799x770 [SAR 1:1 DAR 799:770], q=-1--1, 200 kb/s, 23 fps, 1k tbn, 23 tbc (default)
Metadata:
encoder : Lavc57.89.100 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 200 fps=8.4 q=0.0 Lsize= 187kB time=00:00:08.65 bitrate= 176.8kbits/s speed=0.365x
video:185kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.011632%
`
I thought this had been fixed, but apparently the native VPx decoders still don't decode alpha, so you have to use the libvpx decoders.
ffmpeg -c:v libvpx-vp9 -i 1.webm -c:v libvpx-vp9 -i 2.webm -filter_complex "[0:v:0] 1:v:0]concat=n=2:v=1[outv]" -map "[outv]" 3.webm

Embedding timed text metadata in MP4

Is it possible to manually embed timed text metadata into MP4 files?
I have a TTML / SRT file with the metadata. I just need to embed the text data without doing any encoding the video / audio.
EDIT:
We used to do the metadata injecting using on Wowza server which we use for live streaming. What I need to do is manually inject the metadata in to prerecorded MP4 files without running the video through Wowza.
Here is one such video file that was processed by Wowza:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'metadata-back.mp4':
Metadata:
major_brand : f4v
minor_version : 0
compatible_brands: isommp42m4v
creation_time : 2015-04-16 11:12:39
Duration: 00:00:11.70, start: 0.000000, bitrate: 1373 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv), 640x480 [SAR 1:1 DAR 4:3], 1352 kb/s, 28.60 fps, 30 tbr, 90k tbn, 60 tbc (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
encoder : WowzaStreamingEngine
Stream #0:1(eng): Audio: speex (spex / 0x78657073), 16000 Hz, mono, s16, 17 kb/s (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
Stream #0:2(eng): Data: none (amf0 / 0x30666D61), 0 kb/s (default)
Metadata:
creation_time : 2015-04-16 11:12:39
handler_name : WowzaStreamingEngine
Now if I run the command ffmpeg -i new-meta.mp4 -i sub.srt -c copy -c:s mov_text -movflags +faststart out.mp4 and if I run ffmpeg -i out.mp4, I get this:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.4.101
Duration: 00:00:07.27, start: 0.000000, bitrate: 925 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1366x768 [SAR 1:1 DAR 683:384], 920 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
handler_name : SubtitleHandler
Now as you can see the text is embedded with a different codec (is this the right term?). Also I dont see an audio track as well.
Hope my question is clear enough. I need a way to embed metadata (from srt / ttml) into an MP4 video it should be embedded in amf format (again is this the right term?)
ffmpeg -i in.mp4 -i subs.srt -c copy -c:s mov_text -movflags +faststart out.mp4
Support for 3GPP TS 26.245 Timed Text ("mov_text") in MP4 may vary according to the player.

Resources