
Recherche avancée
Autres articles (63)
-
Personnaliser les catégories
21 juin 2013, parFormulaire de création d’une catégorie
Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
On peut modifier ce formulaire dans la partie :
Administration > Configuration des masques de formulaire.
Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...) -
List of compatible distributions
26 avril 2011, parThe table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...) -
Pas question de marché, de cloud etc...
10 avril 2011Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
sur le web 2.0 et dans les entreprises qui en vivent.
Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)
Sur d’autres sites (8551)
-
Screen Capture with FFMPEG and Google Native Client
18 juillet 2016, par Mohammad Abu MusaI am building a screen recorder that is based on Native Client for Google, I have ffmpeg installed and ready but I do not have experience programming in ffmpeg. so I am looking for tips to understand how to build this recorder.
My goal is to make a screen recorder and export videos as webm files, I have all the required libraries I just could not find any code examples to hack on
This is what I achieved so far
#define __STDC_LIMIT_MACROS
#include
#include <iostream>
#include
#include
#include <sstream>
#include
#include <vector>
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/var_dictionary.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_console.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/var_array_buffer.h"
// Begin File IO headers
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/ppb_file_io.h"
#include "ppapi/cpp/directory_entry.h"
#include "ppapi/cpp/file_io.h"
#include "ppapi/cpp/file_ref.h"
#include "ppapi/cpp/file_system.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/message_loop.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/var_array.h"
#include "ppapi/utility/completion_callback_factory.h"
#include "ppapi/utility/threading/simple_thread.h"
#ifndef INT32_MAX
#define INT32_MAX (0x7FFFFFFF)
#endif
#ifdef WIN32
#undef min
#undef max
#undef PostMessage
// Allow 'this' in initializer list
#pragma warning(disable : 4355)
#endif
namespace {
typedef std::vector StringVector;
}
//End File IO headers
extern "C" {
#include <libavcodec></libavcodec>avcodec.h>
#include <libswscale></libswscale>swscale.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>imgutils.h>
}
const char* file_name = "/file.txt";
const char* video_name = "/video.mpeg";
const char* file_text = "Echo from NaCl: ";
/**
* Pixel formats and codecs
*/
static const AVPixelFormat sourcePixelFormat = AV_PIX_FMT_BGR24;
static const AVPixelFormat destPixelFormat = AV_PIX_FMT_YUV420P;
static const AVCodecID destCodec = AV_CODEC_ID_MPEG2VIDEO;
class RecorderInstance: public pp::Instance {
public:
explicit RecorderInstance(PP_Instance instance) :
pp::Instance(instance), callback_factory_(this), file_system_(this,
PP_FILESYSTEMTYPE_LOCALPERSISTENT), file_system_ready_(
false), file_thread_(this) {
}
virtual ~RecorderInstance() {
file_thread_.Join();
}
virtual bool Init(uint32_t /*argc*/, const char * /*argn*/[],
const char * /*argv*/[]) {
file_thread_.Start();
file_thread_.message_loop().PostWork(
callback_factory_.NewCallback(
&RecorderInstance::OpenFileSystem));
avcodec_register_all(); // mandatory to register ffmpeg functions
return true;
}
private:
pp::CompletionCallbackFactory<recorderinstance> callback_factory_;
pp::FileSystem file_system_;
// Indicates whether file_system_ was opened successfully. We only read/write
// this on the file_thread_.
bool file_system_ready_;
pp::SimpleThread file_thread_;
virtual void HandleMessage(const pp::Var& var_message) {
if (!var_message.is_dictionary()) {
LogToConsole(PP_LOGLEVEL_ERROR, pp::Var("Invalid message!"));
return;
}
pp::VarDictionary dict_message(var_message);
std::string command = dict_message.Get("message").AsString();
if (command == "sendFrame") {
pp::VarArrayBuffer data(dict_message.Get("data"));
uint width = 600;
uint height = 800;
uint8_t endcode[] = { 0, 0, 1, 0xb7 };
/**
* Create an encoder and open it
*/
avcodec_register_all();
AVCodec *h264encoder = avcodec_find_encoder(destCodec);
AVCodecContext *h264encoderContext = avcodec_alloc_context3(
h264encoder);
h264encoderContext->pix_fmt = destPixelFormat;
h264encoderContext->width = width;
h264encoderContext->height = height;
if (avcodec_open2(h264encoderContext, h264encoder, NULL) < 0) {
ShowErrorMessage("Cannot open codec" ,-1);
return;
}
/**
* Create a stream
*/
AVFormatContext *cv2avFormatContext = avformat_alloc_context();
AVStream *h264outputstream = avformat_new_stream(cv2avFormatContext,
h264encoder);
AVFrame *sourceAvFrame = av_frame_alloc(), *destAvFrame =
av_frame_alloc();
int got_frame;
FILE* videoOutFile = fopen("video", "wb");
/**
* Prepare the conversion context
*/
SwsContext *bgr2yuvcontext = sws_getContext(width, height,
sourcePixelFormat, width, height, destPixelFormat,
SWS_BICUBIC, NULL, NULL, NULL);
int framesToEncode = 100;
/**
* Convert and encode frames
*/
for (uint i = 0; i < framesToEncode; i++) {
/**
* Allocate source frame, i.e. input to sws_scale()
*/
av_image_alloc(sourceAvFrame->data, sourceAvFrame->linesize,
width, height, sourcePixelFormat, 1);
/**
* Copy image data into AVFrame from cv::Mat
*/
for (uint32_t h = 0; h < height; h++)
memcpy(
&(sourceAvFrame->data[0][h
* sourceAvFrame->linesize[0]]),
&(data), width * 3);
/**
* Allocate destination frame, i.e. output from sws_scale()
*/
av_image_alloc(destAvFrame->data, destAvFrame->linesize, width,
height, destPixelFormat, 1);
sws_scale(bgr2yuvcontext, sourceAvFrame->data,
sourceAvFrame->linesize, 0, height, destAvFrame->data,
destAvFrame->linesize);
sws_freeContext(bgr2yuvcontext);
/**
* Prepare an AVPacket and set buffer to NULL so that it'll be allocated by FFmpeg
*/
AVPacket avEncodedPacket;
av_init_packet(&avEncodedPacket);
avEncodedPacket.data = NULL;
avEncodedPacket.size = 0;
destAvFrame->pts = i;
avcodec_encode_video2(h264encoderContext, &avEncodedPacket,
destAvFrame, &got_frame);
if (got_frame) {
ShowErrorMessage(
"Encoded a frame of size \n",-1); //+ (string)avEncodedPacket.size + "\n");
if (fwrite(avEncodedPacket.data, 1, avEncodedPacket.size,
videoOutFile) < (unsigned) avEncodedPacket.size)
ShowErrorMessage(
"Could not write all \n",-1);
//+ avEncodedPacket.size
//+ " bytes, but will continue..\n"
fflush(videoOutFile);
}
/**
* Per-frame cleanup
*/
av_packet_free_side_data(&avEncodedPacket);
av_free_packet(&avEncodedPacket);
av_freep(sourceAvFrame->data);
av_frame_free(&sourceAvFrame);
av_freep(destAvFrame->data);
av_frame_free(&destAvFrame);
}
fwrite(endcode, 1, sizeof(endcode), videoOutFile);
fclose(videoOutFile);
/**
* Final cleanup
*/
avformat_free_context(cv2avFormatContext);
avcodec_close(h264encoderContext);
avcodec_free_context(&h264encoderContext);
} else if (command == "createFile") {
file_thread_.message_loop().PostWork(
callback_factory_.NewCallback(&RecorderInstance::Save,
file_name, file_text));
}
}
void OpenFileSystem(int32_t /* result */) {
int32_t rv = file_system_.Open(1024 * 1024, pp::BlockUntilComplete());
if (rv == PP_OK) {
file_system_ready_ = true;
// Notify the user interface that we're ready
ShowStatusMessage("STORAGE READY");
} else {
ShowErrorMessage("Failed to open file system", rv);
}
}
void Save(int32_t /* result */, const std::string& file_name,
const std::string& file_contents) {
if (!file_system_ready_) {
ShowErrorMessage("File system is not open", PP_ERROR_FAILED);
return;
}
pp::FileRef ref(file_system_, file_name.c_str());
pp::FileIO file(this);
int32_t open_result = file.Open(ref,
PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE
| PP_FILEOPENFLAG_TRUNCATE, pp::BlockUntilComplete());
if (open_result != PP_OK) {
ShowErrorMessage("File open for write failed", open_result);
return;
}
// We have truncated the file to 0 bytes. So we need only write if
// file_contents is non-empty.
if (!file_contents.empty()) {
if (file_contents.length() > INT32_MAX) {
ShowErrorMessage("File too big", PP_ERROR_FILETOOBIG);
return;
}
int64_t offset = 0;
int32_t bytes_written = 0;
do {
bytes_written = file.Write(offset,
file_contents.data() + offset, file_contents.length(),
pp::BlockUntilComplete());
if (bytes_written > 0) {
offset += bytes_written;
} else {
ShowErrorMessage("File write failed", bytes_written);
return;
}
} while (bytes_written
< static_cast(file_contents.length()));
}
// All bytes have been written, flush the write buffer to complete
int32_t flush_result = file.Flush(pp::BlockUntilComplete());
if (flush_result != PP_OK) {
ShowErrorMessage("File fail to flush", flush_result);
return;
}
ShowStatusMessage("Save success");
}
/// Encapsulates our simple javascript communication protocol
void ShowErrorMessage(const std::string& message, int32_t result) {
std::stringstream ss;
ss << "ERROR: " << message << " -- Error #: " << result << "\n";
PostMessage(ss.str());
}
void ShowStatusMessage(const std::string& message) {
std::stringstream ss;
ss << "LOG: " << message << "\n";
PostMessage(ss.str());
}
};
class RecorderModule: public pp::Module {
public:
RecorderModule() :
pp::Module() {
}
virtual ~RecorderModule() {
}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new RecorderInstance(instance);
}
};
namespace pp {
/**
* This function is an entry point to a NaCl application.
* It must be implemented.
*/
Module* CreateModule() {
return new RecorderModule();
}
} // namespace pp
</recorderinstance></vector></sstream></iostream> -
ffmpeg leaves audio gap when concatening videos
6 juillet 2016, par RafaelI am trying to cut a video in 2 parts then reassembling with ffmpeg but the final output has a small audio glitch right where the segments meet. I am using the following command to split the video 1.mp4 in 2 parts :
ffmpeg -i 1.mp4 -ss 00:00:00 -t 00:00:02 -async 1 1-1.mp4
and
ffmpeg -i 1.mp4 -ss 00:00:02 -t 00:00:02 -async 1 1-2.mp4
Once I have the 2 parts I am concatening them back together with :
ffmpeg -f concat -i files.txt -c copy output.mp4
files.txt is correctly listing both files. Can anyone point me to where the problem might be ?
Thanks
-
seeking with av_seek_frame returns invalid data
27 juin 2016, par mtadmkBased on dranger tutorial I’m trying to implement seeking in video file. Problem is with seeking to beginning milliseconds - it always returns 0 when seeking backward, or some place in file (based on file format).
I.e. with this video file and seeking forward to 500 pts there is always 6163 pts returned. Seeking backward to 500 is always returning 0. I have no idea why.
Code to do this :
import java.util.Arrays;
import java.util.List;
import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.javacpp.DoublePointer;
import org.bytedeco.javacpp.PointerPointer;
import org.bytedeco.javacpp.avcodec;
import org.bytedeco.javacpp.avformat;
import org.bytedeco.javacpp.avutil;
import org.bytedeco.javacpp.swscale;
import static org.bytedeco.javacpp.avcodec.av_free_packet;
import static org.bytedeco.javacpp.avcodec.avcodec_close;
import static org.bytedeco.javacpp.avcodec.avcodec_decode_video2;
import static org.bytedeco.javacpp.avcodec.avcodec_find_decoder;
import static org.bytedeco.javacpp.avcodec.avcodec_flush_buffers;
import static org.bytedeco.javacpp.avcodec.avcodec_open2;
import static org.bytedeco.javacpp.avcodec.avpicture_fill;
import static org.bytedeco.javacpp.avcodec.avpicture_get_size;
import static org.bytedeco.javacpp.avformat.AVSEEK_FLAG_BACKWARD;
import static org.bytedeco.javacpp.avformat.av_dump_format;
import static org.bytedeco.javacpp.avformat.av_read_frame;
import static org.bytedeco.javacpp.avformat.av_register_all;
import static org.bytedeco.javacpp.avformat.av_seek_frame;
import static org.bytedeco.javacpp.avformat.avformat_close_input;
import static org.bytedeco.javacpp.avformat.avformat_find_stream_info;
import static org.bytedeco.javacpp.avformat.avformat_open_input;
import static org.bytedeco.javacpp.avutil.AVMEDIA_TYPE_VIDEO;
import static org.bytedeco.javacpp.avutil.AV_PIX_FMT_RGB24;
import static org.bytedeco.javacpp.avutil.AV_TIME_BASE;
import static org.bytedeco.javacpp.avutil.av_frame_alloc;
import static org.bytedeco.javacpp.avutil.av_frame_get_best_effort_timestamp;
import static org.bytedeco.javacpp.avutil.av_free;
import static org.bytedeco.javacpp.avutil.av_make_q;
import static org.bytedeco.javacpp.avutil.av_malloc;
import static org.bytedeco.javacpp.avutil.av_q2d;
import static org.bytedeco.javacpp.avutil.av_rescale_q;
import static org.bytedeco.javacpp.swscale.SWS_BILINEAR;
import static org.bytedeco.javacpp.swscale.sws_getContext;
import static org.bytedeco.javacpp.swscale.sws_scale;
public class SeekTest1 {
private avformat.AVFormatContext videoFile;
private final avcodec.AVPacket framePacket = new avcodec.AVPacket();
private avcodec.AVCodecContext videoCodec;
private avutil.AVFrame yuvFrame;
private swscale.SwsContext scalingContext;
private avutil.AVFrame rgbFrame;
private int streamId;
private long lastTime;
public static void main(String[] args) {
if (args.length > 0) {
new SeekTest1().start(args[0]);
} else {
new SeekTest1().start("/path/to/file");
}
}
private void start(String path) {
init(path);
//test for forward
// List<integer> seekPos = Arrays.asList(0, 100, 0, 200, 0, 300, 0, 400, 0, 500, 0, 600, 0, 700);
//test for backward
List<integer> seekPos = Arrays.asList(10000, 8000, 10000, 7000, 10000, 6000, 10000, 4000, 10000, 2000, 10000, 1000, 10000, 200);
seekPos.forEach(seekPosition -> {
readFrame();
seek(seekPosition);
});
readFrame();
cleanUp();
}
long seek(long seekPosition) {
final avutil.AVRational timeBase = fetchTimeBase();
long timeInBaseUnit = fetchTimeInBaseUnit(seekPosition, timeBase);
//changing flag to AVSEEK_FLAG_ANY does not change behavior
int flag = 0;
if (timeInBaseUnit < lastTime) {
flag = AVSEEK_FLAG_BACKWARD;
System.out.println("seeking backward to " + timeInBaseUnit);
} else {
System.out.println("seeking forward to " + timeInBaseUnit);
}
avcodec_flush_buffers(videoCodec);
av_seek_frame(videoFile, streamId, timeInBaseUnit, flag);
return timeInBaseUnit;
}
private long fetchTimeInBaseUnit(long seekPositionMillis, avutil.AVRational timeBase) {
return av_rescale_q((long) (seekPositionMillis / 1000.0 * AV_TIME_BASE), av_make_q(1, AV_TIME_BASE), timeBase);
}
private void readFrame() {
while (av_read_frame(videoFile, framePacket) >= 0) {
if (framePacket.stream_index() == streamId) {
// Decode video frame
final int[] frameFinished = new int[1];
avcodec_decode_video2(this.videoCodec, yuvFrame, frameFinished, framePacket);
if (frameFinished[0] != 0) {
av_free_packet(framePacket);
long millis = produceFinishedFrame();
System.out.println("produced time " + millis);
break;
}
}
av_free_packet(framePacket);
}
}
private long produceFinishedFrame() {
sws_scale(scalingContext, yuvFrame.data(), yuvFrame.linesize(), 0,
videoCodec.height(), rgbFrame.data(), rgbFrame.linesize());
final long pts = av_frame_get_best_effort_timestamp(yuvFrame);
final double timeBase = av_q2d(fetchTimeBase());
final long foundMillis = (long) (pts * 1000 * timeBase);
lastTime = foundMillis;
return foundMillis;
}
private avutil.AVRational fetchTimeBase() {
return videoFile.streams(streamId).time_base();
}
private void init(String videoPath) {
final avformat.AVFormatContext videoFile = new avformat.AVFormatContext(null);
av_register_all();
if (avformat_open_input(videoFile, videoPath, null, null) != 0) throw new RuntimeException("unable to open");
if (avformat_find_stream_info(videoFile, (PointerPointer) null) < 0) throw new RuntimeException("Couldn't find stream information");
av_dump_format(videoFile, 0, videoPath, 0);
final int streamId = findFirstVideoStream(videoFile);
final avcodec.AVCodecContext codec = videoFile.streams(streamId).codec();
final avcodec.AVCodec pCodec = avcodec_find_decoder(codec.codec_id());
if (pCodec == null) throw new RuntimeException("Unsupported codec");
if (avcodec_open2(codec, pCodec, (avutil.AVDictionary) null) < 0) throw new RuntimeException("Could not open codec");
final avutil.AVFrame yuvFrame = av_frame_alloc();
final avutil.AVFrame rgbFrame = av_frame_alloc();
if (rgbFrame == null) throw new RuntimeException("Can't allocate avframe");
final int numBytes = avpicture_get_size(AV_PIX_FMT_RGB24, codec.width(), codec.height());
final BytePointer frameBuffer = new BytePointer(av_malloc(numBytes));
final swscale.SwsContext swsContext = sws_getContext(codec.width(), codec.height(), codec.pix_fmt(), codec.width(), codec.height(),
AV_PIX_FMT_RGB24, SWS_BILINEAR, null, null, (DoublePointer) null);
avpicture_fill(new avcodec.AVPicture(rgbFrame), frameBuffer, AV_PIX_FMT_RGB24, codec.width(), codec.height());
this.videoFile = videoFile;
this.videoCodec = codec;
this.yuvFrame = yuvFrame;
this.scalingContext = swsContext;
this.rgbFrame = rgbFrame;
this.streamId = streamId;
}
private static int findFirstVideoStream(avformat.AVFormatContext videoFile) {
int videoStream = -1;
for (int i = 0; i < videoFile.nb_streams(); i++) {
if (videoFile.streams(i).codec().codec_type() == AVMEDIA_TYPE_VIDEO) {
videoStream = i;
break;
}
}
if (videoStream == -1) throw new RuntimeException("Didn't find video stream");
return videoStream;
}
private void cleanUp() {
av_free(this.rgbFrame);
av_free(yuvFrame);
avcodec_close(videoCodec);
avformat_close_input(videoFile);
}
}
</integer></integer>As input arg should be provided file from above.