
Recherche avancée
Autres articles (105)
-
Le profil des utilisateurs
12 avril 2011, parChaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...) -
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...) -
XMP PHP
13 mai 2011, parDixit Wikipedia, XMP signifie :
Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)
Sur d’autres sites (11409)
-
How to use libavformat to concat 2 video files with same codec (re-muxing) ?
5 avril 2018, par TarhanI have downloaded videos from CDN in flv format (video H264 and audio AAC) and remux to them to MP4 format. But videos are limited by length. So i’ve downloaded each video in several parts : started at start point, at point 1, at point 2 (by using seek parameter in url). Each point starts little earlier than ending of previous one.
Usingav_read_frame
i scanned all parts and found that intersecting packets not only have same sizes and order but also their dts/pts shifted from each other by constant value. So to concat starting video with video started at point 1 I must do following :
1. Create output header in output file
2. Copy all non-intersecting packets from starting video.
3. Copy all non-intersecting packets from video started at point 1 with changed dts values by shifted it by constantHow to do all of this using libav (not ffmpeg) ? I read How can libavformat be used without using other libav libraries. But in
libav
it is not working since there notavformat_alloc_output_context2
inlibav
. Also sourceavconv.c
source is too complex for newbie like me to isolate parts related to stream copy operations.
Can someone provide me example to :
open input_file1 and input_file2 (only needed if procedure differs from standard in generic tutorials)
open and write header for output_file with same container format and same video and audio formats
write packets from input_file1 to output_file up to packet with for example
pos == XXX
write packets from input_file2 to output_file changing their dts (or whatever needed) by constant value
write correct
trailer
Calculating of time shift in dts i made before.
-
Writing opencv frames to avi container using libavformat Custom IO
16 juillet 2017, par AryanI have to write OpenCV cv::Mat frames to an AVI container. I cannot use OpenCV’s VideoWriter because I do not intend to write the AVI file to disk directly, instead I want to send it to a custom stream, so I have to use ffmpeg/libav. As I have never used ffmpeg before I have taken help from solutions provided here and here, alongwith the ffmpeg documentation.
I am able to send AVI container packets to my custom output stream as required but the performance is very bad. Specifically, the call to avcodec_encode_video2 is taking too long.
First, I suspect that due to my inexperience I have misconfigured or wrongly coded something. I am currently working wit 640*480 grayscale frames. On my i.MX6 platform the call to avcodec_encode_video2 is taking about 130ms on average per frame, which is unacceptably slow. Any pointers to an obvious performance killer ??? (i know sws_scale looks useless but it takes negligible time, and might be useful for me later).
Second, I am using PNG encoder, but that is not required, I would be happy to write uncompressed data if I know how to : If the slowdown is not due to my bad programming, can we just get rid of the encoder and generate uncompressed packets for the avi container ? Or use some encoder that accepts grayscale images and is not that slow ?
For Initialization and writing of header I am using :
void MyWriter::WriteHeader()
{
av_register_all();
// allocate output format context
if (avformat_alloc_output_context2(&avFmtCtx, NULL, "avi", NULL) < 0) { printf("DATAREC: avformat_alloc_output_context2 failed"); exit(1); }
// buffer for avio context
bufSize = 640 * 480 * 4; // Don't know how to derive, but this should be big enough for now
buffer = (unsigned char*)av_malloc(bufSize);
if (!buffer) { printf("DATAREC: Buffer alloc failed"); exit(1); }
// allocate avio context
avIoCtx = avio_alloc_context(buffer, bufSize, 1, this, NULL, WriteCallbackWrapper, NULL);
if (!avIoCtx) { printf("DATAREC: avio_alloc_context failed"); exit(1); }
// connect avio context to format context
avFmtCtx->pb = avIoCtx;
// set custom IO flag
avFmtCtx->flags |= AVFMT_FLAG_CUSTOM_IO;
// get encoder
encoder = avcodec_find_encoder(AV_CODEC_ID_PNG);
if (!encoder) { printf("DATAREC: avcodec_find_encoder failed"); exit(1); }
// create new stream
avStream = avformat_new_stream(avFmtCtx, encoder);
if (!avStream) { printf("DATAREC: avformat_new_stream failed"); exit(1); }
// set stream codec defaults
if (avcodec_get_context_defaults3(avStream->codec, encoder) < 0) { printf("DATAREC: avcodec_get_context_defaults3 failed"); exit(1); }
// hardcode settings for now
avStream->codec->pix_fmt = AV_PIX_FMT_GRAY8;
avStream->codec->width = 640;
avStream->codec->height = 480;
avStream->codec->time_base.den = 15;
avStream->codec->time_base.num = 1;
avStream->time_base.den = avStream->codec->time_base.den;
avStream->time_base.num = avStream->codec->time_base.num;
avStream->r_frame_rate.num = avStream->codec->time_base.den;
avStream->r_frame_rate.den = avStream->codec->time_base.num;
// open encoder
if (avcodec_open2(avStream->codec, encoder, NULL) < 0) {
printf("DATAREC: Cannot open codec\n");
exit(1);
}
// write header
if(avformat_write_header(avFmtCtx, NULL) < 0) { printf("DATAREC: avformat_write_header failed\n"); exit(1);}
// prepare for first frame
framePts = 0;
firstFrame = true;
}After writing the header, the following function is called in a loop for each cv::Mat frame :
void MyWriter::WriteFrame(cv::Mat& item)
{
if (firstFrame) // do only once, before writing the first frame
{
// allocate frame
frame = av_frame_alloc();
if (!frame) { printf("DATAREC: av_frame_alloc failed"); exit(1); }
// get size for framebuffer
int picsz = av_image_get_buffer_size(avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, 1);
// allocate frame buffer
framebuf = (unsigned char*)av_malloc(picsz);
if (!framebuf) { printf("DATAREC: fail to alloc framebuf"); exit(1); }
// set frame width, height, format
frame->width = avStream->codec->width;
frame->height = avStream->codec->height;
frame->format = static_cast<int>(avStream->codec->pix_fmt);
// set up data pointers and linesizes
if (av_image_fill_arrays(frame->data, frame->linesize, framebuf, avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, 1) < 0) { printf("DATAREC: av_image_fill_arrays failed\n"); exit(1);}
// get sws context
swsctx = sws_getCachedContext(nullptr, avStream->codec->width, avStream->codec->height, avStream->codec->pix_fmt, avStream->codec->width, avStream->codec->height, avStream->codec->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr);
if (!swsctx) { printf("DATAREC: fail to sws_getCachedContext"); exit(1); }
// done initializing
firstFrame = false; // don't repeat this for the following frames
}
// call sws scale
const int stride[] = { static_cast<int>(item.step[0]) };
sws_scale(swsctx, &item.data, stride, 0, item.rows, frame->data, frame->linesize);
// set presentation timestamp
frame->pts = framePts++;
// initialize packet
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
// THIS TAKES VERY LONG TO EXECUTE
// call encoder, convert frame to packet
if (avcodec_encode_video2(avStream->codec, &pkt, frame, &got_pkt) < 0) { printf("DATAREC: fail to avcodec_encode_video2"); exit(1); }
write packet if available
if (got_pkt)
{
pkt.duration = 1;
av_write_frame(avFmtCtx, &pkt);
}
// wipe packet
av_packet_unref(&pkt);
}
</int></int>After writing required frames, trailer is written :
void MyWriter::WriteTrailer()
{
// prepare packet for trailer
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
// encode trailer packet
if (avcodec_encode_video2(avStream->codec, &pkt, nullptr, &got_pkt) < 0) { printf("DATAREC: fail to avcodec_encode_video2"); exit(1); }
// write trailer packet
if (got_pkt)
{
pkt.duration = 1;
av_write_frame(avFmtCtx, &pkt);
}
// free everything
av_packet_unref(&pkt);
av_write_trailer(avFmtCtx);
av_frame_free(&frame);
avcodec_close(avStream->codec);
av_free(avIoCtx);
sws_freeContext(swsctx);
avformat_free_context(avFmtCtx);
av_free(framebuf);
av_free(buffer);
firstFrame = true; // for the next file
}Many many thanks to everyone who made it down to this line !
-
Block YouTube from source page when trying to download a video with youtube-dl
18 mars 2018, par user3108268E.g. example.com/1 has a video hosted, you run
youtube-dl example.com/1
and it all works fine, the video gets downloaded.E.g. example.com/2 also has a video, but it also has a YouTube trailer. If you run
youtube-dl example.com/2
the hosted video gets completely ignored and only YouTube trailer gets downloaded.From what I see in the log is that the wanted local video playlist gets downloaded first and then ignored by getting overwritten by embedded YouTube playlist download.
You can’t even get the url with
--get-url
or get format with--list-formats
. It always prints the googlevideos URL for the YouTube trailer and lists only the YouTube trailer formats.I did manage to pull out the local video URL via
--dump-pages
and decoding the base64 encoded source. But the problem is that the URL contains a unique token each time the page example.com/2 is called, so passing the unique one-time video URL like e.g. example.com/2/video.php ?token=asdf to youtube-dl won’t download the video.So I figured somehow I need to bypass the YouTube trailer source and playlist when calling
youtube-dl example.com/2
and trying to download local video and not the YouTube trailer.