
Recherche avancée
Médias (2)
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (63)
-
List of compatible distributions
26 avril 2011, parThe table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...) -
Configuration spécifique pour PHP5
4 février 2011, parPHP5 est obligatoire, vous pouvez l’installer en suivant ce tutoriel spécifique.
Il est recommandé dans un premier temps de désactiver le safe_mode, cependant, s’il est correctement configuré et que les binaires nécessaires sont accessibles, MediaSPIP devrait fonctionner correctement avec le safe_mode activé.
Modules spécifiques
Il est nécessaire d’installer certains modules PHP spécifiques, via le gestionnaire de paquet de votre distribution ou manuellement : php5-mysql pour la connectivité avec la (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
Sur d’autres sites (7619)
-
On-demand and seamless transcoding of individual HLS segments
5 janvier 2024, par Omid AriyanBackground


I've been meaning to implement on-demand transcoding of certain video formats such as ".mkv", ".wmv", ".mov", etc. in order to serve them on a media management server using ASP.NET Core 6.0, C# and ffmpeg.


My Approach


The approach I've decided to use is to serve a dynamically generated .m3u8 file which is simply generated using a segment duration of choice e.g. 10s and the known video duration. Here's how I've done it. Note that the resolution is currently not implemented and discarded :


public string GenerateVideoOnDemandPlaylist(double duration, int segment)
{
 double interval = (double)segment;
 var content = new StringBuilder();

 content.AppendLine("#EXTM3U");
 content.AppendLine("#EXT-X-VERSION:6");
 content.AppendLine(String.Format("#EXT-X-TARGETDURATION:{0}", segment));
 content.AppendLine("#EXT-X-MEDIA-SEQUENCE:0");
 content.AppendLine("#EXT-X-PLAYLIST-TYPE:VOD");
 content.AppendLine("#EXT-X-INDEPENDENT-SEGMENTS");

 for (double index = 0; (index * interval) < duration; index++)
 {
 content.AppendLine(String.Format("#EXTINF:{0:#.000000},", ((duration - (index * interval)) > interval) ? interval : ((duration - (index * interval)))));
 content.AppendLine(String.Format("{0:00000}.ts", index));
 }

 content.AppendLine("#EXT-X-ENDLIST");

 return content.ToString();
}

[HttpGet]
[Route("stream/{id}/{resolution}.m3u8")]
public IActionResult Stream(string id, string resolution)
{
 double duration = RetrieveVideoLengthInSeconds();
 return Content(GenerateVideoOnDemandPlaylist(duration, 10), "application/x-mpegURL", Encoding.UTF8);
}



Here's an example of how the .m3u8 file looks like :


#EXTM3U
#EXT-X-VERSION:6
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXTINF:10.000000,
00000.ts
#EXTINF:3.386667,
00001.ts
#EXT-X-ENDLIST



So the player would ask for 00000.ts, 00001.ts, etc. and the next step is to have them generated on demand :


public byte[] GenerateVideoOnDemandSegment(int index, int duration, string path)
{
 int timeout = 30000;
 int totalWaitTime = 0;
 int waitInterval = 100;
 byte[] output = Array.Empty<byte>();
 string executable = "/opt/homebrew/bin/ffmpeg";
 DirectoryInfo temp = Directory.CreateDirectory(System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName()));
 string format = System.IO.Path.Combine(temp.FullName, "output-%05d.ts");

 using (Process ffmpeg = new())
 {
 ffmpeg.StartInfo.FileName = executable;

 ffmpeg.StartInfo.Arguments = String.Format("-ss {0} ", index * duration);
 ffmpeg.StartInfo.Arguments += String.Format("-y -t {0} ", duration);
 ffmpeg.StartInfo.Arguments += String.Format("-i \"{0}\" ", path);
 ffmpeg.StartInfo.Arguments += String.Format("-c:v libx264 -c:a aac ");
 ffmpeg.StartInfo.Arguments += String.Format("-segment_time {0} -reset_timestamps 1 -break_non_keyframes 1 -map 0 ", duration);
 ffmpeg.StartInfo.Arguments += String.Format("-initial_offset {0} ", index * duration);
 ffmpeg.StartInfo.Arguments += String.Format("-f segment -segment_format mpegts {0}", format);

 ffmpeg.StartInfo.CreateNoWindow = true;
 ffmpeg.StartInfo.UseShellExecute = false;
 ffmpeg.StartInfo.RedirectStandardError = false;
 ffmpeg.StartInfo.RedirectStandardOutput = false;

 ffmpeg.Start();

 do
 {
 Thread.Sleep(waitInterval);
 totalWaitTime += waitInterval;
 }
 while ((!ffmpeg.HasExited) && (totalWaitTime < timeout));

 if (ffmpeg.HasExited)
 {
 string filename = System.IO.Path.Combine(temp.FullName, "output-00000.ts");

 if (!File.Exists(filename))
 {
 throw new FileNotFoundException("Unable to find the generated segment: " + filename);
 }

 output = File.ReadAllBytes(filename);
 }
 else
 {
 // It's been too long. Kill it!
 ffmpeg.Kill();
 }
 }

 // Remove the temporary directory and all its contents.
 temp.Delete(true);

 return output;
}

[HttpGet]
[Route("stream/{id}/{index}.ts")]
public IActionResult Segment(string id, int index)
{
 string path = RetrieveVideoPath(id);
 return File(GenerateVideoOnDemandSegment(index, 10, path), "application/x-mpegURL", true);
}
</byte>


So as you can see, here's the command I use to generate each segment incrementing -ss and -initial_offset by 10 for each segment :


ffmpeg -ss 0 -y -t 10 -i "video.mov" -c:v libx264 -c:a aac -segment_time 10 -reset_timestamps 1 -break_non_keyframes 1 -map 0 -initial_offset 0 -f segment -segment_format mpegts /var/folders/8h/3xdhhky96b5bk2w2br6bt8n00000gn/T/4ynrwu0q.z24/output-%05d.ts



The Problem


Things work on a functional level, however the transition between segments is slightly glitchy and especially the audio has very short interruptions at each 10 second mark. How can I ensure the segments are seamless ? What can I improve in this process ?


-
Marketing Touchpoints : Examples, KPIs, and Best Practices
11 mars 2024, par Erin -
ffmpeg and streaming video - frame time issue
6 mai 2014, par 4ntoineI’ve compiled ffmpeg-android (https://github.com/appunite/AndroidFFmpeg) and it works for files.
The problem is that it shows nothing for network streams (both rtmp and hls) as frame timestamp is too big and it seems to be not from video beginning (as for file). Then it waits for the first frame time which for network stream is too big :player_decode_video copying...
05-05 18:11:26.994: INFO/player.c(16998): player_decode_video Decoded video frame: 568.233000, time_base: 51140970
05-05 18:11:26.994: INFO/player.c(16998): player_wait_for_frame[0] start
...
05-05 18:11:30.587: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (568.233000) - (0.000977)
05-05 18:11:30.587: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: 568232023
05-05 18:11:31.088: INFO/player.c(16998): player_wait_for_frame[0] timeout
05-05 18:11:31.088: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (568.233000) - (0.501542)
05-05 18:11:31.088: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: 567731458
05-05 18:11:31.588: INFO/player.c(16998): player_wait_for_frame[0] timeout
05-05 18:11:31.588: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (568.233000) - (1.002778)
05-05 18:11:31.588: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: 567230222
05-05 18:11:32.089: INFO/player.c(16998): player_wait_for_frame[0] timeout
05-05 18:11:32.089: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (568.233000) - (1.504563)
05-05 18:11:32.089: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: 566728437
05-05 18:11:32.590: INFO/player.c(16998): player_wait_for_frame[0] timeout
05-05 18:11:32.590: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (568.233000) - (2.005708)
05-05 18:11:32.590: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: 566227292also i can’t figure out what timestamp for frame for network stream means (for file frames it’s a time from video beginning)
for file it’s clear : time_base is frame number and timestamp is time from video beginning and it plays the files :
player_decode_video Decoded video frame: 0.320000, time_base: 8
05-05 18:32:42.344: INFO/player.c(16998): player_wait_for_frame[0] start
05-05 18:32:42.344: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (0.320000) - (0.344337)
05-05 18:32:42.344: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: -24337
05-05 18:32:42.344: INFO/player.c(16998): player_wait_for_frame[0] finish[0]
05-05 18:32:42.344: INFO/player.c(16998): player_update_time: 0.346169/4.000000
05-05 18:32:42.344: INFO/player.c(16998): player_decode waiting for frame[0]
05-05 18:32:42.344: INFO/player.c(16998): player_decode decoding frame[0]
05-05 18:32:42.344: INFO/player.c(16998): player_decode_video decoding
05-05 18:32:42.344: INFO/player.c(16998): player_decode_video copy wait
05-05 18:32:42.344: INFO/player.c(16998): player_read_from_stream Read frame
05-05 18:32:42.344: INFO/player.c(16998): player_read_from_stream looking for stream
05-05 18:32:42.344: INFO/player.c(16998): player_read_from_stream stream found [0]
05-05 18:32:42.344: INFO/player.c(16998): player_read_from_stream waiting for queue
05-05 18:32:42.344: INFO/player.c(16998): Format: WINDOW_FORMAT_RGBA_8888
05-05 18:32:42.344: INFO/player.c(16998): Buffer: width: 1280, height: 720, stride: 1280
05-05 18:32:42.344: INFO/player.c(16998): player_decode_video copying...
05-05 18:32:42.425: INFO/player.c(16998): player_decode_video Decoded video frame: 0.360000, time_base: 9
05-05 18:32:42.425: INFO/player.c(16998): player_wait_for_frame[0] start
05-05 18:32:42.425: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (0.360000) - (0.427994)
05-05 18:32:42.425: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: -67994
05-05 18:32:42.425: INFO/player.c(16998): player_wait_for_frame[0] finish[0]
05-05 18:32:42.425: INFO/player.c(16998): player_update_time: 0.429214/4.000000
05-05 18:32:42.425: INFO/player.c(16998): player_decode waiting for frame[0]
05-05 18:32:42.425: INFO/player.c(16998): player_decode decoding frame[0]
05-05 18:32:42.425: INFO/player.c(16998): player_decode_video decoding
05-05 18:32:42.425: INFO/player.c(16998): player_read_from_stream Read frame
05-05 18:32:42.425: INFO/player.c(16998): player_read_from_stream looking for stream
05-05 18:32:42.425: INFO/player.c(16998): player_read_from_stream stream found [0]
05-05 18:32:42.425: INFO/player.c(16998): player_read_from_stream waiting for queue
05-05 18:32:42.425: INFO/player.c(16998): player_decode_video copy wait
05-05 18:32:42.435: INFO/player.c(16998): Format: WINDOW_FORMAT_RGBA_8888
05-05 18:32:42.435: INFO/player.c(16998): Buffer: width: 1280, height: 720, stride: 1280
05-05 18:32:42.435: INFO/player.c(16998): player_decode_video copying...
05-05 18:32:42.495: INFO/player.c(16998): player_decode_video Decoded video frame: 0.400000, time_base: 10
05-05 18:32:42.495: INFO/player.c(16998): player_wait_for_frame[0] start
05-05 18:32:42.495: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (0.400000) - (0.494742)
05-05 18:32:42.495: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: -94742
05-05 18:32:42.495: INFO/player.c(16998): player_wait_for_frame[0] finish[0]
05-05 18:32:42.495: INFO/player.c(16998): player_update_time: 0.495993/4.000000
05-05 18:32:42.495: INFO/player.c(16998): player_decode waiting for frame[0]
05-05 18:32:42.495: INFO/player.c(16998): player_decode decoding frame[0]
05-05 18:32:42.495: INFO/player.c(16998): player_decode_video decoding
05-05 18:32:42.495: INFO/player.c(16998): player_decode_video copy wait
05-05 18:32:42.495: INFO/player.c(16998): player_read_from_stream Read frame
05-05 18:32:42.495: INFO/player.c(16998): Format: WINDOW_FORMAT_RGBA_8888
05-05 18:32:42.495: INFO/player.c(16998): Buffer: width: 1280, height: 720, stride: 1280
05-05 18:32:42.495: INFO/player.c(16998): player_decode_video copying...
05-05 18:32:42.495: INFO/player.c(16998): player_read_from_stream looking for stream
05-05 18:32:42.495: INFO/player.c(16998): player_read_from_stream stream found [0]
05-05 18:32:42.495: INFO/player.c(16998): player_read_from_stream waiting for queue
05-05 18:32:42.555: INFO/player.c(16998): player_decode_video Decoded video frame: 0.440000, time_base: 11
05-05 18:32:42.555: INFO/player.c(16998): player_wait_for_frame[0] start
05-05 18:32:42.555: INFO/player.c(16998): player_wait_for_frame[0 = Video] = (0.440000) - (0.556698)
05-05 18:32:42.555: INFO/player.c(16998): player_wait_for_frame[0] Waiting for frame: sleeping: -116698
05-05 18:32:42.555: INFO/player.c(16998): player_wait_for_frame[0] finish[0]
05-05 18:32:42.555: INFO/player.c(16998): player_update_time: 0.557858/4.000000
05-05 18:32:42.555: INFO/player.c(16998): player_decode waiting for frame[0]
05-05 18:32:42.555: INFO/player.c(16998): player_read_from_stream Read frame
05-05 18:32:42.555: INFO/player.c(16998): player_read_from_stream looking for stream
05-05 18:32:42.555: INFO/player.c(16998): player_read_from_stream stream found [0]
05-05 18:32:42.555: INFO/player.c(16998): player_read_from_stream waiting for queue
05-05 18:32:42.555: INFO/player.c(16998): player_decode decoding frame[0]
05-05 18:32:42.555: INFO/player.c(16998): player_decode_video decoding
05-05 18:32:42.555: INFO/player.c(16998): player_decode_video copy wait
05-05 18:32:42.565: INFO/player.c(16998): Format: WINDOW_FORMAT_RGBA_8888
05-05 18:32:42.565: INFO/player.c(16998): Buffer: width: 1280, height: 720, stride: 1280
05-05 18:32:42.565: INFO/player.c(16998): player_decode_video copying...
05-05 18:32:42.625: INFO/player.c(16998): player_decode_video Decoded video frame: 0.480000, time_base: 12So what is the meaning of timestamp for stream and what should i change to make it playing streams (rtmp/hls - its can be opened now but it wait for frame time which is far in the future) ?
UPDATE :
int64_t pts = av_frame_get_best_effort_timestamp(frame);
if (pts == AV_NOPTS_VALUE) {
pts = 0;
}
int64_t time = av_rescale_q(pts, stream->time_base, AV_TIME_BASE_Q);
LOGI(10,
"player_decode_video Decoded video frame: %f, time_base: %" SCNd64,
time/1000000.0, pts);
player_wait_for_frame(player, time, stream_no);it extracts time which is far in future :
player_wait_for_frame[0 = Video] = (568.233000) - (0.000977)
Is it correct ?