
Recherche avancée
Médias (91)
-
Corona Radiata
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Lights in the Sky
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Head Down
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Echoplex
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Discipline
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Letting You
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (41)
-
(Dés)Activation de fonctionnalités (plugins)
18 février 2011, parPour gérer l’ajout et la suppression de fonctionnalités supplémentaires (ou plugins), MediaSPIP utilise à partir de la version 0.2 SVP.
SVP permet l’activation facile de plugins depuis l’espace de configuration de MediaSPIP.
Pour y accéder, il suffit de se rendre dans l’espace de configuration puis de se rendre sur la page "Gestion des plugins".
MediaSPIP est fourni par défaut avec l’ensemble des plugins dits "compatibles", ils ont été testés et intégrés afin de fonctionner parfaitement avec chaque (...) -
Le plugin : Podcasts.
14 juillet 2010, parLe problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
Types de fichiers supportés dans les flux
Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...) -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (7625)
-
FFmpeg Overwiting Playlist
30 septembre 2024, par Program-Me-RevI'm working on an implementation where I aim to generate a DASH Playlist from Raw Camera2 data in Android Java using FFmpeg


However , the current implementation only produces Three .m4s files regardless of how long the recording lasts . My goal is to create a playlist with 1-second .m4s Segments , but the output only includes the following files , and the video length doesn't exceed 2 seconds :


- playlist.mpd
- init.m4s
- 1.m4s
- 2.m4s



While the temporary files are created as expected , the .m4s files stop after these two segments . Additionally , only the last 2 seconds of the recording are retained , no matter how long the recording runs


The FFmpeg output indicates that FFmpeg is repeatedly overwriting the previously generated playlist , which may explain why the recording doesn't extend beyond 2 seconds


FFmpeg version : 6.0


package rev.ca.rev_media_dash_camera2;

 import android.app.Activity;
 import android.content.Context;
 import android.media.Image;
 import android.util.Log;
 import android.util.Size;

 import androidx.annotation.NonNull;
 import androidx.camera.core.CameraSelector;
 import androidx.camera.core.ImageAnalysis;
 import androidx.camera.core.ImageProxy;
 import androidx.camera.core.Preview;
 import androidx.camera.lifecycle.ProcessCameraProvider;
 import androidx.camera.view.PreviewView;
 import androidx.core.content.ContextCompat;
 import androidx.lifecycle.LifecycleOwner;

 import com.arthenica.ffmpegkit.FFmpegKit;
 import com.arthenica.ffmpegkit.ReturnCode;
 import com.google.common.util.concurrent.ListenableFuture;

 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;

 public class RevCameraCapture {
 private static final String REV_TAG = "RevCameraCapture";

 private final Context revContext;
 private final ExecutorService revExecutorService;
 private final String revOutDirPath = "/storage/emulated/0/Documents/Owki/rev_web_rtc_live_chat_temp_files/_abc_rev_uploads_temp";
 private boolean isRevRecording;
 private File revTempFile;
 private int revFrameCount = 0; // Counter for frames captured

 public RevCameraCapture(Context revContext) {
 this.revContext = revContext;

 revInitDir(revOutDirPath);
 revCheckOrCreatePlaylist();

 revExecutorService = Executors.newSingleThreadExecutor();
 }

 private void revInitDir(String revDirPath) {
 // Create a File object for the directory
 File revNestedDir = new File(revDirPath);

 // Check if the directory exists, if not, create it
 if (!revNestedDir.exists()) {
 boolean revResult = revNestedDir.mkdirs(); // mkdirs() creates the whole path
 if (revResult) {
 Log.e(REV_TAG, ">>> Directories created successfully.");
 } else {
 Log.e(REV_TAG, ">>> Failed to create directories.");
 }
 } else {
 Log.e(REV_TAG, ">>> Directories already exist.");
 }
 }

 private void revCheckOrCreatePlaylist() {
 File revPlaylistFile = new File(revOutDirPath, "rev_playlist.mpd");
 if (!revPlaylistFile.exists()) {
 // Create an empty playlist if it doesn't exist
 try {
 FileOutputStream revFos = new FileOutputStream(revPlaylistFile);
 revFos.write("".getBytes());
 revFos.close();
 } catch (IOException e) {
 Log.e(REV_TAG, ">>> Error creating initial rev_playlist : ", e);
 }
 }
 }


 private void revStartFFmpegProcess() {
 // Ensure revTempFile exists before processing
 if (revTempFile == null || !revTempFile.exists()) {
 Log.e(REV_TAG, ">>> Temporary file does not exist for FFmpeg processing.");
 return;
 }

 // FFmpeg command to convert the temp file to DASH format and append to the existing rev_playlist
 String ffmpegCommand = "-f rawvideo -pixel_format yuv420p -video_size 704x704 " + "-i " + revTempFile.getAbsolutePath() + " -c:v mpeg4 -b:v 1M " + "-f dash -seg_duration 1 -use_template 1 -use_timeline 1 " + "-init_seg_name 'init.m4s' -media_seg_name '$Number$.m4s' " + revOutDirPath + "/rev_playlist.mpd -loglevel debug";


 FFmpegKit.executeAsync(ffmpegCommand, session -> {
 ReturnCode returnCode = session.getReturnCode();
 if (ReturnCode.isSuccess(returnCode)) {
 // Optionally handle success, e.g., log or notify that the process completed successfully
 } else {
 Log.e(REV_TAG, ">>> FFmpeg process failed with return code : " + returnCode);
 }
 });
 }


 public void revStartCamera() {
 isRevRecording = true;

 ListenableFuture<processcameraprovider> revCameraProviderFuture = ProcessCameraProvider.getInstance(revContext);

 revCameraProviderFuture.addListener(() -> {
 try {
 ProcessCameraProvider revCameraProvider = revCameraProviderFuture.get();
 revBindPreview(revCameraProvider);
 revBindImageAnalysis(revCameraProvider);
 } catch (ExecutionException | InterruptedException e) {
 Log.e(REV_TAG, ">>> Failed to start camera : ", e);
 }
 }, ContextCompat.getMainExecutor(revContext));
 }

 private void revBindPreview(ProcessCameraProvider revCameraProvider) {
 CameraSelector revCameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();

 PreviewView previewView = ((Activity) revContext).findViewById(R.id.previewView);
 Preview preview = new Preview.Builder().build();
 preview.setSurfaceProvider(previewView.getSurfaceProvider());

 revCameraProvider.unbindAll();
 revCameraProvider.bindToLifecycle((LifecycleOwner) revContext, revCameraSelector, preview);
 }

 private void revBindImageAnalysis(@NonNull ProcessCameraProvider revCameraProvider) {
 ImageAnalysis revImageAnalysis = new ImageAnalysis.Builder().setTargetResolution(new Size(640, 480)) // Lower the resolution to reduce memory consumption
 .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST).build();

 revImageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(revContext), this::revAnalyze);
 CameraSelector revCameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();

 revCameraProvider.bindToLifecycle((LifecycleOwner) revContext, revCameraSelector, revImageAnalysis);
 }

 @androidx.annotation.OptIn(markerClass = androidx.camera.core.ExperimentalGetImage.class)
 private void revAnalyze(@NonNull ImageProxy revImageProxy) {
 try {
 revProcessImageFrame(revImageProxy);
 } catch (Exception e) {
 Log.e(REV_TAG, ">>> Error processing revImage frame", e);
 } finally {
 revImageProxy.close(); // Always close the revImageProxy
 }
 }

 @androidx.annotation.OptIn(markerClass = androidx.camera.core.ExperimentalGetImage.class)
 private void revProcessImageFrame(@NonNull ImageProxy revImageProxy) {
 Image revImage = revImageProxy.getImage();
 if (revImage != null) {
 byte[] revImageBytes = revConvertYUV420888ToByteArray(revImage);
 revWriteFrameToTempFile(revImageBytes); // Write frame to a temporary file
 }
 revImageProxy.close(); // Close the ImageProxy to release the revImage buffer
 }

 private byte[] revConvertYUV420888ToByteArray(Image revImage) {
 Image.Plane[] planes = revImage.getPlanes();
 ByteBuffer revBufferY = planes[0].getBuffer();
 ByteBuffer revBufferU = planes[1].getBuffer();
 ByteBuffer revBufferV = planes[2].getBuffer();

 int revWidth = revImage.getWidth();
 int revHeight = revImage.getHeight();

 int revSizeY = revWidth * revHeight;
 int revSizeUV = (revWidth / 2) * (revHeight / 2); // U and V sizes are half the Y size

 // Total size = Y + U + V
 byte[] revData = new byte[revSizeY + 2 * revSizeUV];

 // Copy Y plane
 revBufferY.get(revData, 0, revSizeY);

 // Copy U and V planes, accounting for row stride and pixel stride
 int revOffset = revSizeY;
 int revPixelStrideU = planes[1].getPixelStride();
 int rowStrideU = planes[1].getRowStride();
 int revPixelStrideV = planes[2].getPixelStride();
 int rowStrideV = planes[2].getRowStride();

 // Copy U plane
 for (int row = 0; row < revHeight / 2; row++) {
 for (int col = 0; col < revWidth / 2; col++) {
 revData[revOffset++] = revBufferU.get(row * rowStrideU + col * revPixelStrideU);
 }
 }

 // Copy V plane
 for (int row = 0; row < revHeight / 2; row++) {
 for (int col = 0; col < revWidth / 2; col++) {
 revData[revOffset++] = revBufferV.get(row * rowStrideV + col * revPixelStrideV);
 }
 }

 return revData;
 }


 private void revWriteFrameToTempFile(byte[] revImageBytes) {
 revExecutorService.execute(() -> {
 try {
 // Create a new temp file for each segment if needed
 if (revTempFile == null || revFrameCount == 0) {
 revTempFile = File.createTempFile("vid_segment_", ".yuv", new File(revOutDirPath));
 }

 try (FileOutputStream revFos = new FileOutputStream(revTempFile, true)) {
 revFos.write(revImageBytes);
 }

 revFrameCount++;

 // Process after 60 frames (2 second for 30 fps)
 if (revFrameCount >= 60 && isRevRecording) {
 revStartFFmpegProcess(); // Process the segment with FFmpeg
 revFrameCount = 0; // Reset the frame count
 revTempFile = null; // Reset temp file for the next segment
 }

 } catch (IOException e) {
 Log.e(REV_TAG, ">>> Error writing frame to temp file : ", e);
 }
 });
 }

 public void revStopCamera() {
 isRevRecording = false;
 if (revTempFile != null && revTempFile.exists()) {
 revTempFile.delete(); // Clean up the temporary file
 revTempFile = null; // Reset the temp file reference
 }
 }
 }


 package rev.ca.rev_media_dash_camera2;

 import android.os.Bundle;

 import androidx.appcompat.app.AppCompatActivity;

 public class MainActivity extends AppCompatActivity {
 private RevCameraCapture revCameraCapture;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 revCameraCapture = new RevCameraCapture(this);
 }

 @Override
 protected void onStart() {
 super.onStart();
 try {
 revCameraCapture.revStartCamera();
 } catch (Exception e) {
 e.printStackTrace();
 }
 }

 @Override
 protected void onStop() {
 super.onStop();
 revCameraCapture.revStopCamera(); // Ensure camera is stopped when not in use
 }
 }
</processcameraprovider>


-
RTSP to HLS via FFMPEG, latency issues
28 juin 2024, par Pabl0The following are all the steps that I took to render a RTSP stream in my web app :


How to display RTSP stream in browser using HLS


Situation and Problem
You have an RTSP stream that you want to display in a browser using HLS (HTTP Live Streaming). However, when you try to play the RTSP stream in the browser using hls.js, you encounter the error "Unsupported HEVC in M2TS found." This error indicates that the HLS stream uses the HEVC (H.265) codec, which is not widely supported by many browsers and HLS players, including hls.js.


The most reliable solution is to transcode the stream from H.265 to H.264 using FFmpeg, which is more broadly supported. Here's how to transcode the stream :


Step 1 : Transcode the Stream Using FFmpeg


Run the following FFmpeg command to transcode the RTSP stream from H.265 to H.264 and generate the HLS segments :


ffmpeg -i rtsp://192.168.144.25:8554/main.264 -c:v libx264 -c:a aac -strict -2 -hls_time 10 -hls_list_size 0 -f hls C:\path\to\output\index.m3u8



c:v libx264 sets the video codec to H.264.


c:a aac sets the audio codec to AAC.


hls_time 10 sets the duration of each segment to 10 seconds.


hls_list_size 0 tells FFmpeg to include all segments in the playlist.


f hls specifies the output format as HLS.


C :\path\to\output\ is the directory where the HLS files will be saved. Ensure that C :\path\to\output\ is the directory where you want to save the HLS files.


Step 2 : Verify the HLS Files


After running the FFmpeg command, verify that the following files are generated in the output directory :


index.m3u8 (HLS playlist file)


Multiple .ts segment files (e.g., index0.ts, index1.ts, etc.)


Step 3 : Serve the HLS Files with an HTTP Server


Navigate to the directory containing the HLS files and start the HTTP server :


cd C :\path\to\output
python -m http.server 8000
Step 4 : Update and Test the HTML File
Ensure that hls_test.html file is in the same directory as the HLS files and update it as needed :


hls_test.html :




 
 
 
 
 
 
 <h1>HLS Stream Test</h1>
 <button>Play Stream</button>
 <video controls="controls" style="width: 100%; height: auto;"></video>
 <code class="echappe-js"><script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>

<script>&#xA; document&#xA; .getElementById(&#x27;playButton&#x27;)&#xA; .addEventListener(&#x27;click&#x27;, () => {&#xA; const video = document.getElementById(&#x27;video&#x27;);&#xA; if (Hls.isSupported()) {&#xA; const hls = new Hls();&#xA; hls.loadSource(&#x27;http://localhost:8000/index.m3u8&#x27;);&#xA; hls.attachMedia(video);&#xA; hls.on(Hls.Events.MANIFEST_PARSED, function () {&#xA; video.play().catch((error) => {&#xA; console.error(&#xA; &#x27;Error attempting to play:&#x27;,&#xA; error,&#xA; );&#xA; });&#xA; });&#xA; hls.on(Hls.Events.ERROR, function (event, data) {&#xA; console.error(&#x27;HLS Error:&#x27;, data);&#xA; });&#xA; } else if (&#xA; video.canPlayType(&#x27;application/vnd.apple.mpegurl&#x27;)&#xA; ) {&#xA; video.src = &#x27;http://localhost:8000/index.m3u8&#x27;;&#xA; video.addEventListener(&#x27;canplay&#x27;, function () {&#xA; video.play().catch((error) => {&#xA; console.error(&#xA; &#x27;Error attempting to play:&#x27;,&#xA; error,&#xA; );&#xA; });&#xA; });&#xA; } else {&#xA; console.error(&#x27;HLS not supported in this browser.&#x27;);&#xA; }&#xA; });&#xA; </script>

 



Step 5 : Open the HTML File in Your Browser


Open your browser and navigate to :


http://localhost:8000/hls_test.html



Click the "Play Stream" button to start playing the HLS stream. If everything is set up correctly, you should see the video playing in the browser.


Conclusion


By transcoding the RTSP stream from H.265 to H.264 and serving it as an HLS stream, you can display the video in a browser using hls.js. This approach ensures broader compatibility with browsers and HLS players, allowing you to stream video content seamlessly.


PART 2 : Add this method to the react app


We are assuming that the ffmpeg command is running in the background and generating the HLS stream. Now, we will create a React component that plays the HLS stream in the browser using the video.js library.


If not, please refer to the previous steps to generate the HLS stream using FFmpeg. (steps 1-3 of the previous section)


Step 1 : Create the Camera Component


import { useRef } from 'react';
import videojs from 'video.js';
import 'video.js/dist/video-js.css';

const Camera = ({ streamUrl }) => {
 const videoRef = useRef(null);
 const playerRef = useRef(null);

 const handlePlayClick = () => {
 const videoElement = videoRef.current;
 if (videoElement) {
 playerRef.current = videojs(videoElement, {
 controls: true,
 autoplay: false,
 preload: 'auto',
 sources: [
 {
 src: streamUrl,
 type: 'application/x-mpegURL',
 },
 ],
 });

 playerRef.current.on('error', () => {
 const error = playerRef.current.error();
 console.error('VideoJS Error:', error);
 });

 playerRef.current.play().catch((error) => {
 console.error('Error attempting to play:', error);
 });
 }
 };

 return (
 
 <button>Play Stream</button>
 
 
 );
};

export default Camera;



Note : This component uses the video.js library to play the HLS stream. Make sure to install video.js using npm or yarn :


npm install video.js


Step 2 : Use the Camera Component in Your App


Now, you can use the Camera component in your React app to display the HLS stream. Here's an example of how to use the Camera component :


<camera streamurl="http://localhost:8000/index.m3u8"></camera>


Note : see we are pointing to the HLS stream URL generated by FFmpeg in the previous steps.


Step 3 : Create the Cors Proxy Server and place it where the HLS files are being stored.


from http.server import HTTPServer, SimpleHTTPRequestHandler
import socketserver
import os

class CORSRequestHandler(SimpleHTTPRequestHandler):
 def end_headers(self):
 if self.path.endswith('.m3u8'):
 self.send_header('Content-Type', 'application/vnd.apple.mpegurl')
 elif self.path.endswith('.ts'):
 self.send_header('Content-Type', 'video/MP2T')
 super().end_headers()

if __name__ == '__main__':
 port = 8000
 handler = CORSRequestHandler
 web_dir = r'C:\Video_cam_usv'
 os.chdir(web_dir)
 httpd = socketserver.TCPServer(('', port), handler)
 print(f"Serving HTTP on port {port}")
 httpd.serve_forever()



Note : Change the web_dir to the directory where the HLS files are stored.


Also, note that the server is sending the correct MIME types for .m3u8 and .ts files. For example :


.m3u8 should be application/vnd.apple.mpegurl or application/x-mpegURL.
.ts should be video/MP2T.



Step 4 : Start the CORS Proxy Server


Open a terminal, navigate to the directory where the CORS proxy server script is located (same as the HLS files are being saved), and run the following command :


python cors_proxy_server.py



This will start the CORS proxy server on port 8000 and serve the HLS files with the correct MIME types.


Step 5 : Start the React App
Start your React app using the following command :


npm run dev


I have tried everything above (it´s my own doc to keep with the steps Ive taken so far) and I get the stream to render on my web app but the latency is very high, at least of 5-10 secs, how can i make it be real time or close to that ?


-
9 Form Optimisation Tips to Convert More Visitors
15 février 2024, par Erin