how to specify codec in m3u8 while creating segments using ffmpeg? - ffmpeg

I am using ffmpeg to create a HLS playlist using segment filter.
result = subprocess.Popen(['ffmpeg -y -i {} -acodec copy -f segment -segment_time {} -segment_list {}.m3u8 {}%03d.ts'.format(pathToDownloadedMediaFile, 10, mediaFileName,mediaFileName)],stdout=subprocess.PIPE,stderr=subprocess.STDOUT, shell=True)
the generated file is :
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:11
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128000.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128001.ts
#EXTINF:9.984000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128002.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128003.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128004.ts
#EXTINF:9.984000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128005.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128006.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128007.ts
#EXTINF:9.984000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128008.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128009.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128010.ts
#EXTINF:9.984000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128011.ts
#EXTINF:10.008000,
c1dcf7f6643551fc22b82978d31f746fc40ed69d-128012.ts
#EXT-X-ENDLIST
As you can see, in the EXTINF tag, there is no CODEC specified,
it is required for using setAllowChunklessPreparation(true) in the exoplayer in Android for faster playback.
does anyone have idea how can i set the codec while generating the m3u8 manifest.

Related

HLS With discontinuity stuck in buffer

We are using JWPlayer 8.9.0 and we are trying to insert advertisements in our videos.
We are using EXT-X-DISCONTINUITY but apparently, when we get to the point of starting our advertising, the player stops showing a buffer status.
This is an example of our playlist:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:16
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:14.557178,
https://slave2.example.com/hls/output1/output_000.ts
#EXTINF:1.376467,
https://slave3.example.com/hls/output1/output_001.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.050244,
https://slave2.example.com/hls/HLSad/output_000.ts
#EXTINF:4.880200,
https://slave2.example.com/hls/HLSad/output_001.ts
#EXTINF:7.090889,
https://slave2.example.com/hls/HLSad/output_002.ts
#EXTINF:5.881267,
https://slave2.example.com/hls/output1/output_002.ts
#EXTINF:5.672711,
https://slave3.example.com/hls/output1/output_003.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.050244,
https://slave2.example.com/hls/HLSad/output_000.ts
#EXTINF:4.880200,
https://slave2.example.com/hls/HLSad/output_001.ts
#EXTINF:7.090889,
https://slave2.example.com/hls/HLSad/output_002.ts
#EXTINF:5.714422,
https://slave2.example.com/hls/output1/output_004.ts
#EXTINF:4.755067,
https://slave3.example.com/hls/output1/output_005.ts
[...]
#EXT-X-ENDLIST
This is what the JS console tells us:
[log] > audio sampling rate : 48000
9512e6e5-eff6-4f75-806f-a367785315b7:1 [log] > manifest codec:undefined,ADTS data:type:2,sampleingIndex:3[48000Hz],channelConfig:2
9512e6e5-eff6-4f75-806f-a367785315b7:1 [log] > parsed codec:mp4a.40.5,rate:48000,nb channel:2
9512e6e5-eff6-4f75-806f-a367785315b7:1 [log] > audio sampling rate : 48000
9512e6e5-eff6-4f75-806f-a367785315b7:1 [log] > AVC:59 ms overlapping between fragments detected
9512e6e5-eff6-4f75-806f-a367785315b7:1 [log] > Video/PTS/DTS adjusted: 15958/15933,delta:-59 ms
While the Chrome Media console says:
1.414 kPlay
{}
17.280 kBufferingStateChanged
{audio_buffering_state: {reason: "DEMUXER_UNDERFLOW", state: "BUFFERING_HAVE_NOTHING"}}
17.280 kBufferingStateChanged
{,…}
pipeline_buffering_state: {for_suspended_start: false, reason: "DEMUXER_UNDERFLOW", state: "BUFFERING_HAVE_NOTHING"}
for_suspended_start: false
reason: "DEMUXER_UNDERFLOW"
state: "BUFFERING_HAVE_NOTHING"
Considering that the two videos that we are going to "merge" in the playlist have the same audio / video characteristics (codecs, bitrate, resolution etc.), why is this not working?
Thank you
I met similar problem, and resolved it by this way:
Add "#EXT-X-DISCONTINUITY-SEQUENCE" in your playlist file, like below:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:16
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:14.557178,
https://slave2.example.com/hls/output1/output_000.ts
#EXTINF:1.376467,
https://slave3.example.com/hls/output1/output_001.ts
#EXT-X-DISCONTINUITY
#EXTINF:8.050244,
https://slave2.example.com/hls/HLSad/output_000.ts
#EXTINF:4.880200,
https://slave2.example.com/hls/HLSad/output_001.ts
Wherever you remove "#EXT-X-DISCONTINUITY" from your playlist file, increase the value of this field by 1.

laravel-ffmpeg - fopen(/tmp/laravel-ffmpegi340VY.mkv): failed to open stream: No such file or directory

Using the laravel-ffmpeg librabry to convert video file from .webm to mp4 aws s3 bucket url and using following code.
$videoFile = '/courses/images/1579626678msr-2020-01-21T17-11-18-771Z.webm'; //= upload/video1.mp4
FFMpeg::fromDisk('s3')
->open($videoFile)
->getFrameFromSeconds(10)
->export()
->toDisk('s3')
->inFormat(new \FFMpeg\Format\Video\X264)
->save('small_steve.mp4');
How can access file from s3 bucket and convert?
Use this code and using fromDesk('public') add public before the file path.
FFMpeg::fromDisK('s3')->open('/courses/images/1579626678msr-2020-01-21T17-11-18-771Z.webm')
->export()
->toDisk('s3')
->inFormat(new \FFMpeg\Format\Video\X264('libfdk_aac'))
->save('output2.mp4');

What is the difference between these 2 videos?

I am using fluent-ffmpeg to resize a video.
I can't figure out what's happening though. I have 2 video files, one works but the other doesn't. I've been scouring the mediainfo outputs of both files, checking for discrepancies but other than filesize, duration etc. there's no difference (same codec, format, width/height, frame rate etc)
Here's a link to both files.
I've been reading these video files into fluent-ffmpeg using an input stream, as so:
await new Promise((resolve, reject) => {
ffmpeg(file.stream)
.output(path)
.size('426x240')
.on('start', function() {
console.log('started');
})
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('progress', function(progress) {
console.log('... frames: ' + progress.frames);
})
.on('end', function() {
console.log('Finished processing');
resolve();
})
.run();
});
The working file prints:
started
... frames: 86
... frames: 107
Finished processing
But the non-working file doesn't seem to have any frames, and prints:
started
... frames: 0
Finished processing
Any idea what could be wrong?
The ffmpeg command being executed:
ffmpeg -i pipe:0 -y -filter:v scale=w=426:h=240 uploads/works.mp4
I've been scouring the mediainfo outputs of both files, checking for discrepancies but other than filesize, duration etc. there's no difference
It does, but in full mode only. try mediainfo -f on the files, you'll see:
IsStreamable : Yes
for the working file, and
IsStreamable : No
For the non working file.
a "no" here means that the input needs to support seek (header is at the end, player needs to seek to end for parsing header then seek back to beginning for parsing data).
It seems like ffmpeg have problem probing the file when you pass it as a stream. But it does work if you pass it as a file. Could be because probing/demuxer can optionally use seeks etc. I tried to increase the probe buffer but didn't get it to work.
This do not work:
cat doesnt_work.mp4 | ffmpeg -i pipe:0 test.mp4
But this works:
ffmpeg -i doesnt_work.mp4 test.mp4

h264 annexb bitstream to flv mux ffmpeg library

I have an IP Camera which gives H264 annexb Bitstream through SDK calls.
I want to pack this video stream into FLV container. So far I've got to know the following :-
I have to convert H264 annexb to H264 AVCC :
For this I'll have to replace NAL header byte (0x00000001) with Size of NALU (big endian format).
My question is, What do I do with SPS and PPS ? should I write (av_interleaved_write_frame) them as are after replacing the NAL header ? or do I not write these frames at all ?
I read about AVCC requiring extra data. How do I construct that ? where do I pass that ?
First retrieve the SPS/PPS from the camera. Write the SPS/PPS to AVCC extradata format (see how to here: Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream)
Set AVCodecContext.extradata
void *extradata = /**/;
int extradata_size = /**/;
codecCtx->extradata_size = extradata_size;
codecCtx->extradata = av_malloc ( codecCtx->extradata_size );
memcpy ( codecCtx->extradata, extradata, codecCtx->extradata_size);
Before calling avcodec_open2

FFmpeg fourcc Avi codec support list?

A couple of similar questions are on stackoverflow, but I haven't been able to figure this exact problem out.
I want to get a list of the fourccs for the avi codecs that FFMpeg can decode.
I know how to get all the formats ffmpeg -formats and codecs ffmpeg -codecs but neither list gives me an accessible list of fourccs. Neither does the documentation I can find.
I need this list, so that my application can access the fourcc of an avi file and determine whether to use ffmpeg or VfW (or DirectX) to try decode the file.
Is there some ffmpeg command that can give me this list?
To extend the answer given above by Darren (and because the comment facility doesn't allow this much text) here is the full list of codecs parsed from the isom_8c-source file on ffmpeg.org:
raw yuv2 2vuy yuvs L555 L565 B565 24BG
BGRA RGBA ABGR b16g b48r bxbg bxrg bxyv
NO16 DVOO R420 R411 R10k R10g r210 AVUI
AVrp SUDS v210 bxy2 v308 v408 v410 Y41P
yuv4 jpeg mjpa AVDJ AVRn dmb1 mjpb SVQ1
svq1 svqi SVQ3 mp4v DIVX XVID 3IV2 h263
s263 dvcp dvc dvpp dv5p dv5n AVdv AVd1
dvhq dvhp dvh1 dvh2 dvh4 dvh5 dvh6 dvh3
VP31 rpza cvid 8BPS smc rle WRLE qdrw
WRAW avc1 ai5p ai5q ai52 ai53 ai55 ai56
ai1p ai1q ai12 ai13 ai15 ai16 m1v1 mpeg
m1v m2v1 hdv1 hdv2 hdv3 hdv4 hdv5 hdv6
hdv7 hdv8 hdv9 hdva mx5n mx5p mx4n mx4p
mx3n mx3p xd54 xd55 xd59 xd5a xd5b xd5c
xd5d xd5e xd5f xdv1 xdv2 xdv3 xdv4 xdv5
xdv6 xdv7 xdv8 xdv9 xdva xdvb xdvc xdvd
xdve xdvf xdhd xdh2 AVmp mjp2 tga tiff
gif png MNG vc-1 avs2 drac AVdn H263
3IVD AV1x AVup sgi dpx exr apch apcn
I don't know if it's comprehensive but the source code seems to contain a list of FourCCs.
Look at http://ffmpeg.org/doxygen/trunk/isom_8c-source.html
There are lots of lines like this
{ CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }
You should be able to download the latest source and write a script to pick them out.
It is possible to the mapping via avformat api, without digging in the source code.
uint32_t tag = MKTAG('H', '2', '6', '4');
const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 };
enum AVCodecID vcodec = av_codec_get_id(table, tag );
The functions avformat_get_riff_video_tags, avformat_get_riff_audio_tags and av_codec_get_id are all defined in "libavformat/avformat.h".
you can also get the mapping for a specific format using the table AVOutputFormat.codec_tag or AVInputFormat.codec_tag

Resources