Guest User

Untitled

a guest
Sep 11th, 2025
24
0
29 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # GLOBAL VARIABLES
  5. # GOP [frames] = seg_duration [s] * framerate [frames/s]
  6. segDuration=1.0
  7. framerate=30
  8.  
  9. gop=30
  10. # gop=$(echo "$segDuration * $framerate" | bc) # floating point operation
  11. # gop=${gop%.*}  # truncate decimal part
  12. # echo -e "GOP: $gop \n seg_duration: $segDuration \n framerate: $framerate \n"
  13.  
  14. # Chunks
  15. fragDuration=0.5
  16. fragType='every_frame' # every_frame, duration, [none]
  17. #CBR (Constant Bit Rate)
  18. bitrate=3000K
  19.  
  20. # Encoder
  21. cd ~/ffmpeg_sources/ffmpeg && \
  22. ./ffmpeg \
  23. -v verbose \
  24. -listen 1 \
  25. -i 'rtmp://127.0.0.1:1935/stream/test' \
  26. -flags +global_header \
  27. -r $framerate \
  28. \
  29. -filter_complex "settb=AVTB,setpts='trunc(PTS/1K)*1K+st(1,trunc(RTCTIME/1K))-1K*trunc(ld(1)/1K)',\
  30. drawbox=x=0:y=0:width=400:height=100:[email protected]:t=fill,\
  31. drawtext=text='%{localtime\:%M}\:%{localtime\:%S}.%{eif\:1M*t-1K*trunc(t*1K)\:d\:3}':x=15:y=20:\
  32. fontfile=/usr/share/fonts/truetype/freefont/FreeSans.ttf:fontsize=80:fontcolor=white,\
  33. split=1[s0]" \
  34. \
  35. -pix_fmt yuv420p \
  36. -c:v libx264 \
  37. \
  38. -b:v:0 $bitrate -minrate:v:0 $bitrate -maxrate:v:0 $bitrate -bufsize:v:0 $bitrate \
  39. \
  40. -g:v $gop -keyint_min:v $gop -sc_threshold:v 0 \
  41. \
  42. -color_primaries bt709 -color_trc bt709 -colorspace bt709 \
  43. \
  44. -c:a aac -ar 48000 -b:a 96k \
  45. \
  46. -map [s0] \
  47. -map 0:a:0 \
  48. \
  49. -preset ultrafast \
  50. -tune zerolatency \
  51. \
  52. -use_template 1 \
  53. -use_timeline 0 \
  54. -streaming 1 \
  55. -frag_type $fragType \
  56. -flags +global_header \
  57. -ldash 1 \
  58. -remove_at_exit 1 \
  59. -utc_timing_url 'https://time.akamai.com?iso&ms' \
  60. -format_options 'movflags=cmaf' \
  61. -write_prft 1 \
  62. -target_latency '3.0' \
  63. -seg_duration $segDuration \
  64. -frag_duration $fragDuration \
  65. -adaptation_sets "id=0,streams=v id=1,streams=a" \
  66. -init_seg_name init-L\$RepresentationID\$.mp4 \
  67. -media_seg_name frag-N\$Number\$-L\$RepresentationID\$.mp4 \
  68. -method PUT \
  69. -f dash \
  70. "http://127.0.0.1:80/upload/live.mpd"
Advertisement
Add Comment
Please, Sign In to add comment