
Recherche avancée
Médias (1)
-
Revolution of Open-source and film making towards open film making
6 octobre 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (73)
-
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. -
Participer à sa traduction
10 avril 2011Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
Actuellement MediaSPIP n’est disponible qu’en français et (...) -
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 (...)
Sur d’autres sites (14244)
-
Crash on ffmpeg avcodec_encode_video in a Console app
5 mars 2013, par Robel sharmaI want make an encoder which encode a raw image into h263 format.But after loading and initializing ffmpeg library I got crash on avcodec_encode_video for a demo image.
int _tmain(int argc, _TCHAR* argv[]) {
avcodec_register_all();
AVCodec *codec;
AVCodecContext *c= NULL;
int i, ret, x, y, got_output;
FILE *f;
AVFrame *frame;
AVPacket pkt;
int out_size, size, outbuf_size;
AVFrame *picture;
uint8_t *outbuf, *picture_buf;
AVRational rp;
rp.den = 1;
rp.num = 25;
uint8_t endcode[] = { 0, 0, 1, 0xb7 };
codec = avcodec_find_encoder(CODEC_ID_H263);
c = avcodec_alloc_context3(codec);
picture= avcodec_alloc_frame();
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
/* frames per second */
//c->time_base= (AVRational){1,25};
c->time_base = rp;
c->gop_size = 10; /* emit one intra frame every ten frames */
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;
avcodec_open(c, codec);
outbuf_size = 100000;
outbuf = (uint8_t*)malloc(outbuf_size);
size = c->width * c->height;
picture_buf = (uint8_t*)malloc((size * 3) / 2); /* size for YUV 420 */
picture->data[0] = picture_buf;
picture->data[1] = picture->data[0] + size;
picture->data[2] = picture->data[1] + size / 4;
picture->linesize[0] = c->width;
picture->linesize[1] = c->width / 2;
picture->linesize[2] = c->width / 2;
/* encode 1 second of video */
for(i=0;i<25;i++) {
fflush(stdout);
/* prepare a dummy image */
/* Y */
for(y=0;yheight;y++) {
for(x=0;xwidth;x++) {
picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
}
}
/* Cb and Cr */
for(y=0;yheight/2;y++) {
for(x=0;xwidth/2;x++) {
picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
}
}
/* encode the image */
**Crash is here** ---> ///////////////////////////////////////////////////
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
printf("encoding frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
}
/* get the delayed frames */
for(; out_size; i++) {
fflush(stdout);
out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
printf("write frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
}
/* add sequence end code to have a real mpeg file */
outbuf[0] = 0x00;
outbuf[1] = 0x00;
outbuf[2] = 0x01;
outbuf[3] = 0xb7;
fwrite(outbuf, 1, 4, f);
fclose(f);
free(picture_buf);
free(outbuf);
avcodec_close(c);
av_free(c);
av_free(picture);
printf("\n");
return 0;
} -
FFMPEG Segmenting skips when m3u8 changes file
25 septembre 2012, par user792164I am attempting to segment a large video file in to segments. When streamed (even locally) by opening the m3u8 file it will jump forward in time by some period of time less than 1 second.
The following commands are executed :
First mp4 —> ts :
ffmpeg -i input_file.mp4 -bsf:v h264_mp4toannexb -acodec libfaac -vcodec libx264 -f mpegts -threads 0 output.ts
Then I split using :
ffmpeg -i output.ts -vcodec copy -acodec copy -map 0 -f segment -segment_time 30 -segment_list output.m3u8 -segment_list_type m3u8 -segment_format mpegts output%03d.ts
Note : Changing segment time has no effect on issue.
Generated manifest :
#EXTM3U
#EXT-X-VERSION:4
#EXTINF:30.947578,
output000.ts
#EXTINF:30.155111,
output001.ts
...
#EXTINF:24.023989,
output082.ts
#EXT-X-TARGETDURATION:37
#EXT-X-ENDLIST
Meta Data :
$> ffmpeg -version
ffmpeg version git-2012-08-19-a93c221
built on Aug 19 2012 13:18:58 with gcc 4.4.5 (Debian 4.4.5-8)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib/ --mandir=/usr/share/man --extra-cflags='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions \ -fstack-protector --param=ssp-buffer-size=4 -mtune=generic' --enable-gpl --enable-shared --enable-nonfree --enable-version3 --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-pthreads --enable-libxvid --enable-postproc --enable-libgsm --enable-libspeex --enable-avfilter --disable-decoder=libdirac --enable-libfreetype --enable-libschroedinger --disable-decoder=libschroedinger --enable-libopenjpeg --disable-ffplay --disable-ffserver
libavutil 51. 70.100 / 51. 70.100
libavcodec 54. 53.100 / 54. 53.100
libavformat 54. 25.104 / 54. 25.104
libavdevice 54. 2.100 / 54. 2.100
libavfilter 3. 11.101 / 3. 11.101
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100-
$> ffprobe input_file.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_file.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isom
creation_time : 2011-09-08 11:43:25
Duration: 00:41:31.00, start: 0.000000, bitrate: 1146 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 720x404 [PAR 1:1 DAR 180:101], 1015 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc
Metadata:
creation_time : 2011-09-08 11:43:25
Stream #0.1(und): Audio: aac, 48000 Hz, stereo, s16, 124 kb/s
Metadata:
creation_time : 2011-09-08 11:43:25-
$> ffprobe output_file.ts
Input #0, mpegts, from 'output_file.ts':
Duration: 00:41:30.98, start: 1.400000, bitrate: 807 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0.0[0x100]: Video: h264 (High), yuv420p, 720x404 [PAR 1:1 DAR 180:101], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
Stream #0.1[0x101](und): Audio: aac, 48000 Hz, stereo, s16, 141 kb/
Is it possible to remove this jump, if so, what encoding parameters or incorrect assumptions have I made ? Thanks.
-
closed (H264 track 1 is not valid : sprop-parameter-sets is missing (96 packetization-mode=1)
8 janvier 2024, par MMingYI used FFmpeg6.1 to stream RTSP, but I received the following errors on the server :




closed (H264 track 1 is not valid : sprop-parameter-sets is missing (96 packetization-mode=1),client:Error occurred when opening output Server returned 400 Bad Request.




#include 
#include 
#include 

#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>
#include <libavutil></libavutil>time.h>

static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
 AVFormatContext *outFormatCtx) {
 int ret;

 /* send the frame to the encoder */
 if (frame)
 printf("Send frame %3"PRId64"\n", frame->pts);

 ret = avcodec_send_frame(enc_ctx, frame);
 if (ret < 0) {
 char errbuf[AV_ERROR_MAX_STRING_SIZE];
 av_strerror(ret, errbuf, AV_ERROR_MAX_STRING_SIZE);
 fprintf(stderr, "Error sending a frame for encoding ,%s\n", errbuf);
 exit(1);
 }

 while (ret >= 0) {
 ret = avcodec_receive_packet(enc_ctx, pkt);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 return;
 else if (ret < 0) {
 fprintf(stderr, "Error during encoding\n");
 exit(1);
 }

 printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
 av_write_frame(outFormatCtx, pkt); // Write the packet to the RTMP stream
 av_packet_unref(pkt);
 }
}

int main(int argc, char **argv) {
 av_log_set_level(AV_LOG_DEBUG);
 const char *rtmp_url, *codec_name;
 const AVCodec *codec;
 AVCodecContext *codecContext = NULL;
 int i, ret, x, y;
 AVFormatContext *outFormatCtx;
 AVStream *st;
 AVFrame *frame;
 AVPacket *pkt;
 uint8_t endcode[] = {0, 0, 1, 0xb7};

 if (argc <= 3) {
 fprintf(stderr, "Usage: %s <rtmp url="url"> <codec>\n", argv[0]);
 exit(0);
 }
 rtmp_url = argv[1];
 codec_name = argv[2];
 avformat_network_init();
 /* find the mpeg1video encoder */
// codec = avcodec_find_encoder_by_name(codec_name);
// codec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);
// codec = avcodec_find_encoder(AV_CODEC_ID_VP9);
// codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);
 codec = avcodec_find_encoder(AV_CODEC_ID_H264);
// codec = avcodec_find_encoder(AV_CODEC_ID_AV1);
// codec = avcodec_find_encoder(AV_CODEC_ID_H265);
 if (!codec) {
 fprintf(stderr, "Codec '%s' not found\n", codec_name);
 exit(1);
 }
 codecContext = avcodec_alloc_context3(codec);
 if (!codecContext) {
 fprintf(stderr, "Could not allocate video codec context\n");
 exit(1);
 }

 /* ... (rest of the setup code) ... */
/* put sample parameters */
 codecContext->bit_rate = 400000;
 /* resolution must be a multiple of two */
 codecContext->width = 352;
 codecContext->height = 288;
 /* frames per second */
 codecContext->time_base = (AVRational) {1, 25};
 codecContext->framerate = (AVRational) {25, 1};

 /* emit one intra frame every ten frames
 * check frame pict_type before passing frame
 * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
 * then gop_size is ignored and the output of encoder
 * will always be I frame irrespective to gop_size
 */
 codecContext->gop_size = 10;
 codecContext->max_b_frames = 1;
 codecContext->pix_fmt = AV_PIX_FMT_YUV420P;



 /* Open the RTSP output */
// const AVOutputFormat *ofmt = av_guess_format("tcp", NULL, NULL);
 const AVOutputFormat *ofmt = av_guess_format("rtsp", rtmp_url, NULL);
// const AVOutputFormat *ofmt = av_guess_format("flv", NULL, NULL);
// const AVOutputFormat *ofmt = av_guess_format("rtmp", NULL, NULL);
// const AVOutputFormat *ofmt = av_guess_format("mpegts", NULL, NULL);
// const AVOutputFormat *ofmt = av_guess_format("mp4", NULL, NULL);
 if (!ofmt) {
 fprintf(stderr, "Could not find output format\n");
 exit(1);
 }

 /* Allocate the output context */

/* outFormatCtx = avformat_alloc_context();
 if (!outFormatCtx) {
 fprintf(stderr, "Could not allocate output context\n");
 exit(1);
 }*/

 // 打开输出 这个会导致outFormatCtx 中的stream 为空,并且产生这个问题[rtsp @ 00000204f6218b80] No streams to mux were specified
 if (avformat_alloc_output_context2(&outFormatCtx, ofmt, "rtsp", rtmp_url) != 0) {
 fprintf(stderr, "Could not allocate output context\n");
 return 1;
 }


 outFormatCtx->oformat = ofmt;
 outFormatCtx->url = av_strdup(rtmp_url);

 /* Add a video stream */
 st = avformat_new_stream(outFormatCtx, codec);
 if (!st) {
 fprintf(stderr, "Could not allocate stream\n");
 exit(1);
 }
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 st->codecpar->codec_id = codec->id;
 st->codecpar->width = 352;
 st->codecpar->height = 288;
 st->codecpar->format = AV_PIX_FMT_YUV420P;
// st->codecpar = c;
// st->codecpar->format = AV_PIX_FMT_YUV420P;
 // Set video stream parameters
// st->codecpar->framerate = (AVRational) {25, 1};
// st->id=outFormatCtx->nb_streams-1;
 /* Set the output URL */
 av_dict_set(&outFormatCtx->metadata, "url", rtmp_url, 0);


 pkt = av_packet_alloc();
 if (!pkt)
 exit(1);


 if (codec->id == AV_CODEC_ID_H264)
 av_opt_set(codecContext->priv_data, "preset", "slow", 0);

 AVDictionary *opt = NULL;
/* av_dict_set(&opt, "rtsp_transport", "udp", 0);
 av_dict_set(&opt, "announce_port", "1935", 0);
 av_dict_set(&opt, "enable-protocol", "rtsp", 0);
 av_dict_set(&opt, "protocol_whitelist", "file,udp,tcp,rtp,rtsp", 0);
 av_dict_set(&opt, "enable-protocol", "rtp", 0);
 av_dict_set(&opt, "enable-protocol", "rtsp", 0);
 av_dict_set(&opt, "enable-protocol", "udp", 0);
 av_dict_set(&opt, "enable-muxer", "rtsp", 0);
 av_dict_set(&opt, "enable-muxer", "rtp", 0);*/
 av_dict_set(&opt, "rtsp_transport", "tcp", 0);
 av_dict_set(&opt, "stimeout", "2000000", 0);
 av_dict_set(&opt, "max_delay", "500000", 0);
 av_dict_set(&opt, "sprop-parameter-sets", "asdgasdfs", AV_DICT_APPEND);
 /* open it */
 ret = avcodec_open2(codecContext, codec, &opt);
 if (ret < 0) {
 fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
 exit(1);
 }
/* // 打开RTSP输出URL 微软AI给出的代码
 if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE)) {
 int ret = avio_open(&outFormatCtx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (ret < 0) {
// std::cerr << "Could not open output URL " << out_url << std::endl;
 fprintf(stderr, "Could not open output URL %s\n", av_err2str(ret));
 return -1;
 }
 }*/

 avcodec_parameters_to_context(codecContext, st->codecpar);

/* AVDictionary *options = NULL;
 av_dict_set(&options, "rtsp_transport", "tcp", 0);
 av_dict_set(&options, "stimeout", "2000000", 0);
 av_dict_set(&options, "max_delay", "500000", 0);
 // 初始化输出
 av_dict_set(&options, "rtsp_transport", "tcp", 0);
//设置 接收包间隔最大延迟,微秒
 av_dict_set(&options, "max_delay", "200000", 0);
// rtmp、rtsp延迟控制到最小
 av_dict_set(&options, "fflags", "nobuffer", 0);
// 在进行网络操作时允许的最大等待时间。5秒
 av_dict_set(&options, "timeout", "5000000", 0);
//设置 阻塞超时,否则可能在流断开时连接发生阻塞,微秒
 av_dict_set(&options, "stimeout", "3000000", 0);
//设置 find_stream_info 最大时长,微秒
 av_dict_set(&options, "analyzeduration", "1000000", 0);*/
 av_dict_set(&opt, "preset", "medium", 0);
 av_dict_set(&opt, "tune", "zerolatency", 0);
 av_dict_set(&opt, "profile", "baseline", 0);
 av_dump_format(outFormatCtx, 0, rtmp_url, 1);

 if (avformat_init_output(outFormatCtx, &opt) != 0) {
 fprintf(stderr, "Error initializing output\n");
 return 1;
 }
 if (!(ofmt->flags & AVFMT_NOFILE)) {
 ret = avio_open(&outFormatCtx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (ret < 0) {
 fprintf(stderr, "Could not open output file '%s'", rtmp_url);
 exit(1);
 }
 }
 /* 这种方式修改没有效果,无法添加修改SDP
 * av_dict_set(&st->metadata, "title", "Cool video", 0);
 av_dict_set(&st->metadata, "Content-Base", " rtsp://10.45.12.141/h264/ch1/main/av_stream/", 0);
 av_dict_set(&st->metadata, "sprop-parameter-sets", "sdsfwedeo", 0);*/
 AVCodecParameters *codecParams = st->codecpar;
 const char *spropParameterSets = "Z0IACpZTBYmI,aMlWsA=="; // 替换为实际的sprop-parameter-sets值
 av_dict_set(&st->metadata, "sprop-parameter-sets", spropParameterSets, 0);
 avcodec_parameters_to_context(codecContext, st->codecpar);
 AVFormatContext *avFormatContext[1];
 avFormatContext[0] = outFormatCtx;
 char spd[2048];
 av_sdp_create(avFormatContext, 1, spd, sizeof(spd));
 printf("%s\n", spd);
/* ret = avio_open(&outFormatCtx->pb, rtmp_url, AVIO_FLAG_WRITE);
 if (ret < 0) {
 fprintf(stderr, "Could not open output ,%s\n", av_err2str(ret));
 exit(1);
 }*/

/*// 设置 H264 参数
 AVDictionary *params = NULL;
 av_dict_set(&params, "profile", "main", 0);
 av_dict_set(&params, "level", "3.1", 0);

// 获取 `sprop-parameter-sets` 参数
 AVPacket *extradata = av_packet_alloc();
// avcodec_parameters_from_context(extradata->data, codecContext);

// 获取 `sprop-parameter-sets` 参数的大小
 int sprop_parameter_sets_size = extradata->size;

// 释放资源
 av_packet_free(&extradata);

// 设置 `sprop-parameter-sets` 参数
 uint8_t *sprop_parameter_sets = extradata->data;
 codecContext->extradata = sprop_parameter_sets;
 codecContext->extradata_size = sprop_parameter_sets_size;*/

 /* Write the header */
// ret = avformat_write_header(outFormatCtx, NULL);
 ret = avformat_write_header(outFormatCtx, &opt);
 if (ret != 0) {
 fprintf(stderr, "Error occurred when opening output %s\n", av_err2str(ret));
 exit(1);
 }

 frame = av_frame_alloc();
 if (!frame) {
 fprintf(stderr, "Could not allocate video frame\n");
 exit(1);
 }
// frame->format = c->pix_fmt;
// frame->format = AV_PIX_FMT_YUV420P;
 frame->format = 0;
 frame->width = codecContext->width;
 frame->height = codecContext->height;

 ret = av_frame_get_buffer(frame, 0);
 if (ret < 0) {
 fprintf(stderr, "Could not allocate the video frame data ,%s\n", av_err2str(ret));
 exit(1);
 }

 /* encode 1 second of video */
 for (i = 0; i < 2500; i++) {
 /* ... (rest of the encoding loop) ... */
 fflush(stdout);

 /* make sure the frame data is writable */
 ret = av_frame_make_writable(frame);
 if (ret < 0)
 exit(1);

 /* prepare a dummy image */
 /* Y */
 for (y = 0; y < codecContext->height; y++) {
 for (x = 0; x < codecContext->width; x++) {
 frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
 }
 }

 /* Cb and Cr */
 for (y = 0; y < codecContext->height / 2; y++) {
 for (x = 0; x < codecContext->width / 2; x++) {
 frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
 frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
 }
 }

 frame->pts = i;

 /* encode the image */
 encode(codecContext, frame, pkt, outFormatCtx);
 }

 /* flush the encoder */
 encode(codecContext, NULL, pkt, outFormatCtx);

 /* Write the trailer */
 av_write_trailer(outFormatCtx);

 /* Close the output */
 avformat_free_context(outFormatCtx);

 avcodec_free_context(&codecContext);
 av_frame_free(&frame);
 av_packet_free(&pkt);

 return 0;
}
</codec></rtmp>


I searched online for how to add "prop parameter sets", but I used their method but none of them worked. I also used WireShark to capture packets, but during the communication process, there was still no "prop parameter sets". Here is the method I tried :


AVDictionary *opt = NULL;
 av_dict_set(&opt, "sprop-parameter-sets", "asdgasdfs", 0);