Advertisement
Sweetening

CLIPPING FRONTEND BACKEND EXAMPLE

Oct 29th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. -------------------------------------------------------------------------
  2. -------------------------------------------------------------------------
  3. FRONT END BELOW FOR CLIPPING FEATURE
  4. -------------------------------------------------------------------------
  5. <!DOCTYPE html>
  6. <html lang="en">
  7. <head>
  8. <meta charset="UTF-8">
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  10. <title>Clip Your Stream</title>
  11. <style>
  12. body { font-family: Arial, sans-serif; }
  13. #clipSection { margin: 20px 0; }
  14. </style>
  15. </head>
  16. <body>
  17.  
  18. <h1>Clip Your Live Stream</h1>
  19. <video id="liveStream" width="640" height="360" controls>
  20. <source src="your_live_stream_url" type="video/mp4">
  21. Your browser does not support the video tag.
  22. </video>
  23.  
  24. <div id="clipSection">
  25. <label for="startTime">Start Time (seconds):</label>
  26. <input type="number" id="startTime" min="0" required>
  27. <label for="endTime">End Time (seconds):</label>
  28. <input type="number" id="endTime" min="1" required>
  29. <button id="clipButton">Create Clip</button>
  30. </div>
  31.  
  32. <script>
  33. document.getElementById('clipButton').addEventListener('click', async () => {
  34. const startTime = document.getElementById('startTime').value;
  35. const endTime = document.getElementById('endTime').value;
  36.  
  37. const response = await fetch('/api/clip', {
  38. method: 'POST',
  39. headers: {
  40. 'Content-Type': 'application/json'
  41. },
  42. body: JSON.stringify({ startTime, endTime })
  43. });
  44.  
  45. if (response.ok) {
  46. const result = await response.json();
  47. alert(`Clip created: ${result.clipUrl}`);
  48. } else {
  49. alert('Error creating clip.');
  50. }
  51. });
  52. </script>
  53.  
  54. </body>
  55. </html>
  56. -------------------------------------------------------------------------
  57. -------------------------------------------------------------------------
  58. BACKEND FOR CLIPPING FEATURE
  59. -------------------------------------------------------------------------
  60. const express = require('express');
  61. const bodyParser = require('body-parser');
  62. const ffmpeg = require('fluent-ffmpeg');
  63. const path = require('path');
  64. const fs = require('fs');
  65.  
  66. const app = express();
  67. const PORT = process.env.PORT || 3000;
  68.  
  69. app.use(bodyParser.json());
  70. app.use(express.static('public')); // Serve static files from the 'public' directory
  71.  
  72. app.post('/api/clip', (req, res) => {
  73. const { startTime, endTime } = req.body;
  74.  
  75. // Path to your live stream video
  76. const inputVideo = 'path/to/your_live_stream.mp4';
  77. const outputVideo = `clipped_${startTime}-${endTime}.mp4`;
  78.  
  79. ffmpeg(inputVideo)
  80. .setStartTime(startTime)
  81. .setDuration(endTime - startTime)
  82. .output(path.join(__dirname, outputVideo))
  83. .on('end', () => {
  84. res.json({ clipUrl: `/${outputVideo}` });
  85. })
  86. .on('error', (err) => {
  87. console.error('Error: ' + err.message);
  88. res.status(500).send('Error processing video.');
  89. })
  90. .run();
  91. });
  92.  
  93. app.listen(PORT, () => {
  94. console.log(`Server is running on port ${PORT}`);
  95. });
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement