
Recherche avancée
Autres articles (12)
-
Other interesting software
13 avril 2011, parWe don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
We don’t know them, we didn’t try them, but you can take a peek.
Videopress
Website : http://videopress.com/
License : GNU/GPL v2
Source code : (...) -
Emballe médias : à quoi cela sert ?
4 février 2011, parCe plugin vise à gérer des sites de mise en ligne de documents de tous types.
Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ; -
Prérequis à l’installation
31 janvier 2010, parPréambule
Cet article n’a pas pour but de détailler les installations de ces logiciels mais plutôt de donner des informations sur leur configuration spécifique.
Avant toute chose SPIPMotion tout comme MediaSPIP est fait pour tourner sur des distributions Linux de type Debian ou dérivées (Ubuntu...). Les documentations de ce site se réfèrent donc à ces distributions. Il est également possible de l’utiliser sur d’autres distributions Linux mais aucune garantie de bon fonctionnement n’est possible.
Il (...)
Sur d’autres sites (4123)
-
FFMpeg drawtext not working in my code
10 juillet 2018, par DevI am trying to overlay a text on existing movie using
FFMpeg
. Overlaying of an image works perfectly, but failed to drawtext. My code is as below.GeneralUtils.checkForPermissionsMAndAbove(RecordVideo.this, true);
LoadJNI vk = new LoadJNI();
String[] complexCommand = {
"ffmpeg", "-i", FilePath, "-vf",
"drawtext=text='Hello Dev..':"
+ "fontsize=24:fontfile=/system/fonts/DroidSans.ttf:box=1:boxcolor=black@0.5:x=w-tw:y=h-th",
FilePath1};
vk.run(complexCommand , StorageDIR , getApplicationContext());I am getting error as follows
ffmpeg version git-2016-10-26-efa89a8 Copyright (c) 2000-2016 the FFmpeg
developers
built with gcc 4.9 (GCC) 20140827 (prerelease)
ffmpeg4android 3.22_00_full_LM322
libavutil 55. 35.100 / 55. 35.100
libavcodec 57. 65.100 / 57. 65.100
libavformat 57. 57.100 / 57. 57.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 66.100 / 6. 66.100
libswscale 4. 3.100 / 4. 3.100
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Splitting the commandline.
Reading option '-i' ... matched as input file with argument '/storage/emulated/0/Pictures/ReporterLive/VID_10072018141402.avi'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'drawtext=text='Hello Dev..':fontsize=24:fontfile=/system/fonts/DroidSans.ttf:box=1:boxcolor=black@0.5:x=w-tw:y=h-th'.
Reading option '/storage/emulated/0/Pictures/ReporterLive/VID_10072018141402_1.avi' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Successfully parsed a group of options.
Parsing a group of options: input file /storage/emulated/0/Pictures/ReporterLive/VID_10072018141402.avi.
Successfully parsed a group of options.
Opening an input file: /storage/emulated/0/Pictures/ReporterLive/VID_10072018141402.avi.
Setting default whitelist 'file,crypto'
Probing mov,mp4,m4a,3gp,3g2,mj2 score:100 size:2048
Probing mp3 score:1 size:2048
Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
type: 70797466 'ftyp' parent:'root' sz: 24 8 3096055
ISO: File Type Major Brand: mp42
type: 7461646d 'mdat' parent:'root' sz: 3093790 32 3096055
type: 766f6f6d 'moov' parent:'root' sz: 2241 3093822 3096055
type: 6468766d 'mvhd' parent:'moov' sz: 108 8 2233
time scale = 1000
type: 61746475 'udta' parent:'moov' sz: 52 116 2233
type: 4e4c4453 'SDLN' parent:'udta' sz: 16 8 44
type: 64726d73 'smrd' parent:'udta' sz: 16 24 44
type: 61746d73 'smta' parent:'udta' sz: 12 40 44
type: 6174656d 'meta' parent:'moov' sz: 119 168 2233
type: 726c6468 'hdlr' parent:'meta' sz: 33 8 111
ctype= (0x00000000)
stype= mdta
type: 7379656b 'keys' parent:'meta' sz: 43 41 111
type: 74736c69 'ilst' parent:'meta' sz: 35 84 111
type: 01000000 '' parent:'ilst' sz: 27 8 27
lang " " tag "com.android.version" value "7.0" atom "" 7 3
type: 6b617274 'trak' parent:'moov' sz: 1023 287 2233
type: 64686b74 'tkhd' parent:'trak' sz: 92 8 1015
type: 6169646d 'mdia' parent:'trak' sz: 923 100 1015
type: 6468646d 'mdhd' parent:'mdia' sz: 32 8 915
type: 726c6468 'hdlr' parent:'mdia' sz: 44 40 915
ctype= (0x00000000)
stype= vide
type: 666e696d 'minf' parent:'mdia' sz: 839 84 915
type: 64686d76 'vmhd' parent:'minf' sz: 20 8 831
type: 666e6964 'dinf' parent:'minf' sz: 36 28 831
type: 66657264 'dref' parent:'dinf' sz: 28 8 28
type url size 12
Unknown dref type 0x08206c7275 size 12
type: 6c627473 'stbl' parent:'minf' sz: 775 64 831
type: 64737473 'stsd' parent:'stbl' sz: 171 8 767
size=155 4CC= avc1/0x31637661 codec_type=0
type: 43637661 'avcC' parent:'stsd' sz: 34 8 69
type: 70736170 'pasp' parent:'stsd' sz: 16 42 69
type: 726c6f63 'colr' parent:'stsd' sz: 19 58 69
nclx: pri 1 trc 1 matrix 1 full 0
type: 73747473 'stts' parent:'stbl' sz: 304 179 767
track[0].stts.entries = 36
sample_count=1, sample_duration=5942
.
sample_count=2, sample_duration=5401
type: 73737473 'stss' parent:'stbl' sz: 24 483 767
keyframe_count = 2
type: 7a737473 'stsz' parent:'stbl' sz: 188 507 767
sample_size = 0 sample_count = 42
type: 63737473 'stsc' parent:'stbl' sz: 52 695 767
track[0].stsc.entries = 3
type: 6f637473 'stco' parent:'stbl' sz: 28 747 767
AVIndex stream 0, sample 0, offset 831f, dts 0, size 212746, distance 0, keyframe 1
.
AVIndex stream 0, sample 41, offset 2e28a5, dts 221935, size 68753, distance 11, keyframe 0
type: 6b617274 'trak' parent:'moov' sz: 931 1310 2233
type: 64686b74 'tkhd' parent:'trak' sz: 92 8 923
type: 6169646d 'mdia' parent:'trak' sz: 831 100 923
type: 6468646d 'mdhd' parent:'mdia' sz: 32 8 823
type: 726c6468 'hdlr' parent:'mdia' sz: 44 40 823
ctype= (0x00000000)
stype= soun
type: 666e696d 'minf' parent:'mdia' sz: 747 84 823
type: 64686d73 'smhd' parent:'minf' sz: 16 8 739
type: 666e6964 'dinf' parent:'minf' sz: 36 24 739
type: 66657264 'dref' parent:'dinf' sz: 28 8 28
type url size 12
Unknown dref type 0x08206c7275 size 12
type: 6c627473 'stbl' parent:'minf' sz: 687 60 739
type: 64737473 'stsd' parent:'stbl' sz: 91 8 679
size=75 4CC= mp4a/0x6134706d codec_type=1
audio channels 2
version =0, isom =1
type: 73647365 'esds' parent:'stsd' sz: 39 8 39
MPEG-4 description: tag=0x03 len=25
MPEG-4 description: tag=0x04 len=17
esds object type id 0x40
MPEG-4 description: tag=0x05 len=2
Specific MPEG-4 header len=2
mp4a config channels 2 obj 2 ext obj 0 sample rate 48000 ext sample rate 0
type: 73747473 'stts' parent:'stbl' sz: 32 99 679
track[1].stts.entries = 2
sample_count=1, sample_duration=1024
sample_count=113, sample_duration=1024
type: 7a737473 'stsz' parent:'stbl' sz: 476 131 679
sample_size = 0 sample_count = 114
type: 63737473 'stsc' parent:'stbl' sz: 52 607 679
track[1].stsc.entries = 3
type: 6f637473 'stco' parent:'stbl' sz: 28 659 679
AVIndex stream 1, sample 0, offset 20, dts 0, size 682, distance 0, keyframe 1
AVIndex stream 1, sample 1, offset 2ca, dts 1024, size 683, distance 0, keyframe 1
.
AVIndex stream 1, sample 99, offset 28939d, dts 101376, size 682, distance 0, keyframe 1
.
AVIndex stream 1, sample 113, offset 28b8f2, dts 115712, size 683, distance 0, keyframe 1
on_parse_exit_offset=3096055
rfps: 16.500000 0.014060
rfps: 16.583333 0.003530
rfps: 16.666667 0.000000
rfps: 16.666667 0.000000
rfps: 16.750000 0.003470
rfps: 16.750000 0.003470
rfps: 16.833333 0.013939
rfps: 50.000000 0.000001
rfps: 50.000000 0.000001
Before avformat_find_stream_info() pos: 3096055 bytes read:35009 seeks:1 nb_streams:2
nal_unit_type: 7, nal_ref_idc: 3
nal_unit_type: 8, nal_ref_idc: 3
stream 0, sample 0, dts 0
.
stream 1, sample 47, dts 1002667
nal_unit_type: 5, nal_ref_idc: 3
Reinit context to 1920x1088, pix_fmt: yuv420p
All info found
stream 0: start_time: 0.000 duration: 2.526
stream 1: start_time: 0.000 duration: 2.432
format: start_time: 0.000 duration: 2.520 bitrate=9828 kb/s
After avformat_find_stream_info() pos: 246313 bytes read:281290 seeks:2 frames:48
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Pictures/ReporterLive/VID_10072018141402.avi':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2018-07-10T08:44:06.000000Z
com.android.version: 7.0
Duration: 00:00:02.52, start: 0.000000, bitrate: 9828 kb/s
Stream #0:0(eng), 1, 1/90000: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 9551 kb/s, SAR 1:1 DAR 16:9, 16.63 fps, 16.67 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2018-07-10T08:44:06.000000Z
handler_name : VideoHandle
Stream #0:1(eng), 47, 1/48000: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
creation_time : 2018-07-10T08:44:06.000000Z
handler_name : SoundHandle
Successfully opened the file.
Parsing a group of options: output file /storage/emulated/0/Pictures/ReporterLive/VID_10072018141402_1.avi.
Applying option vf (set video filters) with argument drawtext=text='Hello Dev..':fontsize=24:fontfile=/system/fonts/DroidSans.ttf:box=1:boxcolor=black@0.5:x=w-tw:y=h-th.
Successfully parsed a group of options.
Opening an output file: /storage/emulated/0/Pictures/ReporterLive/VID_10072018141402_1.avi.
Setting default whitelist 'file,crypto'
Successfully opened the file.
No such filter: 'drawtext'
Error opening filters!
Statistics: 0 seeks, 0 writeouts
Statistics: 281290 bytes read, 2 seeksCan anyone tell what I am doing wrong ? I want to do it in the simplest form.
-
rtmp ffmpeg stream after opencv process c++
13 juin 2016, par Javier Cabrera ArteagaI want to catch video stream from live stream, process image with opencv and repacket to rtmp live stream with the original audio. The first step is done, i have the opencv processed image, but when i send to output live stream and open with some video program (eg. VLC) nothing is showing. Here is mi code. Thanks in advance.
#include <iostream>
#include <vector>
#include <map>
#include <opencv2></opencv2>opencv.hpp>
extern "C" {
//Library containing decoders and encoders for audio/video codecs.
#include <libavutil></libavutil>common.h>
#include <libavutil></libavutil>avassert.h>
#include <libavutil></libavutil>channel_layout.h>
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>mathematics.h>
#include <libavutil></libavutil>timestamp.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>
#include <libswresample></libswresample>swresample.h>
#include<libavutil></libavutil>imgutils.h>
//Library performing highly optimized image scaling and color space/pixel format conversion operations.
}
using namespace std;
struct openCVFrameContext{
cv::Mat cvFrameRGB;
bool errorStatus;
bool isEmpty;
};
char errorBuffer[80];
class Capture_FFMPEG{
public:
Capture_FFMPEG(){init();}
~Capture_FFMPEG(){close();}
virtual bool openVideoFile(const char* filename);
virtual openCVFrameContext queryFrame(AVFrame **dstAudio);
int videoStream;
int audioStream;
int currentStream;
int frameFinished;
//Video
AVFormatContext *pFormatContext;
AVCodecContext *pCodecContext;
AVCodec *pVCodec;
AVFrame *pFrame;
AVFrame *pFrameBGR;
//Video
//Audio
AVCodecContext *pACodecContext;
AVCodec *pACodec;
AVFrame *pAFrame;
//Audio
uint8_t *bufferBGR;
AVPacket pVPacket;
openCVFrameContext cvFrameContext;
struct SwsContext *pVImgConvertCtx;
protected:
virtual void init();
virtual void close();
};
//function to initialize all protected variables
void Capture_FFMPEG::init(){
videoStream = -1;
frameFinished = 0;
audioStream = -1;
currentStream = 0;
}
//Function to destroy all protected variables
void Capture_FFMPEG::close() {
if(pFrame) av_free(pFrame);
if(pFrameBGR) av_free(pFrameBGR);
if(&pVPacket) av_free(&pVPacket);
//if(pVImgConvertCtx) sws_frpeeContext(pVImgConvertCtx);
if(pFormatContext) avformat_close_input(&pFormatContext);
// if(pCodecContext) avcodec_close(pCodecContext);
}
bool Capture_FFMPEG::openVideoFile(const char *filename) {
bool statusError = false;
if(avformat_open_input(&pFormatContext, filename,NULL, NULL) != 0){
cout << "Error opening video file";
statusError = true;
}
if(avformat_find_stream_info(pFormatContext, NULL) < 0){
cout << "Error loading video information";
statusError = true;
}
av_dump_format(pFormatContext,0,filename, 0);
videoStream = -1;
audioStream = -1;
//Getting only video channel
for(int i = 0; i < pFormatContext->nb_streams; i++){
if(pFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
videoStream = i;
}
if(pFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
audioStream = i;
}
if(videoStream < 0){
cout << "Error getting video stream index" << endl;
}
if(audioStream < 0){
cout << "Error getting audio stream idex" << endl;
}
// Check video stream is > 0
pCodecContext = pFormatContext->streams[videoStream]->codec;
pVCodec = avcodec_find_decoder(pCodecContext->codec_id);
cout << "Open video decoder " << pVCodec->name << endl;
// checking opening codec
if(avcodec_open2(pCodecContext,pVCodec, NULL) < 0){
cout << "Error opening video codec" << endl;
statusError = true;
}
pFrame = av_frame_alloc();
pFrameBGR = av_frame_alloc();
int numBytes = av_image_get_buffer_size(AV_PIX_FMT_BGR24, pCodecContext->width, pCodecContext->height, 24);
cout << numBytes;
bufferBGR = (uint8_t *)av_malloc(numBytes* sizeof(uint8_t));
// av_image_alloc(pFrameBGR->data, pFrameBGR->linesize, pCodecContext->width, pCodecContext->height,
// AV_PIX_FMT_BGR24,32);
int ret = av_image_fill_arrays(pFrameBGR->data, pFrameBGR->linesize, bufferBGR,AV_PIX_FMT_BGR24,
pCodecContext->width, pCodecContext->height, 24);
cout << ret << endl;
if(ret < 0){
av_strerror(ret, errorBuffer, 80);
cout << "Could not fill image "<< errorBuffer;
}
cvFrameContext.cvFrameRGB.create(pCodecContext->height,pCodecContext->width, CV_8UC(3));
//audio
pACodecContext = pFormatContext->streams[audioStream]->codec;
pACodec = avcodec_find_decoder(pACodecContext->codec_id);
avcodec_open2(pACodecContext, pACodec, NULL);
cout << "Audio decoder " << pACodec->name << endl;
pAFrame = av_frame_alloc();
return statusError;
}
openCVFrameContext Capture_FFMPEG::queryFrame(AVFrame **audio_dst) {
if(av_read_frame(pFormatContext, &pVPacket) < 0){
cout << "Error Could not read frame" << endl;
return cvFrameContext;
}
currentStream = pVPacket.stream_index;
if(pVPacket.stream_index == videoStream){
if(avcodec_decode_video2(pCodecContext,pFrame, &frameFinished, &pVPacket) < 0){
cout << "Error could not decode video" << endl;
}
if(frameFinished){
if(pVImgConvertCtx == NULL){
pVImgConvertCtx = sws_getContext(pCodecContext->width, pCodecContext->height,
pCodecContext->pix_fmt, pCodecContext->width, pCodecContext->height, AV_PIX_FMT_BGR24, SWS_BICUBIC,
NULL,NULL, NULL);
}
// int ret = av_frame_make_writable(pFrameBGR);
// if(ret < 0) {
// av_strerror(ret, errorBuffer, 80);
// cout << "Could not write frame" << errorBuffer << endl;
// }
sws_scale(pVImgConvertCtx,(const uint8_t* const *) pFrame->data,pFrame->linesize,
0, pCodecContext->height, pFrameBGR->data,pFrameBGR->linesize );
//Populate opencv matrix
for(int y = 0; y < pCodecContext->height; y++){
for(int x = 0; x < pCodecContext->width; x++){
cvFrameContext.cvFrameRGB.at(y, x)[0] = pFrameBGR->data[0][y*pFrameBGR->linesize[0] +x*3 + 0];
cvFrameContext.cvFrameRGB.at(y, x)[1] = pFrameBGR->data[0][y*pFrameBGR->linesize[0] +x*3 + 1];
cvFrameContext.cvFrameRGB.at(y, x)[2] = pFrameBGR->data[0][y*pFrameBGR->linesize[0] +x*3 + 2];
}
}
}
}
*audio_dst = NULL;
if(pVPacket.stream_index == audioStream){
int ret = avcodec_decode_audio4(pACodecContext, pAFrame, &frameFinished, &pVPacket);
if(ret < 0){
av_strerror(ret, errorBuffer,80);
cout << "Could not decode audio " << errorBuffer << endl;
}
*audio_dst = pAFrame;
}
return cvFrameContext;
}
int main() {
av_register_all();
avformat_network_init();
Capture_FFMPEG *capture = new Capture_FFMPEG;
openCVFrameContext frame;
frame.errorStatus = false;
string fname = "/var/www/html/stream/test2.ts";
//string fname = "rtmp://127.0.0.1:1935/live/got.ts";
//string fname = "/home/javier/PycharmProjects/unmask/output.mpg";
frame.errorStatus = capture->openVideoFile(fname.c_str());
//frame.errorStatus = capture->openVideoFile("http://localhost/stream/out1.ts");
// cv::namedWindow("test", cv::WINDOW_NORMAL);
AVFormatContext* outfc = NULL;
AVIOContext * avioCTX;
outfc = avformat_alloc_context();
int ret2 = avformat_alloc_output_context2(&outfc, NULL, "mpegts", "rtmp://127.0.0.1:1935/live/test");
//int ret2 = avformat_alloc_output_context2(&outfc, NULL, NULL, "/home/javier/Videos/test.mpg");
if(ret2 < 0){
av_strerror(ret2, errorBuffer, 80);
cout << "Could not open video to encode output " << errorBuffer << endl;
}
AVCodec* outCodec = avcodec_find_encoder(AV_CODEC_ID_RAWVIDEO);
if(!outCodec){
cout << "Could not find coder" << endl;
}
AVStream* str = avformat_new_stream(outfc, outCodec);
avcodec_get_context_defaults3(str->codec, outCodec);
str->codec->width = capture->pCodecContext->width;
str->codec->height = capture->pCodecContext->height;
str->codec->pix_fmt = capture->pCodecContext->pix_fmt;
str->time_base = capture->pCodecContext->time_base;
str->codec->time_base = str->time_base;
str->codec->framerate = capture->pCodecContext->framerate;
str->codec->bit_rate = capture->pCodecContext->bit_rate;
str->codec->gop_size = capture->pCodecContext->gop_size;
str->codec->has_b_frames = capture->pCodecContext->has_b_frames;
avcodec_open2(str->codec, outCodec, NULL);
AVCodec* audioCodec = avcodec_find_encoder(outfc->oformat->audio_codec);
AVStream* audioStream = avformat_new_stream(outfc, audioCodec);
avcodec_get_context_defaults3(audioStream->codec, audioCodec);
audioStream->codec->sample_fmt = capture->pACodecContext->sample_fmt;
audioStream->codec->bit_rate = capture->pACodecContext->bit_rate;
audioStream->codec->sample_rate = capture->pACodecContext->sample_rate;
audioStream->codec->channel_layout = AV_CH_LAYOUT_STEREO;
audioStream->codec->channels = av_get_channel_layout_nb_channels(str->codec->channel_layout);
audioStream->time_base = (AVRational){1, str->codec->sample_rate};
avcodec_open2(audioStream->codec, audioCodec, NULL);
av_dump_format(outfc,0, "rtmp://127.0.0.1:1935/live/test", true);
av_dump_format(outfc,1, "rtmp://127.0.0.1:1935/live/test", true);
ret2 = avio_open2(&outfc->pb, "rtmp://127.0.0.1:1935/live/test", AVIO_FLAG_WRITE, NULL, NULL);
cout << ret2 << endl;
int ret = 0;
SwsContext* swsctx = sws_getCachedContext(
NULL, capture->pCodecContext->width, capture->pCodecContext->height, AV_PIX_FMT_BGR24,
str->codec->width, str->codec->height, str->codec->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);
AVFrame* outFrame = av_frame_alloc();
// av_frame_get_buffer(outFrame, 32);
std::vector framebuf((unsigned long)av_image_get_buffer_size(str->codec->pix_fmt, str->codec->width, str->codec->height, 24));
ret = av_image_fill_arrays(outFrame->data, outFrame->linesize, framebuf.data(), str->codec->pix_fmt, capture->pCodecContext->width,
capture->pCodecContext->height, 12);
cout << ret << endl;
if(ret < 0){
av_strerror(ret, errorBuffer, 80);
cout << "Could not fill image data empty for frame " << errorBuffer << endl;
}
outFrame->width = capture->pCodecContext->width;
outFrame->height = capture->pCodecContext->height;
outFrame->format = str->codec->pix_fmt;
// AVFrame* audioOutFrame = avcodec_alloc_frame();
int r = avformat_write_header(outfc, NULL);
if(r < 0){
av_strerror(r, errorBuffer, 80);
cout << "Could not write header "<< errorBuffer << endl;
exit(1);
}
cv::Mat gray;
cv::Mat msk;
cv::Mat copy;
cv::Mat zeros;
cv::Mat inp;
vector > contours;
vector rectangles;
int got;
int got_audio;
int frame_pts = 0;
int delay = 1;
int dst_nb_samples;
AVFrame *audioFrame;
while(1) {
frame_pts++;
cout << frame_pts << endl;
frame = capture->queryFrame(&audioFrame);
if(capture->currentStream == capture->videoStream && capture->frameFinished)
{
cv::cvtColor(frame.cvFrameRGB, gray, cv::COLOR_RGB2GRAY);
const int stride[] = {static_cast<int>(frame.cvFrameRGB.step[0])};
ret = sws_scale(swsctx, &frame.cvFrameRGB.data, stride,
0, frame.cvFrameRGB.rows, outFrame->data, outFrame->linesize);
if(ret < 0){
av_strerror(ret, errorBuffer, 80);
cout << "Could not scale "<< errorBuffer << endl;
}
outFrame->pts = capture->pVPacket.pts;
AVPacket outPck = {0};
av_init_packet(&outPck);
ret = avcodec_encode_video2(str->codec, &outPck, outFrame, &got);
if (ret < 0) {
av_strerror(ret, errorBuffer, 80);
cout << "Error encoding frame " << errorBuffer << endl;
}
av_packet_rescale_ts(&outPck,capture->pCodecContext->time_base, str->time_base);
if (got) {
outPck.stream_index = str->index;
// av_interleaved_write_frame(outfc, &outPck);
av_write_frame(outfc, &outPck);
}
av_packet_free_side_data(&outPck);
}
else{
AVPacket audioPckt = {0};
//
av_packet_ref(&audioPckt, &capture->pVPacket);
audioPckt.stream_index = 1;
av_write_frame(outfc, &audioPckt);
// av_interleaved_write_frame(outfc, &audioPckt);
av_packet_free_side_data(&audioPckt);
//
}
}
av_write_trailer(outfc);
delete capture;
return 0;
}
</int></map></vector></iostream> -
Correct command to transmit audio to ip camera using ffmpeg ?
4 novembre 2016, par the_naiveSo I found some hints in this discussion on the correct command to transmit audio to Axis IP camera through using ffmpeg in windows, but still I have not managed to successfully transmit audio to the camera.
The command I’m using is the following :
ffmpeg -v debug -y -re -f dshow -i "audio=Microphone (2- High Definition Audio Device)" -c:a pcm_mulaw -ac 1 -ar 16000 -b:a 128k -f flv http://oper
ator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi -multiple_requests 1 -reconnect_at_eof 1 -reconnect_streamed 1 -content_type "audio/basic" -reportThe ouput I get following this command is the following :
ffmpeg started on 2016-11-04 at 17:32:13
Report written to "ffmpeg-20161104-173213.log"
Command line:
ffmpeg -v debug -y -re -f dshow -i "audio=Microphone (2- High Definition Audio Device)" -c:a pcm_mulaw -ac 1 -ar 16000 -b:a 128k -f flv http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi -content_type audio/basic -multiple_requests 1 -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -report
ffmpeg version N-82225-gb4e9252 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 35.100 / 55. 35.100
libavcodec 57. 66.101 / 57. 66.101
libavformat 57. 57.100 / 57. 57.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 66.100 / 6. 66.100
libswscale 4. 3.100 / 4. 3.100
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'debug'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-re' ... matched as option 're' (read input at native frame rate) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'dshow'.
Reading option '-i' ... matched as input file with argument 'audio=Microphone (2- High Definition Audio Device)'.
Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'pcm_mulaw'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '1'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '16000'.
Reading option '-b:a' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '128k'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option 'http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi' ... matched as output file.
Reading option '-content_type' ... matched as AVOption 'content_type' with argument 'audio/basic'.
Reading option '-multiple_requests' ... matched as AVOption 'multiple_requests' with argument '1'.
Reading option '-reconnect' ... matched as AVOption 'reconnect' with argument '1'.
Reading option '-reconnect_at_eof' ... matched as AVOption 'reconnect_at_eof' with argument '1'.
Reading option '-reconnect_streamed' ... matched as AVOption 'reconnect_streamed' with argument '1'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Trailing options were found on the commandline.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument debug.
Applying option y (overwrite output files) with argument 1.
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file audio=Microphone (2- High Definition Audio Device).
Applying option re (read input at native frame rate) with argument 1.
Applying option f (force format) with argument dshow.
Successfully parsed a group of options.
Opening an input file: audio=Microphone (2- High Definition Audio Device).
[dshow @ 00000000000279e0] Selecting pin Capture on audio only
dshow passing through packet of type audio size 88200 timestamp 310221040000 orig timestamp 310221040000 graph timestamp 310226130000 diff 5090000 Microphone (2- High Definition Audio Device)
[dshow @ 00000000000279e0] All info found
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, dshow, from 'audio=Microphone (2- High Definition Audio Device)':
Duration: N/A, start: 31022.104000, bitrate: 1411 kb/s
Stream #0:0, 1, 1/10000000: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Successfully opened the file.
Parsing a group of options: output file http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi.
Applying option c:a (codec name) with argument pcm_mulaw.
Applying option ac (set number of audio channels) with argument 1.
Applying option ar (set audio sampling rate (in Hz)) with argument 16000.
Applying option b:a (video bitrate (please use -b:v)) with argument 128k.
Applying option f (force format) with argument flv.
Successfully parsed a group of options.
Opening an output file: http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi.
[http @ 0000000001c94040] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[http @ 0000000001c94040] request: POST /axis-cgi/audio/transmit.cgi HTTP/1.1
Transfer-Encoding: chunked
User-Agent: Lavf/57.57.100
Accept: */*
Expect: 100-continue
Connection: close
Host: 10.10.210.2
Icy-MetaData: 1
[http @ 0000000001c94040] request: POST /axis-cgi/audio/transmit.cgi HTTP/1.1
Transfer-Encoding: chunked
User-Agent: Lavf/57.57.100
Accept: */*
Connection: close
Host: 10.10.210.2
Icy-MetaData: 1
Authorization: Digest username="operator", realm="AXIS_ACCC8E027F47", nonce="0EcsO3xABQA=ab5efc4740a6c625ecf6a6729d0d67d2b62b615a", uri="/axis-cgi/audio/transmit.cgi", response="4bd3a627b20d6bcaba9e2f595ef6cd2a", algorithm="MD5", qop="auth", cnonce="6a579dd6664b57eb", nc=00000001
Successfully opened the file.
detected 8 logical cores
[graph 0 input from stream 0:0 @ 0000000001c9f6e0] Setting 'time_base' to value '1/44100'
[graph 0 input from stream 0:0 @ 0000000001c9f6e0] Setting 'sample_rate' to value '44100'
[graph 0 input from stream 0:0 @ 0000000001c9f6e0] Setting 'sample_fmt' to value 's16'
[graph 0 input from stream 0:0 @ 0000000001c9f6e0] Setting 'channel_layout' to value '0x3'
[graph 0 input from stream 0:0 @ 0000000001c9f6e0] tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3
[audio format for output stream 0:0 @ 0000000001c9fa20] Setting 'sample_fmts' to value 's16'
[audio format for output stream 0:0 @ 0000000001c9fa20] Setting 'sample_rates' to value '16000'
[audio format for output stream 0:0 @ 0000000001c9fa20] Setting 'channel_layouts' to value '0x4'
[audio format for output stream 0:0 @ 0000000001c9fa20] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 0:0'
[AVFilterGraph @ 000000000002ab20] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto-inserted resampler 0 @ 0000000001ca4060] [SWR @ 0000000001ca4a80] Using s16p internally between filters
[auto-inserted resampler 0 @ 0000000001ca4060] [SWR @ 0000000001ca4a80] Matrix coefficients:
[auto-inserted resampler 0 @ 0000000001ca4060] [SWR @ 0000000001ca4a80] FC: FL:0.500000 FR:0.500000
[auto-inserted resampler 0 @ 0000000001ca4060] ch:2 chl:stereo fmt:s16 r:44100Hz -> ch:1 chl:mono fmt:s16 r:16000Hz
Output #0, flv, to 'http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi':
Metadata:
encoder : Lavf57.57.100
Stream #0:0, 0, 1/1000: Audio: pcm_mulaw ([8][0][0][0] / 0x0008), 16000 Hz, mono, s16, 128 kb/s
Metadata:
encoder : Lavc57.66.101 pcm_mulaw
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_mulaw (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
av_interleaved_write_frame(): Unknown error
No more output streams to write to, finishing.
Error writing trailer of http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi: Error number -10053 occurredsize= 8kB time=00:00:00.49 bitrate= 131.2kbits/s speed=79.6x
video:0kB audio:8kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.492485%
Input file #0 (audio=Microphone (2- High Definition Audio Device)):
Input stream #0:0 (audio): 1 packets read (88200 bytes); 1 frames decoded (22050 samples);
Total: 1 packets (88200 bytes) demuxed
Output file #0 (http://operator:operator@10.10.210.2/axis-cgi/audio/transmit.cgi):
Output stream #0:0 (audio): 1 frames encoded (7984 samples); 1 packets muxed (7984 bytes);
Total: 1 packets (7984 bytes) muxed
1 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0000000001c9e4c0] Statistics: 0 seeks, 2 writeouts
dshow passing through packet of type audio size 12152 timestamp 310226130000 orig timestamp 310226130000 graph timestamp 310226820000 diff 690000 Microphone (2- High Definition Audio Device)
Conversion failed!For some reason, despite setting
multiple_requests
,reconnect_eof
,reconnect_streamed
all to true, connection becomes closed.Could you please tell me what I’m doing wrong ?