bentasker / HLS-Stream-Creator

Simple Bash Script to take a media file, segment it and create an M3U8 playlist for serving using HLS
BSD 3-Clause "New" or "Revised" License
273 stars 101 forks source link

Works great but... #14

Closed madhudvisa closed 7 years ago

madhudvisa commented 7 years ago

Hi

It seems to work well but seems to be creating video files that are way bigger than the set bitrates:

I checked a stream made with this at http://krishnatube.com/output/1.mp4_master.m3u8 and the apple mediastreamvalidator is giving the following error messages:

Error: Measured peak bitrate compared to master playlist declared value exceeds error tolerance --> Detail: Measured: 222.58 kb/s, Master playlist: 28.00 kb/s, Error: 87.42% --> Source: http://krishnatube.com/output/1.mp4_master.m3u8 --> Compare: 1.mp4_28.m3u8

--> Detail: Measured: 344.47 kb/s, Master playlist: 128.00 kb/s, Error: 62.84% --> Source: http://krishnatube.com/output/1.mp4_master.m3u8 --> Compare: 1.mp4_128.m3u8

--> Detail: Measured: 270.08 kb/s, Master playlist: 64.00 kb/s, Error: 76.30% --> Source: http://krishnatube.com/output/1.mp4_master.m3u8 --> Compare: 1.mp4_64.m3u8

--> Detail: Measured: 512.63 kb/s, Master playlist: 256.00 kb/s, Error: 50.06% --> Source: http://krishnatube.com/output/1.mp4_master.m3u8 --> Compare: 1.mp4_256.m3u8

Also is there any chance of being able to specify the frame rate? If original video is 60 frames per second for example to change that to 25 frames per second, maybe even different frames per second for the different variants?

madhudvisa commented 7 years ago

https://developer.apple.com/library/content/technotes/tn2224/_index.html#//apple_ref/doc/uid/DTS40009745-CH1-SETTINGSFILES screen shot 2016-11-22 at 10 21 12 pm

bentasker commented 7 years ago

Those bitrates are definitely way out, can you paste the command you used

madhudvisa commented 7 years ago

Hi

The command is below.

I suspect the difference may be in the Apple standard they are considering the total bitrate [audio + video] but the script is just specifying the video bitrate without considering the audio bitrate.

So to get a stream that matches the current standards [which has different video and audio bitrates and framerates for the different streams, you would need to be able to specify:

for each variant.

HLS-Stream-Creator.sh -i 1.mp4 -s 10 -b 64,128,256

It is making ffmpeg commands like:

ffmpeg -i 1.mp4 -loglevel verbose -y -vcodec libx264 -acodec aac -threads 0 -map 0 -flags -global_header -f segment -segment_list ./output/1.mp4_64.m3u8 -segment_time 10 -segment_format mpeg_ts -b:v 64k ./output/1.mp464%05d.ts

ffmpeg -i 1.mp4 -loglevel verbose -y -vcodec libx264 -acodec aac -threads 0 -map 0 -flags -global_header -f segment -segment_list ./output/1.mp4_128.m3u8 -segment_time 10 -segment_format mpeg_ts -b:v 128k ./output/1.mp4128%05d.ts

ffmpeg -i 1.mp4 -loglevel verbose -y -vcodec libx264 -acodec aac -threads 0 -map 0 -flags -global_header -f segment -segment_list ./output/1.mp4_256.m3u8 -segment_time 10 -segment_format mpeg_ts -b:v 256k ./output/1.mp4256%05d.ts

The whole thing is below:

HLS-Stream-Creator.sh -i 1.mp4 -s 10 -b 64,128,256

2011-10-22 03:48:48 handler_name : handler_name : GPAC ISO Video HandlerGPAC ISO Video Handler handler_name :

GPAC ISO Video Handler Stream #0:1 Stream #0:1 Stream #0:1(eng)(eng)(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 47 kb/s: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 47 kb/s: Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 47 kb/s (default) (default) (default)

Metadata:
Metadata:
Metadata:
  creation_time   :       creation_time   :       creation_time   : 2011-10-22 03:48:482011-10-22 03:48:482011-10-22 03:48:48

  handler_name    :       handler_name    :       handler_name    : GPAC ISO Audio HandlerGPAC ISO Audio HandlerGPAC ISO Audio Handler

[graph 0 input from stream 0:0 @ 0x12e10a0] [graph 0 input from stream 0:0 @ 0x84c0a0] w:352 h:288 pixfmt:yuv420p tb:1/30000 fr:30/1 sar:1/1 sws_param:flags=2 w:352 h:288 pixfmt:yuv420p tb:1/30000 fr:30/1 sar:1/1 sws_param:flags=2 [graph 0 input from stream 0:0 @ 0x23370a0] w:352 h:288 pixfmt:yuv420p tb:1/30000 fr:30/1 sar:1/1 sws_param:flags=2 [graph 1 input from stream 0:1 @ 0x84fbc0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3 [graph 1 input from stream 0:1 @ 0x12e4bc0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3 [graph 1 input from stream 0:1 @ 0x233abc0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3 [libx264 @ 0x85f420] [libx264 @ 0x12f4420] using SAR=1/1 using SAR=1/1 [libx264 @ 0x234a420] using SAR=1/1 [libx264 @ 0x85f420] using cpu capabilities: none! [libx264 @ 0x12f4420] using cpu capabilities: none! [libx264 @ 0x234a420] using cpu capabilities: none! [libx264 @ 0x12f4420] profile High, level 1.3 [libx264 @ 0x85f420] profile High, level 1.3 [libx264 @ 0x234a420] profile High, level 1.3 [segment @ 0x12b2720] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times [segment @ 0x12b2720] Selected stream id:0 type:video [segment @ 0x81d720] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. Last message repeated 1 times [segment @ 0x81d720] Selected stream id:0 type:video [mpegts @ 0x1f4be00] muxrate VBR, pcr every 3 pkts, sdt every 200, pat/pmt every 40 pkts Output #0, segment, to './output/1.mp4256%05d.ts': Metadata: major_brand : M4V minor_version : 0 [mpegts @ 0x14b6e00] compatible_brands: muxrate VBR, isomavc1M4V mp42M4A pcr every 3 pkts, sdt every 200, pat/pmt every 40 pkts

title           : Output #0, segment, to './output/1.mp4_128_%05d.ts':

/home/ktube/off_web/1 Metadata:

major_brand     :     album           : M4V The Mac Video Archive

minor_version   :     artist          : 0Apple Computer // massanti.com

compatible_brands:     comment         : isomavc1M4V mp42M4A Professionally encoded by Diego Massanti

title           :     date            : /home/ktube/off_web/1
album           : The Mac Video Archive2007

artist          :     encoder         : Apple Computer // massanti.comLavf57.36.100

comment         : Professionally encoded by Diego Massanti
date            : 2007
encoder         : Lavf57.36.100
Stream #0:0(eng): Video: h264, 1 reference frame, yuv420p, 352x288 (0x0) [SAR 1:1 DAR 11:9], q=2-31, 256 kb/s, 30 fps, 90k tbn    Stream #0:0 (default)(eng)

: Video: h264, 1 reference frame, yuv420p, 352x288 (0x0) [SAR 1:1 DAR 11:9], q=2-31, 128 kb/s Metadata: , creation_time : 2011-10-22 03:48:48 30 fps, handler_name : 90k tbnGPAC ISO Video Handler (default)

  encoder         :     Metadata:

Lavc57.42.100 libx264 creation_time : 2011-10-22 03:48:48 Side data:

        handler_name    : cpb: GPAC ISO Video Handlerbitrate max/min/avg: 0/0/256000 buffer size: 0 vbv_delay: -1

  encoder         : Lavc57.42.100 libx264
Side data:
  cpb: bitrate max/min/avg: 0/0/128000 buffer size: 0 vbv_delay: -1
Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
  creation_time   :     Stream #0:12011-10-22 03:48:48(eng)

: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s handler_name : (default)GPAC ISO Audio Handler

Metadata:
  encoder         :       creation_time   : Lavc57.42.100 aac2011-10-22 03:48:48

Stream mapping: handler_name : GPAC ISO Audio Handler Stream #0:0 -> #0:0[segment @ 0x2308720] (h264 (native) -> h264 (libx264))Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead. encoder : Stream #0:1 -> #0:1Last message repeated 1 times (aac (native) -> aac (native))Stream mapping:

Stream #0:0 -> #0:0 Last message repeated 1 times (h264 (native) -> h264 (libx264))Press [q] to stop, [?] for help [segment @ 0x2308720] Selected stream id:0 type:video Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help [mpegts @ 0x2fa1e00] muxrate VBR, pcr every 3 pkts, sdt every 200, pat/pmt every 40 pkts Output #0, segment, to './output/1.mp464%05d.ts': Metadata: major_brand : M4V minor_version : 0 compatible_brands: isomavc1M4V mp42M4A title : /home/ktube/off_web/1 album : The Mac Video Archive artist : Apple Computer // massanti.com comment : Professionally encoded by Diego Massanti date : 2007 encoder : Lavf57.36.100 Stream #0:0(eng): Video: h264, 1 reference frame, yuv420p, 352x288 (0x0) [SAR 1:1 DAR 11:9], q=2-31, 64 kb/s, 30 fps, 90k tbn (default) Metadata: creation_time : 2011-10-22 03:48:48 handler_name : GPAC ISO Video Handler encoder : Lavc57.42.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/64000 buffer size: 0 vbv_delay: -1 Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s (default) Metadata: creation_time : 2011-10-22 03:48:48 handler_name : GPAC ISO Audio Handler encoder : Lavc57.42.100 aac Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help 2 dup! 2 dup! *** 2 dup! [segment @ 0x2308720] segment:'./output/1.mp4_64_00000.ts' starts with packet stream:0 pts:6000 pts_time:0.0666667 frame:0 [segment @ 0x81d720] segment:'./output/1.mp4_128_00000.ts' starts with packet stream:0 pts:6000 pts_time:0.0666667 frame:0 [segment @ 0x12b2720] segment:'./output/1.mp4_256_00000.ts' starts with packet stream:0 pts:6000 pts_time:0.0666667 frame:0 frame= 65 fps=0.0 q=52.0 size=N/A time=00:00:01.96 bitrate=N/A dup=2 drop=0 spframe= 61 fps=0.0 q=47.0 size=N/A time=00:00:01.87 bitrate=N/A dup=2 drop=0 spframe= 61 fps=0.0 q=40.0 size=N/A time=00:00:01.87 bitrate=N/A dup=2 drop=0 sp+ '[' 3 -ne 0 ']'

bentasker commented 7 years ago
 I suspect the difference may be in the Apple standard they are considering the total bitrate [audio + video] but the script is just specifying the video bitrate without considering the audio bitrate.

That's certainly a possibility, though from memory the spec specifies that they should be considered seperately.

Can you try re-running the transcode but pass in -C so that a constant bitrate is used (rather than an average). Although those numbers seem too high for it to be the case, one possibility is that the average br is correct.

Could you also provide a ffprobe of a couple of the chunks that were generated for each bitrate?

bentasker commented 7 years ago

As I've not heard back, I'm going to close this off.

If it's still an issue, please re-open with the requested output.