
Recherche avancée
Médias (2)
-
Valkaama DVD Label
4 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
Autres articles (81)
-
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page. -
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
Emballe médias : à quoi cela sert ?
4 février 2011, parCe plugin vise à gérer des sites de mise en ligne de documents de tous types.
Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;
Sur d’autres sites (12794)
-
Split h.264 stream into multiple parts in python
31 janvier 2023, par BillPlayzMy objective is to split an h.264 stream into multiple parts, meaning while reading the stream from a pipe i would like to save it into x second long packages (in my case 10).


I am using a libcamera-vid subprocess on my Raspberry Pi that outputs the h.264 stream into stdout.

Might be irrelevant, depends : libcamera-vid outputs a message every frame and I am able to locate it at isFrameStopLine
To convert the stream, I use an ffmpeg subprocess, as you can see in the code below.

Imagine it like that :

Stream is running...

- Start recording to a file

- Sleep x seconds

- Finish recording to file

- Start recording a new file

- Sleep x seconds

- Finish recording the new file

- and so on...

Here is my current code, however upon running the first export succeeds, and after the second or third the ffmpeg-subprocess is terminating with the error :

pipe:: Invalid data found when processing input

And shortly after, the python process, because of the ffmpeg termination i believe.
Traceback (most recent call last): File "/home/survpi-camera/main.py", line 56, in <module> processStreamLine(readData) File "/home/survpi-camera/main.py", line 16, in processStreamLine streamInfo["process"].stdin.write(data) BrokenPipeError: [Errno 32] Broken pipe</module>


recentStreamProcesses = []
streamInfo = {
 "lastStreamStart": -1,
 "process": None
}

def processStreamLine(data):
 isInfoLine = ((data.startswith(b"[") and (b"INFO" in data)) or (data == b"Preview window unavailable"))
 isFrameStopLine = (data.startswith(b"#") and (b" fps) exp" in data))
 if ((not isInfoLine) and (not isFrameStopLine)):
 streamInfo["process"].stdin.write(data)
 
 if (isFrameStopLine):
 if (time.time() - streamInfo["lastStreamStart"] >= 10):
 print("10 seconds passed, exporting...")
 exportStream()
 createNewStream()

def createNewStream():
 streamInfo["lastStreamStart"] = time.time()
 streamInfo["process"] = subprocess.Popen([
 "ffmpeg",
 "-r","30",
 "-i","-",
 "-c","copy",("/home/survpi-camera/" + str(round(time.time())) + ".mp4")
 ],stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
 print("Created new streamProcess.")

def exportStream():
 print("Exporting...")
 streamInfo["process"].stdin.close()
 recentStreamProcesses.append(streamInfo["process"])


cameraProcess = subprocess.Popen([
 "libcamera-vid",
 "-t","0",
 "--width","1920",
 "--height","1080",
 "--codec","h264",
 "--inline",
 "--listen",
 "-o","-"
],stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.STDOUT)

createNewStream()

while True:
 readData = cameraProcess.stdout.readline()
 
 processStreamLine(readData)



Thank you in advance !


-
FFmpeg remuxing parts of an audio file
22 décembre 2022, par zorleoneI'm trying to remux individual tracks from a FLAC file using the FFmpeg libraries.
I get the starting timestamps from a Cue sheet, I seek to the timestamps using
avformat_seek_file
. However after writing the packets to output files, they only have data from the beginning of the input file.

This is the code snippet which opens the input FLAC and also creates an output
AVFormatContext
for each track. I'm guessing the issue isavformat_seek_file
, it doesn't seem to do anything, since even though I seek to the beginning of a track, the output file contains data from the beginning of the input.

for(int i = 0; i <= sheet.ntracks; i++) {
 sheet.avfmtctx = avformat_alloc_context();
 if(avformat_open_input(&sheet.avfmtctx, sheet.file, NULL, NULL) < 0) {
 fprintf(stderr,
 "avformat_open_input(): failed to open %s\n",
 sheet.file);
 return 1;
 }
 int audio_stream_idx = -1;
 for(int i = 0; i < sheet.avfmtctx->nb_streams; i++) {
 if(sheet.avfmtctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
 audio_stream_idx = i;
 break;
 }
 }
 avformat_find_stream_info(sheet.avfmtctx, NULL);
 AVFormatContext *output;
 char *filepath = title_to_filepath(&sheet.tracks[i], sheet.file);
 avformat_alloc_output_context2(&output, NULL, NULL, filepath);
 AVStream *out_audio_stream = avformat_new_stream(output, NULL);
 avcodec_parameters_copy(out_audio_stream->codecpar,
 sheet.avfmtctx->streams[audio_stream_idx]->codecpar);

 if(avio_open(&output->pb, filepath, AVIO_FLAG_WRITE) < 0) {
 fprintf(stderr, "Failed to open %s for writing\n", filepath);
 return 1;
 }
 if(avformat_write_header(output, NULL) < 0) {
 fprintf(stderr, "avformat_write_header() failed\n");
 return 1;
 }
 int64_t current_frame = sheet.tracks[i].index;
 int64_t next_track_index = (i < sheet.ntracks) ?
 sheet.tracks[i + 1].index :
 INT64_MAX;
 if(avformat_seek_file(sheet.avfmtctx,
 -1,
 INT64_MIN,
 current_frame,
 current_frame,
 0) < 0) {
 fprintf(stderr, "Failed to seek to the index of track %d\n", i);
 avformat_free_context(sheet.avfmtctx);
 sheet.avfmtctx = NULL;
 av_write_trailer(output);
 avio_closep(&output->pb);
 avformat_free_context(output);
 free(filepath);
 continue;
 }
 AVPacket *pkt = av_packet_alloc();
 int64_t pts_diff = AV_NOPTS_VALUE, dts_diff = AV_NOPTS_VALUE;
 while(current_frame < next_track_index && !avio_feof(output->pb)) {
 int ret;
 if((ret = av_read_frame(sheet.avfmtctx, pkt)) < 0) {
 if(ret != AVERROR_EOF)
 fprintf(stderr, "av_read_frame() failed: %s\n", av_err2str(ret));
 break;
 }
 if(pkt->stream_index != audio_stream_idx)
 continue;
 // runs only once
 if(pts_diff == AV_NOPTS_VALUE && dts_diff == AV_NOPTS_VALUE) {
 pts_diff = pkt->pts;
 dts_diff = pkt->dts;
 }

 pkt->stream_index = 0; // first and only stream
 pkt->pts -= pts_diff;
 pkt->dts -= dts_diff;
 pkt->pos = -1;
 av_interleaved_write_frame(output, pkt);

 current_frame++;
 }

 avformat_free_context(sheet.avfmtctx);
 sheet.avfmtctx = NULL;

 av_write_trailer(output);
 av_packet_free(&pkt);
 avio_closep(&output->pb);
 avformat_free_context(output);

 free(filepath);
 }




current_frame
andnext_track_index
are calculated from the INDEX lines in the Cue sheet :MM * 60 * 75 + SS * 75 + FF
.
Can someone tell me what I'm doing wrong, and how to get the data I need from the input ?

-
corrupted video after concat parts of captured RTSP stream with FFMPEG
11 décembre 2022, par 555RussichTarget : capture rtsp stream with sound from intercom camera and save it as 1hour duration video



URL for rtsp stream is updаting every 2 minutes, but i need to get parts with 1hour duration. So i see only solution to concatenate 2 minutes videos. It's required time between capturing stream parts to get response from server and reconnect with another url



First i tried
opencv
. It's not working with sound


Then i started using
ffmpeg
:

Capturing stream :


ffmpeg -rtsp_transport tcp -i 2min_part.mp4





ffmpeg -safe 0 -f concat -i parts_list.txt -c copy concatenated_1.mp4



in stdout getting
Non-monotonous DTS in output stream
:

[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400952, current: 41462297; changing to 57400953. This may result in incorrect timestamps in the output file.
[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400953, current: 41462809; changing to 57400954. This may result in incorrect timestamps in the output file.
[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400954, current: 41463321; changing to 57400955. This may result in incorrect timestamps in the output file.
...



After opening video in media players i see that from one second video is stopped, but sound is going on. Interesting part that with every new opening this second (starting from video stops) changes



Then i tried this solution :


ffmpeg -safe 0 -f concat -segment_time_metadata 1 -i parts_list.txt -vf select=concatdec_select -af aselect=concatdec_select,aresample=async=1 concatenated_2.mp4



No
Non-monotonous DTS
wаrnings, but video is still corrupted like first. Also this solution requires a lot of CPU while first concatenating method is very fast.


Question : How to do concatenating and get not corrupted video ? May be i need to configure capturing options to simply use concatenating with
-c copy
?

parts of videos and concatenated


using
exiftool concatenated_1.mp4
i see that :

Duration : 1:17:44
Track Duration : 1:17:44
Media Duration : 0:53:59