
Recherche avancée
Autres articles (41)
-
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...) -
Submit bugs and patches
13 avril 2011Unfortunately a software is never perfect.
If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
You may also (...) -
Le plugin : Podcasts.
14 juillet 2010, parLe problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
Types de fichiers supportés dans les flux
Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...)
Sur d’autres sites (7154)
-
Losing quality when encoding with ffmpeg
22 mai 2016, par lupodI am using the c libraries of ffmpeg to read frames from a video and create an output file that is supposed to be identical to the input.
However, somewhere during this process some quality gets lost and the result is "less sharp". My guess is that the problem is the encoding and that the frames are too compressed (also because the size of the file decreases quite significantly). Is there some parameter in the encoder that allows me to control the quality of the result ? I found that AVCodecContext has a compression_level member, but changing it that does not seem to have any effect.I post here part of my code in case it could help. I would say that something must be changed in the init function of OutputVideoBuilder when I set the codec. The AVCodecContext that is passed to the method is the same of InputVideoHandler.
Here are the two main classes that I created to wrap the ffmpeg functionalities :// This class opens the video files and sets the decoder
class InputVideoHandler {
public:
InputVideoHandler(char* name);
~InputVideoHandler();
AVCodecContext* getCodecContext();
bool readFrame(AVFrame* frame, int* success);
private:
InputVideoHandler();
void init(char* name);
AVFormatContext* formatCtx;
AVCodec* codec;
AVCodecContext* codecCtx;
AVPacket packet;
int streamIndex;
};
void InputVideoHandler::init(char* name) {
streamIndex = -1;
int numStreams;
if (avformat_open_input(&formatCtx, name, NULL, NULL) != 0)
throw std::exception("Invalid input file name.");
if (avformat_find_stream_info(formatCtx, NULL)<0)
throw std::exception("Could not find stream information.");
numStreams = formatCtx->nb_streams;
if (numStreams < 0)
throw std::exception("No streams in input video file.");
for (int i = 0; i < numStreams; i++) {
if (formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
streamIndex = i;
break;
}
}
if (streamIndex < 0)
throw std::exception("No video stream in input video file.");
// find decoder using id
codec = avcodec_find_decoder(formatCtx->streams[streamIndex]->codec->codec_id);
if (codec == nullptr)
throw std::exception("Could not find suitable decoder for input file.");
// copy context from input stream
codecCtx = avcodec_alloc_context3(codec);
if (avcodec_copy_context(codecCtx, formatCtx->streams[streamIndex]->codec) != 0)
throw std::exception("Could not copy codec context from input stream.");
if (avcodec_open2(codecCtx, codec, NULL) < 0)
throw std::exception("Could not open decoder.");
}
// frame must be initialized with av_frame_alloc() before!
// Returns true if there are other frames, false if not.
// success == 1 if frame is valid, 0 if not.
bool InputVideoHandler::readFrame(AVFrame* frame, int* success) {
*success = 0;
if (av_read_frame(formatCtx, &packet) < 0)
return false;
if (packet.stream_index == streamIndex) {
avcodec_decode_video2(codecCtx, frame, success, &packet);
}
av_free_packet(&packet);
return true;
}
// This class opens the output and write frames to it
class OutputVideoBuilder{
public:
OutputVideoBuilder(char* name, AVCodecContext* inputCtx);
~OutputVideoBuilder();
void writeFrame(AVFrame* frame);
void writeVideo();
private:
OutputVideoBuilder();
void init(char* name, AVCodecContext* inputCtx);
void logMsg(AVPacket* packet, AVRational* tb);
AVFormatContext* formatCtx;
AVCodec* codec;
AVCodecContext* codecCtx;
AVStream* stream;
};
void OutputVideoBuilder::init(char* name, AVCodecContext* inputCtx) {
if (avformat_alloc_output_context2(&formatCtx, NULL, NULL, name) < 0)
throw std::exception("Could not determine file extension from provided name.");
codec = avcodec_find_encoder(inputCtx->codec_id);
if (codec == nullptr) {
throw std::exception("Could not find suitable encoder.");
}
codecCtx = avcodec_alloc_context3(codec);
if (avcodec_copy_context(codecCtx, inputCtx) < 0)
throw std::exception("Could not copy output codec context from input");
codecCtx->time_base = inputCtx->time_base;
codecCtx->compression_level = 0;
if (avcodec_open2(codecCtx, codec, NULL) < 0)
throw std::exception("Could not open encoder.");
stream = avformat_new_stream(formatCtx, codec);
if (stream == nullptr) {
throw std::exception("Could not allocate stream.");
}
stream->id = formatCtx->nb_streams - 1;
stream->codec = codecCtx;
stream->time_base = codecCtx->time_base;
av_dump_format(formatCtx, 0, name, 1);
if (!(formatCtx->oformat->flags & AVFMT_NOFILE)) {
if (avio_open(&formatCtx->pb, name, AVIO_FLAG_WRITE) < 0) {
throw std::exception("Could not open output file.");
}
}
if (avformat_write_header(formatCtx, NULL) < 0) {
throw std::exception("Error occurred when opening output file.");
}
}
void OutputVideoBuilder::writeFrame(AVFrame* frame) {
AVPacket packet = { 0 };
int success;
av_init_packet(&packet);
if (avcodec_encode_video2(codecCtx, &packet, frame, &success))
throw std::exception("Error encoding frames");
if (success) {
av_packet_rescale_ts(&packet, codecCtx->time_base, stream->time_base);
packet.stream_index = stream->index;
logMsg(&packet,&stream->time_base);
av_interleaved_write_frame(formatCtx, &packet);
}
av_free_packet(&packet);
}This is the part of the main function that reads and write frames :
while (inputHandler->readFrame(frame,&gotFrame)) {
if (gotFrame) {
try {
outputBuilder->writeFrame(frame);
}
catch (std::exception e) {
std::cout << e.what() << std::endl;
return -1;
}
}
} -
How to estimate in Node audio bitrate, bytes, duration without ffmpeg
6 mai 2016, par loretoparisiSupposed to not have access to
ffmpeg
I need a simple way to calculate thebitrate
of an audio (or video) file given media length (bytes) and duration (seconds), i.e. the functionbitrate = MediaInfo.bitrate(bytes, duration);
Also I need to do the opposite, so that given approximate media
bitrate
andlength
I need calculate theduration
:duration = MediaInfo.duration(bytes, bitrate);
So, this is my attempt, inspired by bitrate node module :
var console = {
log: function(s) {
document.getElementById("console").innerHTML += s + "<br />"
}
}
/**
* Get media file info
* @see https://www.npmjs.com/package/bitrate
* * @author Loreto Parisi (loretoparisi at gmail dot com)
*/
var MediaInfo = {
/** unit divisors */
DIVISORS : {
bps: 0.125,
kbps: 125,
mbps: 125000,
Bps: 1,
KBps: 1000,
MBps: 1000000
},
/**
* Calcuate approximate bitrate
* @param bytes integer media length in bytes
* @param seconds float media duration
* @param format string: bps|kbps|Bps|KBps|MBps
* @param pos integer decimal approximation
*/
bitrate : function(bytes, seconds, format, pos) {
if (typeof format !== 'string') throw new TypeError('Expected \'format\' to be a string')
format = format.replace('/', 'p')
var divisor = this.DIVISORS[format];
if (!divisor) throw new Error('\'format\' is an invalid string')
var bitrate = bytes / seconds / divisor;
pos=pos||4;
return (Math.round(bitrate * Math.pow(10,pos)) / Math.pow(10,pos) );
},
/**
* Calcuate media bytes
* @param bitrate float media bitrate per seconds
* @param seconds float media duration
* @param format string: bps|kbps|Bps|KBps|MBps
* @param pos integer decimal approximation
*/
bytes : function(bitrate, seconds, format) {
if (typeof format !== 'string') throw new TypeError('Expected \'format\' to be a string')
format = format.replace('/', 'p')
var divisor = this.DIVISORS[format];
if (!divisor) throw new Error('\'format\' is an invalid string')
var bytes = bitrate * seconds * divisor;
return ( Math.round(bytes) );
}, //bytes
/**
* Calcuate approximate duration
* @param bytes integer media length in bytes
* @param bitrate float media bitrate per seconds
* @param format string: bps|kbps|Bps|KBps|MBps
* @param pos integer decimal approximation
*/
duration : function(bytes, bitrate, format, pos) {
if (typeof format !== 'string') throw new TypeError('Expected \'format\' to be a string')
format = format.replace('/', 'p')
var divisor = this.DIVISORS[format];
if (!divisor) throw new Error('\'format\' is an invalid string')
var seconds = bytes / bitrate / divisor;
pos=pos||4;
return (Math.round(seconds * Math.pow(10,pos)) / Math.pow(10,pos) );
}
} //MediaInfo
// example of usage
var bytes = 57511; // media file size in bytes
var seconds = 20.35 // media file duration in seconds
// calculate media bitrate given media length and duration
var kilobitsPerSecond = MediaInfo.bitrate(bytes, seconds, 'kbps', 3) // => 326.3
var bitsPerSecond = MediaInfo.bitrate(bytes, seconds, 'bps', 3) // => 326279
var BytesPerSecond = MediaInfo.bitrate(bytes, seconds, 'Bps', 3) // => 40785
// inverse: calculate media duration given media length and bitrate
var duration = MediaInfo.duration(bytes, kilobitsPerSecond, 'kbps', 3);
// estimated bytes length given bitrate and duration
var estimatedBytes = MediaInfo.bytes(kilobitsPerSecond, duration, 'kbps', 3);
var data = {
bytes : bytes,
seconds : seconds,
kilobitsPerSecond : kilobitsPerSecond + " kb/s",
bitsPerSecond : bitsPerSecond + " b/s",
BytesPerSecond : BytesPerSecond + " B/s",
duration : duration,
estimatedBytes : estimatedBytes
}
console.log( JSON.stringify(data, null, 2) );<div></div>
The result media info are
{
"bytes": 57511,
"seconds": 20.35,
"kilobitsPerSecond": "22.609 kb/s",
"bitsPerSecond": "22608.747 b/s",
"BytesPerSecond": "2826.093 B/s",
"duration": 20.35,
"estimatedBytes": 57512
}while
ffmpeg
givesDuration: 00:00:20.35, start: 0.000000, bitrate: 22 kb/s
Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 16 kb/s (default)Of course, the problem here is the assumption that I have a fixed bitrate when calculating the
duration
. But, is there any other way without having ffprobe or lame in node ?Note. A good options, where the media file has ID3 tagging, is to use the JSMediaTags node module that supports
ID3
andMP4
tagging for media files and works both in the browser that in node :var jsmediatags = require("jsmediatags");
jsmediatags.read("./music-file.mp3", {
onSuccess: function(tag) {
console.log(tag);
},
onError: function(error) {
console.log(':(', error.type, error.info);
}
});This will not work for streaming media files or for files coming from direct audio sources of course.
-
ffmpeg error : Data doesn't look like RTP packets, make sure the RTP muxer is used
29 juin 2016, par SOFuserI am trying to stream both video&audio from usbcam&mic throw ffmpeg over ffserver
I got 2 errors :
- ffmpeg seems functionning but showing "Data doesn’t look like RTP packets, make sure the RTP muxer is used"
- i can connect to ffserver only for static fileshere is server.conf file :
HTTPPort 1235
RTSPPort 1234
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 100000
#CustomLog –
########################################
## static file for testing
########################################
#HTTP requests
<stream>
File "/home/username/media.flv"
Format flv
</stream>
#RTSP requests
<stream>
#preconverted file:
File "/home/username/media.mpg"
Format rtp
VideoFrameRate 30
VideoCodec libx264
VideoSize 720x720
StartSendOnKey
Preroll 0
</stream>
##################################################
## usb cam
###################################################
<feed>
File /tmp/test.ffm
FileMaxSize 20K
ACL allow 192.168.1.149
</feed>
<stream>
Feed test.ffm
Format rtp
VideoFrameRate 25
VideoCodec libx264
VideoSize 720x720
PreRoll 0
StartSendOnKey
</stream>my ffmpeg cmd is
ffmpeg -s 720x720 -f video4linux2 -i /dev/video0 -r 25 -f alsa -i hw:0 -c:v libx264 -c:a aac -strict -2 rtp://192.168.1.149:1234/test.ffm
it seems working but showing this error :
"Data doesn’t look like RTP packets, make sure the RTP muxer is used"
when i stream the static files it works
but when i try to play usbcam stream throw ffplay and vlc nothing worksthank you in advance,