gstreamer-screencaster 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # NOTE: this script is not yet working properly
  3. # screencap works well as do videotestsrc and audiotestsrc
  4. # but using alsa , pulse , or jack audio cause the audio to be intermittent
  5. # e.g. recording "test 1 2 3 4 5 6 7 8 9" results like "test 3 6 8 9"
  6. # configuration
  7. WIDTH=1280
  8. HEIGHT=800
  9. FPS=12
  10. VIDEO_BITRATE=1200
  11. SAMPLERATE=44100
  12. AUDIO_BITRATE=128
  13. N_CHANNELS=2
  14. # constants
  15. VIDEO_TEST_SRC='videotestsrc pattern=0 is-live=true'
  16. AUDIO_TEST_SRC='audiotestsrc is-live=true'
  17. SCREENCAP_SRC="ximagesrc endx=$(($WIDTH-1)) endy=$(($HEIGHT-1)) use-damage=false show-pointer=true"
  18. TIME_SRC='timeoverlay halignment=left valignment=top text="t:" shaded-background=true'
  19. PULSE_SRC='pulsesrc'
  20. H264_ENCODER="x264enc bitrate=$VIDEO_BITRATE bframes=0"
  21. LAME_ENCODER="lamemp3enc bitrate=$AUDIO_BITRATE"
  22. VIDEO_TEST_CAPS="video/x-raw, format=(string)BGRA, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=$FPS/1, width=$WIDTH, height=$HEIGHT"
  23. AUDIO_TEST_CAPS="audio/x-raw, format=(string)S16LE, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)$SAMPLERATE, channels=(int)$N_CHANNELS"
  24. PULSE_CAPS=" audio/x-raw, format=(string)S16LE, rate=(int)$SAMPLERATE, channels=(int)$N_CHANNELS, layout=(string)interleaved"
  25. VIDEO_TEST_CAPS="video/x-raw, format=(string)BGRA, framerate=(fraction)$FPS/1, width=(int)$WIDTH, height=(int)$HEIGHT"
  26. AUDIO_TEST_CAPS="audio/x-raw, format=(string)S16LE, rate=(int)$SAMPLERATE, channels=(int)$N_CHANNELS"
  27. SCREENCAP_CAPS=" video/x-raw, framerate=(fraction)$FPS/1, width=(int)$WIDTH, height=(int)$HEIGHT, pixel-aspect-ratio=(fraction)1/1"
  28. PULSE_CAPS=" audio/x-raw, format=(string)S16LE, rate=(int)$SAMPLERATE, channels=(int)$N_CHANNELS"
  29. H264_ENC_CAPS=' video/x-h264, level=(string)4.1, profile=main'
  30. FLV_MUXER='flvmux streamable=true name=mux'
  31. OUTPUT_FILE=./deleteme.flv
  32. FILE_OUTPUT="filesink location=$OUTPUT_FILE"
  33. DEBUG_LOGGING='--gst-debug-level=2'
  34. VERBOSE_LOGGING='--verbose'
  35. # input selections
  36. VIDEO_SRC=$SCREENCAP_SRC
  37. VIDEO_CAPS=$SCREENCAP_CAPS
  38. # OVERLAY_SRC=$TIME_SRC # NOTE: put OVERLAY_SRC between VIDEO_SRC and VIDEO_CAPS
  39. VIDEO_ENC_CAPS=$H264_ENC_CAPS
  40. VIDEO_ENCODER=$H264_ENCODER
  41. # AUDIO_SRC=$AUDIO_TEST_SRC
  42. AUDIO_SRC=$PULSE_SRC
  43. # AUDIO_CAPS=$AUDIO_TEST_CAPS
  44. AUDIO_CAPS=$PULSE_CAPS
  45. AUDIO_ENCODER=$LAME_ENCODER
  46. MUXER=$FLV_MUXER
  47. OUTPUT_STREAM=$FILE_OUTPUT
  48. LOGGING="$DEBUG_LOGGING $VERBOSE_LOGGING"
  49. TESTING_COMPOSITOR="
  50. VIDEO_TEST_SRC1='videotestsrc pattern=1'
  51. VIDEO_TEST_SRC2='videotestsrc pattern=0'
  52. VIDEO_TEST_CAPS1='video/x-raw,format=I420, framerate=10/1, width=640, height=480'
  53. VIDEO_TEST_CAPS2='video/x-raw,format=I420, framerate=10/1, width=160, height=120'
  54. COMPOSITOR='compositor name=comp sink_1::xpos=480 sink_1::ypos=360 sink_1::zorder=1'
  55. gst-launch-1.0 $VIDEO_TEST_SRC1 ! \
  56. $VIDEO_TEST_CAPS1 ! \
  57. comp. \
  58. $VIDEO_TEST_SRC2 ! \
  59. $VIDEO_TEST_CAPS2 ! \
  60. comp. \
  61. $COMPOSITOR ! \
  62. videoconvert ! \
  63. ximagesink
  64. exit
  65. "
  66. gst-launch-1.0 $LOGGING $VIDEO_SRC ! \
  67. $VIDEO_CAPS ! \
  68. queue ! \
  69. videoconvert ! \
  70. $VIDEO_ENCODER ! \
  71. h264parse ! \
  72. $VIDEO_ENC_CAPS ! \
  73. queue ! \
  74. mux. \
  75. $AUDIO_SRC ! \
  76. $AUDIO_CAPS ! \
  77. queue ! \
  78. queue ! \
  79. $AUDIO_ENCODER ! \
  80. mpegaudioparse ! \
  81. queue ! \
  82. queue ! \
  83. queue ! \
  84. mux. \
  85. $MUXER ! \
  86. queue ! \
  87. $OUTPUT_STREAM