
Recherche avancée
Médias (1)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
Autres articles (111)
-
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 est la première version de MediaSPIP stable.
Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Mise à disposition des fichiers
14 avril 2011, parPar défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...) -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)
Sur d’autres sites (9629)
-
ERROR "Application provided invalid, non monotonically increasing dts to muxer in stream 1 : 6874 >= 6874" while writing encoded output to an mp4 file
11 mai 2023, par lokit khemkaI have a running RTSP stream, streaming video on a loop using the following FFMPEG command :


ffmpeg -re -stream_loop -1 -i ./ffmpeg_c_test/small_bunny_1080p_60fps.mp4 -ac 2 -f rtsp -rtsp_transport tcp rtsp://localhost:8554/mystream



The video file is obtained from the github link : https://github.com/leandromoreira/ffmpeg-libav-tutorial


I keep getting error response, when I calling the function
av_interleaved_write_frame
called from the functionremux
in the attached program. The output format ismp4
, output video codec isav1
and output audio codec is same as input audio codec. The error is from audio stream.

I tried to create a "minimal reproducible code", however, I think it is still not completely minimal, but it reproduces the exact error.


#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>timestamp.h>
#include <libavutil></libavutil>opt.h>
#include <libswscale></libswscale>swscale.h>
#include 
#include 
#include 

#include 
#include 

typedef struct StreamingContext{
 AVFormatContext* avfc;
 const AVCodec *video_avc;
 const AVCodec *audio_avc;
 AVStream *video_avs;
 AVStream *audio_avs;
 AVCodecContext *video_avcc;
 AVCodecContext *audio_avcc;
 int video_index;
 int audio_index;
 char* filename;
 struct SwsContext *sws_ctx;
}StreamingContext;


typedef struct StreamingParams{
 char copy_video;
 char copy_audio;
 char *output_extension;
 char *muxer_opt_key;
 char *muxer_opt_value;
 char *video_codec;
 char *audio_codec;
 char *codec_priv_key;
 char *codec_priv_value;
}StreamingParams;

void logging(const char *fmt, ...)
{
 va_list args;
 fprintf(stderr, "LOG: ");
 va_start(args, fmt);
 vfprintf(stderr, fmt, args);
 va_end(args);
 fprintf(stderr, "\n");
}

int fill_stream_info(AVStream *avs, const AVCodec **avc, AVCodecContext **avcc)
{
 *avc = avcodec_find_decoder(avs->codecpar->codec_id);
 *avcc = avcodec_alloc_context3(*avc);
 if (avcodec_parameters_to_context(*avcc, avs->codecpar) < 0)
 {
 logging("Failed to fill Codec Context.");
 return -1;
 }
 avcodec_open2(*avcc, *avc, NULL);
 return 0;
}

int open_media(const char *in_filename, AVFormatContext **avfc)
{
 *avfc = avformat_alloc_context();
 if (avformat_open_input(avfc, in_filename, NULL, NULL) != 0)
 {
 logging("Failed to open input file %s", in_filename);
 return -1;
 }

 if (avformat_find_stream_info(*avfc, NULL) < 0)
 {
 logging("Failed to get Stream Info.");
 return -1;
 }
}

int prepare_decoder(StreamingContext *sc)
{
 for (int i = 0; i < (int)sc->avfc->nb_streams; i++)
 {
 if (sc->avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 sc->video_avs = sc->avfc->streams[i];
 sc->video_index = i;

 if (fill_stream_info(sc->video_avs, &sc->video_avc, &sc->video_avcc))
 {
 return -1;
 }
 }
 else if (sc->avfc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
 {
 sc->audio_avs = sc->avfc->streams[i];
 sc->audio_index = i;

 if (fill_stream_info(sc->audio_avs, &sc->audio_avc, &sc->audio_avcc))
 {
 return -1;
 }
 }
 else
 {
 logging("Skipping Streams other than Audio and Video.");
 }
 }
 return 0;
}

int prepare_video_encoder(StreamingContext *encoder_sc, AVCodecContext *decoder_ctx, AVRational input_framerate,
 StreamingParams sp, int scaled_frame_width, int scaled_frame_height)
{
 encoder_sc->video_avs = avformat_new_stream(encoder_sc->avfc, NULL);
 encoder_sc->video_avc = avcodec_find_encoder_by_name(sp.video_codec);
 if (!encoder_sc->video_avc)
 {
 logging("Cannot find the Codec.");
 return -1;
 }

 encoder_sc->video_avcc = avcodec_alloc_context3(encoder_sc->video_avc);
 if (!encoder_sc->video_avcc)
 {
 logging("Could not allocate memory for Codec Context.");
 return -1;
 }

 av_opt_set(encoder_sc->video_avcc->priv_data, "preset", "fast", 0);
 if (sp.codec_priv_key && sp.codec_priv_value)
 av_opt_set(encoder_sc->video_avcc->priv_data, sp.codec_priv_key, sp.codec_priv_value, 0);

 encoder_sc->video_avcc->height = scaled_frame_height;
 encoder_sc->video_avcc->width = scaled_frame_width;
 encoder_sc->video_avcc->sample_aspect_ratio = decoder_ctx->sample_aspect_ratio;

 if (encoder_sc->video_avc->pix_fmts)
 encoder_sc->video_avcc->pix_fmt = encoder_sc->video_avc->pix_fmts[0];
 else
 encoder_sc->video_avcc->pix_fmt = decoder_ctx->pix_fmt;

 encoder_sc->video_avcc->bit_rate = 2 * 1000 * 1000;

 encoder_sc->video_avcc->time_base = av_inv_q(input_framerate);
 encoder_sc->video_avs->time_base = encoder_sc->video_avcc->time_base;

 

 if (avcodec_open2(encoder_sc->video_avcc, encoder_sc->video_avc, NULL) < 0)
 {
 logging("Could not open the Codec.");
 return -1;
 }
 avcodec_parameters_from_context(encoder_sc->video_avs->codecpar, encoder_sc->video_avcc);
 return 0;
}


int prepare_copy(AVFormatContext *avfc, AVStream **avs, AVCodecParameters *decoder_par)
{
 *avs = avformat_new_stream(avfc, NULL);
 avcodec_parameters_copy((*avs)->codecpar, decoder_par);
 return 0;
}

int encode_video(StreamingContext *decoder, StreamingContext *encoder, AVFrame *input_frame)
{
 if (input_frame)
 input_frame->pict_type = AV_PICTURE_TYPE_NONE;

 AVPacket *output_packet = av_packet_alloc();


 int response = avcodec_send_frame(encoder->video_avcc, input_frame);

 while (response >= 0)
 {
 response = avcodec_receive_packet(encoder->video_avcc, output_packet);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }

 output_packet->stream_index = decoder->video_index;
 output_packet->duration = encoder->video_avs->time_base.den / encoder->video_avs->time_base.num;

 av_packet_rescale_ts(output_packet, decoder->video_avs->time_base, encoder->video_avs->time_base);
 response = av_interleaved_write_frame(encoder->avfc, output_packet);
 }

 av_packet_unref(output_packet);
 av_packet_free(&output_packet);

 return 0;
}

int remux(AVPacket **pkt, AVFormatContext **avfc, AVRational decoder_tb, AVRational encoder_tb)
{
 (*pkt)->duration = av_rescale_q((*pkt)->duration, decoder_tb, encoder_tb);
 (*pkt)->pos = -1;
 av_packet_rescale_ts(*pkt, decoder_tb, encoder_tb);
 if (av_interleaved_write_frame(*avfc, *pkt) < 0)
 {
 logging("Error while copying Stream Packet.");
 return -1;
 }
 return 0;
}

int transcode_video(StreamingContext *decoder, StreamingContext *encoder, AVPacket *input_packet, AVFrame *input_frame)
{
 int response = avcodec_send_packet(decoder->video_avcc, input_packet);
 while (response >= 0)
 {
 response = avcodec_receive_frame(decoder->video_avcc, input_frame);
 
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
 {
 break;
 }
 if (response >= 0)
 {
 if (encode_video(decoder, encoder, input_frame))
 return -1;
 }

 av_frame_unref(input_frame);
 }
 return 0;
}

int main(int argc, char *argv[])
{
 const int scaled_frame_width = 854;
 const int scaled_frame_height = 480;
 StreamingParams sp = {0};
 sp.copy_audio = 1;
 sp.copy_video = 0;
 sp.video_codec = "libsvtav1";
 
 StreamingContext *decoder = (StreamingContext *)calloc(1, sizeof(StreamingContext));
 decoder->filename = "rtsp://localhost:8554/mystream";

 StreamingContext *encoder = (StreamingContext *)calloc(1, sizeof(StreamingContext));
 encoder->filename = "small_bunny_9.mp4";
 
 if (sp.output_extension)
 {
 strcat(encoder->filename, sp.output_extension);
 }

 open_media(decoder->filename, &decoder->avfc);
 prepare_decoder(decoder);


 avformat_alloc_output_context2(&encoder->avfc, NULL, "mp4", encoder->filename);
 AVRational input_framerate = av_guess_frame_rate(decoder->avfc, decoder->video_avs, NULL);
 prepare_video_encoder(encoder, decoder->video_avcc, input_framerate, sp, scaled_frame_width, scaled_frame_height);

 prepare_copy(encoder->avfc, &encoder->audio_avs, decoder->audio_avs->codecpar);
 

 if (encoder->avfc->oformat->flags & AVFMT_GLOBALHEADER)
 encoder->avfc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

 if (!(encoder->avfc->oformat->flags & AVFMT_NOFILE))
 {
 if (avio_open(&encoder->avfc->pb, encoder->filename, AVIO_FLAG_WRITE) < 0)
 {
 logging("could not open the output file");
 return -1;
 }
 }

 
 if (avformat_write_header(encoder->avfc, NULL) < 0)
 {
 logging("an error occurred when opening output file");
 return -1;
 }

 AVFrame *input_frame = av_frame_alloc();
 AVPacket *input_packet = av_packet_alloc();

 while (1)
 {
 int ret = av_read_frame(decoder->avfc, input_packet);
 if(ret<0)
 break;
 if (decoder->avfc->streams[input_packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 if (transcode_video(decoder, encoder, input_packet, input_frame))
 return -1;
 av_packet_unref(input_packet);

 }
 else if (decoder->avfc->streams[input_packet->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
 {
 
 if (remux(&input_packet, &encoder->avfc, decoder->audio_avs->time_base, encoder->audio_avs->time_base))
 return -1;
 }
 else
 {
 logging("Ignoring all nonvideo or audio packets.");
 }
 }

 if (encode_video(decoder, encoder, NULL))
 return -1;
 

 av_write_trailer(encoder->avfc);


 if (input_frame != NULL)
 {
 av_frame_free(&input_frame);
 input_frame = NULL;
 }

 if (input_packet != NULL)
 {
 av_packet_free(&input_packet);
 input_packet = NULL;
 }

 avformat_close_input(&decoder->avfc);

 avformat_free_context(decoder->avfc);
 decoder->avfc = NULL;
 avformat_free_context(encoder->avfc);
 encoder->avfc = NULL;

 avcodec_free_context(&decoder->video_avcc);
 decoder->video_avcc = NULL;
 avcodec_free_context(&decoder->audio_avcc);
 decoder->audio_avcc = NULL;

 free(decoder);
 decoder = NULL;
 free(encoder);
 encoder = NULL;

 return 0;
}




-
How to modify the bit_rate of AVFormatContext ?
27 mars 2023, par Zion LiuHello,I would like to know how to modify the bit_rate of AVFormatContext.


Here is the minimal reproducible example.This is a simple process for pushing rtmp video streams.Now I want to control the bitrate of the video it pushes.


I tried modifying the bitrate like this, but it didn't work.


AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
int64_t bit_rate = 400*1000;
....
ofmt_ctx->bit_rate = bit_rate;



Can be compiled by
g++ -Wall -o -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -L/usr/local/lib simplt_push_streaming.cpp -o test.out -lavformat -lavcodec -lavutil -lgobject-2.0 -lglib-2.0 -lpthread


And my ffmpeg version :
ffmpeg version 4.4.2-0ubuntu0.22.04.1


#include 
extern "C"
{
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>mathematics.h>
#include <libavutil></libavutil>time.h>
};

int main(int argc, char* argv[])
{
 AVOutputFormat *ofmt = NULL;
 //Input AVFormatContext and Output AVFormatContext
 AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
 AVPacket pkt;
 const char *in_filename, *out_filename;
 int ret, i;
 int videoindex=-1;
 int frame_index=0;
 int64_t start_time=0;
 int64_t bit_rate = 400*1000;
 in_filename = "/home/zion/video/mecha.flv";// Input file URL
 out_filename = "rtmp://localhost:1935/live/test";//Output URL [RTMP]
 av_register_all();
 avformat_network_init();
 avformat_open_input(&ifmt_ctx, in_filename, 0, 0);
 avformat_find_stream_info(ifmt_ctx, 0);
 for(i=0; inb_streams; i++) 
 if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
 videoindex=i;
 break;
 }
 //Output
 avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", out_filename); //RTMP
 ofmt = ofmt_ctx->oformat;
 for (i = 0; i < ifmt_ctx->nb_streams; i++) {
 //Create output AVStream according to input AVStream
 AVStream *in_stream = ifmt_ctx->streams[i];
 AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
 //Copy the settings of AVCodecContext
 ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
 out_stream->codec->codec_tag = 0;
 if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
 out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }
 //Open output URL
 if (!(ofmt->flags & AVFMT_NOFILE)) {
 ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
 }
 //Write file header
 avformat_write_header(ofmt_ctx, NULL);
 start_time=av_gettime();
 while (1) {
 AVStream *in_stream, *out_stream;
 //Get an AVPacket
 ret = av_read_frame(ifmt_ctx, &pkt);
 if (ret < 0)
 break;
 //Important:Delay
 if(pkt.stream_index==videoindex){
 AVRational time_base=ifmt_ctx->streams[videoindex]->time_base;
 AVRational time_base_q={1,AV_TIME_BASE};
 int64_t pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 int64_t now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 av_usleep(pts_time - now_time);
 }
 in_stream = ifmt_ctx->streams[pkt.stream_index];
 out_stream = ofmt_ctx->streams[pkt.stream_index];
 if(pkt.stream_index==videoindex){
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
/*I tried modifying the bitrate here and I'm not sure if this is the correct usage.*/
 ofmt_ctx->bit_rate = bit_rate;
 av_interleaved_write_frame(ofmt_ctx, &pkt);
 av_free_packet(&pkt);
 }
 //Write file trailer
 av_write_trailer(ofmt_ctx);
end:
 avformat_close_input(&ifmt_ctx);
 /* close output */
 if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
 avio_close(ofmt_ctx->pb);
 avformat_free_context(ofmt_ctx);
 return 0;
}



-
Puzzled with file descriptor in Bash (ffmpeg video capture)
3 mai 2020, par ChrisAgaI am trying to use file descriptors in Bash and found a problem I cannot solve.
I have to read a video stream coming from the standard output of a command executed in a
coproc
. This piece of code works as expected :


ffmpeg \
 -i <(exec cat <&${COPROC[0]}) \
 -c:v $ENCODE_VIDEO_FORMAT_LOSSLESS $ENCODE_VIDEO_OPTIONS_LOSSLESS \
 -c:a copy \
 -progress /dev/fd/1 \
 "${capfile}"




But the
cat
process is not really useful sinceffmpeg -i pipe:<file descriptor="descriptor"></file>
seems to do the same. So I tried the following code which fails withpipe:63: Bad file descriptor

error.


ffmpeg \
 -i pipe:"${COPROC[0]}" \
 -c:v $ENCODE_VIDEO_FORMAT_LOSSLESS $ENCODE_VIDEO_OPTIONS_LOSSLESS \
 -c:a copy \
 -progress /dev/fd/1 \
 "${capfile}"




The actual script is something a bit complicated but here is a minimal testing code for this issue :



#!/bin/bash
#

ENCODE_VIDEO_FORMAT_LOSSLESS=ffv1
ENCODE_VIDEO_OPTIONS_LOSSLESS="-level 3 -threads 7 -coder 1 -context 1 -g 1 -slices 30 -slicecrc 1"

capfile=capure.mkv

coproc ffmpeg -i file:'Camomille.mkv' -c:v copy -c:a copy -f matroska pipe:1

capture_fd=${COPROC[0]}
echo "hk_capture_pid=${COPROC_PID}"

ffmpeg \
 -i pipe:${COPROC[0]} \
 -c:v $ENCODE_VIDEO_FORMAT_LOSSLESS $ENCODE_VIDEO_OPTIONS_LOSSLESS \
 -c:a copy \
 -progress /dev/fd/1 \
 "${capfile}"




This is the output of the second
ffmpeg
command :


ffmpeg version 4.1.4-1build2 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 9 (Ubuntu 9.2.1-4ubuntu1)
 configuration: --prefix=/usr --extra-version=1build2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 22.100 / 56. 22.100
 libavcodec 58. 35.100 / 58. 35.100
 libavformat 58. 20.100 / 58. 20.100
 libavdevice 58. 5.100 / 58. 5.100
 libavfilter 7. 40.101 / 7. 40.101
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 3.100 / 5. 3.100
 libswresample 3. 3.100 / 3. 3.100
 libpostproc 55. 3.100 / 55. 3.100
pipe:63: Bad file descriptor
av_interleaved_write_frame(): Broken pipe 
Error writing trailer of pipe:1: Broken pipe 
frame= 4 fps=0.0 q=-1.0 Lsize= 48kB time=00:00:00.03 bitrate=10051.1kbits/s speed=3.44x 
video:86kB audio:1kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: unknown
Conversion failed!




This one fails and if you replace
-i pipe:${COPROC[0]}
by-i <(exec cat <&${COPROC[0]})
a capture.mkv file is created.


I run ubuntu eoan and bash version is :
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
. I upgraded several times since I started with this issue, so it wouldn't be related too much to bash and ffmpeg versions.


If someone can point me to what I do wrong with bash file descriptors I would be grateful.