
Recherche avancée
Autres articles (66)
-
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 ;
-
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 -
Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs
12 avril 2011, parLa manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.
Sur d’autres sites (13939)
-
Encoding images to h264 and rtp output : SDP file without sprop-parameter-sets does not play
14 septembre 2021, par oarfishtl ;dr : I try to encode acquired camera frames to h264, send via RTP
and play this back on another device. SDP file generated by ffmpeg for
a sample video has info which my own SDP file misses. My SDP file
plays in ffplay, but not VLC, while both play ffmpeg's SDP file. I am
suspecting missing sprop-parameter-sets in my SDP file.


Ultimately I want to play this back in VLC.



I am writing code that encodes images to h264 and outputs to an RTP
server (or client ? anyway the part that is listening). I generate an
SDP file for this.


- 

- ffplay plays the stream without problem
- mplayer shows a green box embedded in a larger black box, but I read
somewhere it only supports mpegts over RTP, so not sure
- VLC does not play the SDP file.








Now when instead I use some random video and have ffmpeg output an SDP
file like so


ffmpeg -re -i some.mp4 -an -c:v copy -f rtp -sdp_file
video.sdp "rtp://127.0.0.1:5004"



I can see that the generated SDP file – which plays in both ffplay and
VLC – includes the base64 encoded
sprop-parameter-sets
field, and
removing this causes the stream to not play.

> cat video.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.76.100
m=video 5004 RTP/AVP 96
b=AS:1034
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;
sprop-parameter-sets=Z2QANKzZQDAA7fiMBagICAoAAAMAAgAAAwDwHjBjLA==,aOvjyyLA;
profile-level-id=640034



My own SDP file on the other hand, does not contain this information,
and VLC hangs for 10s and then stops trying with "no data received".


> cat test.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.76.100
m=video 44499 RTP/AVP 96
b=AS:2000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1



So my theory is that my custom code must somehow add this SPS
information to the SDP file. But despite hours of searching, I could
not find a structured way to set the extradata field on the
AVStream
's
AVCodecParams
. The code I'm using is roughly this (I'm sure there's
unrelated errors in there) :

// variables
std::vector imgbuf;
AVFormatContext *ofmt_ctx = nullptr;
AVCodec *out_codec = nullptr;
AVStream *out_stream = nullptr;
AVCodecContext *out_codec_ctx = nullptr;
SwsContext *swsctx = nullptr;
cv::Mat canvas_;
unsigned int height_;
unsigned int width_;
unsigned int fps_;
AVFrame *frame_ = nullptr;

AVOutputFormat *format = av_guess_format("rtp", nullptr, nullptr);
const auto url = std::string("rtp://127.0.0.1:5001");
avformat_alloc_output_context2(ofmt_ctx, format, format->name, url.c_str());

out_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
stream = avformat_new_stream(ofmt_ctx, out_codec);
out_codec_ctx = avcodec_alloc_context3(out_codec);

// then, for each incoming image:
while (receive_image) {
 static bool first_time = true;
 if (first_time) {
 // discover necessary params such as image dimensions from the first
 // received image
 first_time = false;
 height_ = image.rows;
 width_ = image.cols;

 codec_ctx->codec_tag = 0;
 codec_ctx->bit_rate = 2e6;
 // does nothing, unfortunately
 codec_ctx->thread_count = 1;
 codec_ctx->codec_id = AV_CODEC_ID_H264;
 codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
 codec_ctx->width = width_;
 codec_ctx->height = height_;
 codec_ctx->gop_size = 6;
 codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
 codec_ctx->framerate = fps_;
 codec_ctx->time_base = av_inv_q(fps_);

 avcodec_parameters_from_context(stream, out_codec_ctx);

 // this stuff is empty: is that the problem?
 stream->codecpar->extradata = codec_ctx->extradata;
 stream->codecpar->extradata_size = codec_ctx->extradata_size;

 AVDictionary *codec_options = nullptr;
 av_dict_set(&codec_options, "profile", "high", 0);
 av_dict_set(&codec_options, "preset", "ultrafast", 0);
 av_dict_set(&codec_options, "tune", "zerolatency", 0);

 // open video encoder
 avcodec_open2(codec_ctx, codec, &codec_options);

 stream->time_base.num = 1;
 stream->time_base.den = fps_;
 avio_open(&(ofmt_ctx->pb), ofmt_ctx->filename, AVIO_FLAG_WRITE);

 /* Write a file for VLC */
 char buf[200000];
 AVFormatContext *ac[] = {ofmt_ctx};
 av_sdp_create(ac, 1, buf, 20000);
 printf("sdp:\n%s\n", buf);
 FILE *fsdp = fopen("test.sdp", "w");
 fprintf(fsdp, "%s", buf);
 fclose(fsdp);

 swsctx = sws_getContext(width_, height_, AV_PIX_FMT_BGR24, width_, height_,
 out_codec_ctx->pix_fmt, SWS_BICUBIC, nullptr,
 nullptr, nullptr);
 }

 if (!frame_) {
 frame_ = av_frame_alloc();

 std::uint8_t *framebuf = new uint8_t[av_image_get_buffer_size(
 codec_ctx->pix_fmt, width_, height_, 1)];
 av_image_fill_arrays(frame_->data, frame_->linesize, framebuf,
 codec_ctx->pix_fmt, width, height, 1);
 frame_->width = width_;
 frame_->height = height_;
 frame_->format = static_cast<int>(codec_ctx->pix_fmt);
 success = avformat_write_header(ofmt_ctx, nullptr);
 }
 if (imgbuf.empty()) {
 imgbuf.resize(height_ * width_ * 3 + 16);
 canvas_ = cv::Mat(height_, width_, CV_8UC3, imgbuf.data(), width_ * 3);
 } else {
 image.copyTo(canvas_);
 }

 const int stride[] = {static_cast<int>(image.step[0])};

 sws_scale(swsctx, &canvas_.data, stride, 0, canvas_.rows, frame_->data,
 frame_->linesize);
 frame_->pts += av_rescale_q(1, out_codec_ctx->time_base, stream->time_base);

 AVPacket pkt = {0};
 avcodec_send_frame(out_codec_ctx, frame_);
 avcodec_receive_packet(out_codec_ctx, &pkt);
 av_interleaved_write_frame(ofmt_ctx, &pkt);
}
</int></int>


Can anyone offer some advice here ?


—


Update


When setting


this->out_codec_ctx->flags |=AV_CODEC_FLAG_GLOBAL_HEADER;



extradata is actually present in the codec context, but I had to move
avcodec_parameters_from_context()
afteravcodec_open2()
, as the extradata is empty before opening the codec. I now getsprop-parameter-sets
in the SDP file, but VLC still does not play it.

-
unable to download youtube video portion via extracted video URL from youtube-dl and ffmpeg
29 juillet 2020, par karmaI've read the following link, and did :


youtube-dl --rm-cache-dir



But it still give me 403 forbidden.


This is my process :


youtube-dl -g https://www.youtube.com/watch?v=kGDgGsrA78s



It gave me a result like this :


https://r2---sn-uigxxi0ujipnvo-q2ne.googlevideo.com/videoplayback?expire=1596034295&ei=lzghX6SHKMOD8QPlx5SQBw&ip=223.255.228.87&id=o-AK6cYo88zJXe5Xb4y1QsXspuRnVCy-zPFpMaHcAaTQ-_&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=DA&mm=31%2C29&mn=sn-uigxxi0ujipnvo-q2ne%2Csn-npoe7nlz&ms=au%2Crdu&mv=m&mvi=2&pl=24&initcwndbps=173750&vprv=1&mime=video%2Fmp4&gir=yes&clen=456970484&dur=1389.955&lmt=1521825834085900&mt=1596012582&fvip=5&keepalive=yes&fexp=23883098&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAMvZrHYvC1YrkvtARzhjyD8dnMnlefobGrOFM1rX6QZPAiEAqqeIsKdZ19y-SlHf-l8YwTx2yYbo1p5sFlVoC87oXEQ%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgAIwAVMPrcMhAL476uN_ZzWj8vKPGGW58KCpHBYBsKeICICRgVWgthNvgbGl8VgQwscjJ0n8ib4XBNjRxRgSg2T5r&ratebypass=yes
https://r2---sn-uigxxi0ujipnvo-q2ne.googlevideo.com/videoplayback?expire=1596034295&ei=lzghX6SHKMOD8QPlx5SQBw&ip=223.255.228.87&id=o-AK6cYo88zJXe5Xb4y1QsXspuRnVCy-zPFpMaHcAaTQ-_&itag=140&source=youtube&requiressl=yes&mh=DA&mm=31%2C29&mn=sn-uigxxi0ujipnvo-q2ne%2Csn-npoe7nlz&ms=au%2Crdu&mv=m&mvi=2&pl=24&initcwndbps=173750&vprv=1&mime=audio%2Fmp4&gir=yes&clen=22077901&dur=1390.039&lmt=1521818817521456&mt=1596012582&fvip=5&keepalive=yes&fexp=23883098&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANHMaZK4jYg7p4t2dID3d21VRv18I1nhBtXqYRSZo0C7AiAEjO8LwjhXeNQiKqdiZFQ_DsHuXT4rgvPnNQhaDGj9hg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgAIwAVMPrcMhAL476uN_ZzWj8vKPGGW58KCpHBYBsKeICICRgVWgthNvgbGl8VgQwscjJ0n8ib4XBNjRxRgSg2T5r&ratebypass=yes



The result gave me two URL, so I only copy the first line and since what I want is just to copy a few minutes video portion - so in ffmpeg :


ffmpeg -ss 00:00:15.00 -i https://r2---sn-uigxxi0ujipnvo-q2ne.googlevideo.com/videoplayback?expire=1596034295&ei=lzghX6SHKMOD8QPlx5SQBw&ip=223.255.228.87&id=o-AK6cYo88zJXe5Xb4y1QsXspuRnVCy-zPFpMaHcAaTQ-_&itag=140&source=youtube&requiressl=yes&mh=DA&mm=31%2C29&mn=sn-uigxxi0ujipnvo-q2ne%2Csn-npoe7nlz&ms=au%2Crdu&mv=m&mvi=2&pl=24&initcwndbps=173750&vprv=1&mime=audio%2Fmp4&gir=yes&clen=22077901&dur=1390.039&lmt=1521818817521456&mt=1596012582&fvip=5&keepalive=yes&fexp=23883098&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANHMaZK4jYg7p4t2dID3d21VRv18I1nhBtXqYRSZo0C7AiAEjO8LwjhXeNQiKqdiZFQ_DsHuXT4rgvPnNQhaDGj9hg%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgAIwAVMPrcMhAL476uN_ZzWj8vKPGGW58KCpHBYBsKeICICRgVWgthNvgbGl8VgQwscjJ0n8ib4XBNjRxRgSg2T5r&ratebypass=yes -t 00:00:10.00 -c copy out.mp4



But then the result in command prompt is like this :


ffmpeg version N-93300-g96451477b9 Copyright (c) 2000-2019 the FFmpeg developers
 built with gcc 8.2.1 (GCC) 20190212
 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
 libavutil 56. 26.100 / 56. 26.100
 libavcodec 58. 47.103 / 58. 47.103
 libavformat 58. 26.101 / 58. 26.101
 libavdevice 58. 6.101 / 58. 6.101
 libavfilter 7. 48.100 / 7. 48.100
 libswscale 5. 4.100 / 5. 4.100
 libswresample 3. 4.100 / 3. 4.100
 libpostproc 55. 4.100 / 55. 4.100
[https @ 0000020137c895c0] HTTP error 403 Forbidden
https://r2---sn-uigxxi0ujipnvo-q2ne.googlevideo.com/videoplayback?expire=1596034295: Server returned 403 Forbidden (access denied)
'ei' is not recognized as an internal or external command,
operable program or batch file.
'ip' is not recognized as an internal or external command,
operable program or batch file.
'id' is not recognized as an internal or external command,
operable program or batch file.
.... and so on....



BTW, I've also tried to copy the second URL, still 403 error.

I also tried to copy both URL, still 403 error.

On the other hand, when I tried to paste the URL into Internet Download Manager,

IDM directly recognized the URL and I can download the file via IDM.

Is there a way to resolve this ?


Any kind of respond would be greatly appreciated.

Thank you in advanced.

EDIT :
I'm very sorry for my ignorant.

It turn out I need to put apostrophe at the beginning and at the end of the URL :).

Dear moderator, please close this thread.

Thank you for you all.

-
FFmpeg : What re-encoding settings can be used to achieve results similar to Google Drive's video processing ?
4 août 2023, par Mycroft_47Context :


I have a large collection of videos recorded by my phone's camera, which is taking up a significant amount of space. Recently, I noticed that when I uploaded a video to Google Drive and then downloaded it again using IDM (by clicking on the pop-up that IDM displays when it detects something that can be downloaded here's what i mean), the downloaded video retained the same visual quality but occupied much less space. Upon further research, I discovered that Google re-encodes uploaded videos using H.264 video encoding, and I believe I can achieve similar compression using FFmpeg.


Problem :


Despite experimenting with various FFmpeg commands, I haven't been able to replicate Google Drive's compression. Every attempt using
-codec:v libx264
option alone resulted in videos larger than the original files.

While adjusting the
-crf
parameter to a higher value and opting for a faster-preset
option did yield smaller file sizes, it unfortunately came at the cost of a noticeable degradation in visual quality and the appearance of some visible artifacts in the video.

Google Drive's processing, on the other hand, strikes a commendable balance, achieving a satisfactory file size without compromising visual clarity, (I should note that upon zooming in on this video, I observed some minor blurring, but it was acceptable to me).


Note :


I'm aware that using the H.265 video encoder instead of H.264 may give better results. However, to ensure fairness and avoid any potential bias, I think the optimal approach is first to find the best command using the H.264 video encoder. Once identified, I can then replace
-codec:v libx264
with-codec:v libx265
. This approach will ensure that the chosen command is really the best that FFMPEG can achieve, and that it is not solely influenced by the superior performance of H.265 when used from the outset.

Here's the FFMPEG command I am currently using :


ffmpeg -hide_banner -loglevel verbose ^
 -i input.mp4 ^
 -codec:v libx264 ^
 -crf 36 -preset ultrafast ^
 -codec:a libopus -b:a 112k ^
 -movflags use_metadata_tags+faststart -map_metadata 0 ^
 output.mp4








 Video file 

Size (bytes) 

Bit rate (bps) 

Encoder 

FFPROB - JSON 







 Original (named 'raw 1.mp4') 

31,666,777 

10,314,710 

!!! 

link 




 Without crf 

36,251,852 

11,805,216 

Lavf60.3.100 

link 




 With crf 

10,179,113 

3,314,772 

Lavf60.3.100 

link 




 Gdrive 

6,726,189 

2,190,342 

Google 

link 









Those files can be found here.


Update :


I continued my experiments with the video "raw_1.mp4" and found some interesting results that resemble those shown in this blog post, (I recommend consulting this answer).


In the following figure, I observed that using the
-preset
set to veryfast provided the most advantageous results, striking the optimal balance between compression ratio and compression time, (Note that a negative percentage in the compression variable indicates an increase in file size after processing) :


In this figure, I used the H.264 encoder and compared the compression ratio of different outputted files resulting from seven different values of the
-crf
parameter (CRF values used : 25, 27, 29, 31, 33, 35, 37),


For this figure, I've switched the encoder to H.265 while maintaining the same CRF values used in the previous figure :



Based on these results, the
-preset
veryfast and a-crf
value of 31 are my current preferred settings for FFmpeg, until they are proven to be suboptimal choices.
As a result, the FFmpeg command I'll use is as follows :

ffmpeg -hide_banner -loglevel verbose ^
 -i input.mp4 ^
 -codec:v libx264 ^
 -crf 31 -preset veryfast ^
 -codec:a libopus -b:a 112k ^
 -movflags use_metadata_tags+faststart -map_metadata 0 ^
 output.mp4



Note that these choices are based solely on the compression results obtained so far, and they do not take into account the visual quality of the outputted files.