
Recherche avancée
Autres articles (47)
-
La file d’attente de SPIPmotion
28 novembre 2010, parUne file d’attente stockée dans la base de donnée
Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...) -
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir
Sur d’autres sites (5451)
-
ffmpeg command in my Python code is not working in Docker
12 juin 2024, par Akhil VargheseI am developing a Python (Django-REST) app for video processing. I need to extract the frames of videos and need to save a live stream(RSTP stream) to the desired directory.
I am using
ffmpeg
for saving the RTSP stream, and I have also Dockerized the app.

- 

- Live Stream save method




import subprocess
@api_view(['POST'])
def saveRtsp(request):
 logger.info("Saving RTSP URL")
 rtsp_url = 'rtsp://192.168.1.117/sample2.mkv'
 rtsp_video_path = 'rtsp.mp4'
 try:
 ffmpeg_command = [
 'ffmpeg',
 '-y',
 "-analyzeduration", "20000000",
 "-probesize", "10000000",
 "-rtsp_transport", "tcp",
 "-r", "30",
 "-i", rtsp_url,
 "-c:v", "copy",
 "-b:v", "1M",
 "-c:a", "copy",
 "-b:a", "128k",
 "-f", "mp4",
 rtsp_video_path
 ]
 
 subprocess.run(ffmpeg_command)
 return True
 except Exception as e:
 logger.error(f"Failed to save RTSP URL: {e}")
 return False



This is actually saving a video file in my directory with properties (as shown by "Get Info" in the MacOS Finder) :




As shown in the image, the video doesn't have the resolution and codec information, so it's not compatible with players.


However, If I execute the following command directly in the Docker container shell, I get a compatible video.


A valid video information :




As shown in the image, a compatible video has the Dimension, codecs, and Duration details in the more info section.


ffmpeg -analyzeduration 20000000 -probesize 10000000 -rtsp_transport tcp -r 30 -i rtsp://xx.xx.xx.xx/sample2.mkv -c:v copy -b:v 1M -c:a copy -b:a 128k -f mp4 testoutput2.mp4



My
Dockerfile
is :

FROM python:3.9-slim

# Set environment variables
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
 build-essential \
 ffmpeg \
 libsm6 \
 libxext6 \
 libx264-dev \
 libopencv-dev \
 && apt-get clean

# Copy the requirements file into the container
COPY requirements.txt /app/requirements.txt

# Install Python dependencies
RUN pip install --no-cache-dir -r /app/requirements.txt

# Copy the current directory contents into the container at /app
COPY . /app/

# Expose the port the app runs on
EXPOSE 8000

# Run the Django development server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]



Why does the strange behaviour happen ?
How can I fix this issue ?


I tried using different codecs and even the
ffmpeg-python
library,
but still getting the same result.

-
How can you combine multiple video files with FFMPEG and merging the audio track as well
19 décembre 2023, par CodrutI'm trying to combine multiple MP4 files in Delphi with the FFMPEG video library. I have the headers unit with all the functions. All videos are
MPEG-4
, and so is the destination output file.

I found this question on Stack Overflow asking the same question. To combine video files while keeping the audio and video tracks.
I have translated the answers to Delphi, and while the code is executed successfully, the output file is invalid and cannot be played.


Here is my implementation :


var
 Files: TArray<pansichar>;
 Output: PAnsiChar;

 I, S: integer;

 i_fmt_ctx: PAVFormatContext;
 i_video_stream: PAVStream;
 o_fmt_ctx: PAVFormatContext;
 o_video_stream: PAVStream;

 P: PPAVStream;
begin
 SetLength(Files, 2);
 Files[0] := PAnsiChar('.\Clips\file9.mp4');
 Files[1] := PAnsiChar('.\Clips\file10.mp4');
 Output := '.\Output\out.mp4';

 avcodec_register_all(); 
 av_register_all();

 (* should set to NULL so that avformat_open_input() allocate a new one *)
 i_fmt_ctx := nil;

 if avformat_open_input(@i_fmt_ctx, Files[0], nil, nil) <> 0 then
 raise Exception.Create('Could not open file');

 if avformat_find_stream_info(i_fmt_ctx, nil) < 0 then
 raise Exception.Create('Could not find stream info');
 
 (* Find 1st video stream *)
 i_video_stream := nil;
 P := i_fmt_ctx.streams;
 for i := 0 to i_fmt_ctx.nb_streams-1 do begin
 if P^.codec.codec_type = AVMEDIA_TYPE_VIDEO then
 begin
 i_video_stream := P^;
 Break;
 end;
 Inc(P);
 end;
 if i_video_stream = nil then
 raise Exception.Create('Could not find video stream');

 avformat_alloc_output_context2(@o_fmt_ctx, nil, nil, Output);

 (*
 since all input files are supposed to be identical (framerate, dimension, color format, ...)
 we can safely set output codec values from first input file
 *)
 o_video_stream := avformat_new_stream(o_fmt_ctx, nil);
 
 var c: PAVCodecContext;
 c := o_video_stream.codec;
 c.bit_rate := 400000;
 c.codec_id := i_video_stream.codec.codec_id;
 c.codec_type := i_video_stream.codec.codec_type;
 c.time_base.num := i_video_stream.time_base.num;
 c.time_base.den := i_video_stream.time_base.den;
 //fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den);
 c.width := i_video_stream.codec.width;
 c.height := i_video_stream.codec.height;
 c.pix_fmt := i_video_stream.codec.pix_fmt;
 //printf("%d %d %d", c->width, c->height, c->pix_fmt);
 c.flags := i_video_stream.codec.flags;
 c.flags := c.flags or CODEC_FLAG_GLOBAL_HEADER;
 c.me_range := i_video_stream.codec.me_range;
 c.max_qdiff := i_video_stream.codec.max_qdiff;

 c.qmin := i_video_stream.codec.qmin;
 c.qmax := i_video_stream.codec.qmax;

 c.qcompress := i_video_stream.codec.qcompress;

 c.extradata := i_video_stream.codec.extradata;
 c.extradata_size := i_video_stream.codec.extradata_size;

 avio_open(@o_fmt_ctx.pb, Output, AVIO_FLAG_WRITE);

 (* yes! this is redundant *)
 avformat_close_input(@i_fmt_ctx);

 avformat_write_header(o_fmt_ctx, nil);

 var last_pts: integer; last_pts := 0;
 var last_dts: integer; last_dts := 0;
 for i := 1 to High(Files) do begin
 i_fmt_ctx := nil;

 if avformat_open_input(@i_fmt_ctx, Files[i], nil, nil) <> 0 then
 raise Exception.Create('Could not open input file');

 if avformat_find_stream_info(i_fmt_ctx, nil) < 0 then
 raise Exception.Create('Could not find stream info');

 av_dump_format(i_fmt_ctx, 0, Files[i], 0);
 
 (* we only use first video stream of each input file *)
 i_video_stream := nil;

 P := i_fmt_ctx.streams;
 for S := 0 to i_fmt_ctx.nb_streams-1 do
 begin
 if (P^.codec.codec_type = AVMEDIA_TYPE_VIDEO) then
 begin
 i_video_stream := P^;
 break;
 end;
 
 Inc(P);
 end;

 if i_video_stream = nil then
 raise Exception.Create('Could not find video stream');
 
 var pts, dts: int64;
 pts := 0; dts := 0;
 while true do begin
 var i_pkt: TAVPacket;
 av_init_packet( @i_pkt );
 i_pkt.size := 0;
 i_pkt.data := nil;

 if av_read_frame(i_fmt_ctx, @i_pkt) < 0 then
 break;
 (*
 pts and dts should increase monotonically
 pts should be >= dts
 *)
 i_pkt.flags := i_pkt.flags or AV_PKT_FLAG_KEY;
 pts := i_pkt.pts;
 Inc(i_pkt.pts, last_pts);
 dts := i_pkt.dts;
 Inc(i_pkt.dts, last_dts);
 i_pkt.stream_index := 0;

 // Write
 av_interleaved_write_frame(o_fmt_ctx, @i_pkt);
 end;

 Inc(last_dts, dts);
 Inc(last_pts, pts); 
 
 avformat_close_input(@i_fmt_ctx)
 end;

 av_write_trailer(o_fmt_ctx);

 avcodec_close(o_fmt_ctx.streams^.codec);
 av_freep(&o_fmt_ctx.streams^.codec);
 av_freep(&o_fmt_ctx.streams);

 avio_close(o_fmt_ctx.pb);
 av_free(o_fmt_ctx);
</pansichar>


Which is a translation of
Михаил Чеботарев
's answer.

Even if the code worked, I see no handling of the
AVMEDIA_TYPE_AUDIO
stream, which means this answer is 1/2 of the problem, since It only combines the video stream.

Another approach I tried was using the UBitmaps2Video FFMPEG implementation, which is successfully able to merge the video files, but only the video stream, no audio.


I tried manually converting the audio stream with the Bass Audio Library. It was able to read the audio and write It in a single WAV file, which then I converted to MP3. Finally muxing the combined video file and the MP3 file with
MuxStreams2
. Unfortunately, the audio and video do not align properly. I was unable to pinpoint the issue.

Currently, the only functional option is using the precompiled FFMPEG Executables and using ShellExecute with the according parameters to combine the videos.
This more exactly :


ffmpeg -f concat -safe 0 -i video-list.txt -c copy output.mp4



But I would still rather use the FFMPEG headers in Delphi to combine the videos that way, as that gives the option for Progress indicatiors, more control of the playback and the ability to pause the thread at any point.


So, why does my implementation to merge video files not work. And what is a good method to include the audio stream as well ?


-
Class "FFMpeg\FFMpeg" not found
16 août 2024, par Saeed EisakhaniI installed ffmpeg on xampp by COMPOSER. I installed FFMPEG on windows before.



Then with the command
composer require php-ffmpeg/php-ffmpeg
installed php-ffmpeg


I use code below (from php-ffmpeg github) for a test but this does not work


<?php

require '../../phpMyAdmin/vendor/autoload.php';

$ffmpeg = FFMpeg\FFMpeg::create(); // line 5 that error referees to 
$video = $ffmpeg->open('video.mpg');
$video
 ->filters()
 ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
 ->synchronize();
$video
 ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
 ->save('frame.jpg');
$video
 ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
 ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
 ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');

?>



This is the error I encounter.



I read many and many similar questions but almost all of them suggest
require '../../phpMyAdmin/vendor/autoload.php';
that I have it in my code.