
Recherche avancée
Médias (91)
-
Collections - Formulaire de création rapide
19 février 2013, par
Mis à jour : Février 2013
Langue : français
Type : Image
-
Les Miserables
4 juin 2012, par
Mis à jour : Février 2013
Langue : English
Type : Texte
-
Ne pas afficher certaines informations : page d’accueil
23 novembre 2011, par
Mis à jour : Novembre 2011
Langue : français
Type : Image
-
The Great Big Beautiful Tomorrow
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
-
Richard Stallman et la révolution du logiciel libre - Une biographie autorisée (version epub)
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (52)
-
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)
Sur d’autres sites (7816)
-
TCL command prompt crashed with the error "ffmpeg.exe stopped working" with tcl version 8.0 and window 7
9 février 2019, par M. D. PTCL command prompt crashed with the error "ffmpeg.exe has stopped working" with tcl version 8.0 and window 7 32 bit. my code file is "live.tcl" which is as follow :
proc live {} {
exec ffmpeg -f dshow -s 1280x720 -i "video=Logitech HD Webcam C525" -f sdl2 - >& c:/test/temp.txt &
}
liveOn the other hand same my code for video capturing i.e "videocapture.tcl" works on the same tclsh command prompt on windows 7. my tcl code for "videocapture.tcl" is :
proc videocapture {} {
exec ffmpeg -f dshow -t 00:00:10 -i "video=Integrated Webcam" c:/test/sample-a.avi >& temp.txt &
}
videocaptureerror report is as follow :
ffmpeg started on 2017-11-22 at 10:56:04
Report written to "ffmpeg-20171122-105604.log"
Command line:
ffmpeg -f dshow -s 1280x720 -i "video=HD Webcam C525" -report -f sdl2 -
ffmpeg version N-89127-g8f4702a93f Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --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-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 56. 0.100 / 56. 0.100
libavcodec 58. 3.103 / 58. 3.103
libavformat 58. 2.100 / 58. 2.100
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 2.100 / 7. 2.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Splitting the commandline.
Reading option '-f' ... matched as option 'f' (force format) with argument 'dshow'.
Reading option '-s' ... matched as option 's' (set frame size (WxH or abbreviation)) with argument '1280x720'.
Reading option '-i' ... matched as input url with argument 'video=HD Webcam C525'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'sdl2'.
Reading option '-' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url video=HD Webcam C525.
Applying option f (force format) with argument dshow.
Applying option s (set frame size (WxH or abbreviation)) with argument 1280x720.
Successfully parsed a group of options.
Opening an input file: video=HD Webcam C525.
[dshow @ 03dfca20] Selecting pin Capture on video
dshow passing through packet of type video size 1843200 timestamp 664898760000 orig timestamp 664898643970 graph timestamp 664898760000 diff 116030 HD Webcam C525
[dshow @ 03dfca20] All info found
Input #0, dshow, from 'video=HD Webcam C525':
Duration: N/A, start: 66489.876000, bitrate: N/A
Stream #0:0, 1, 1/10000000: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 10 fps, 10 tbr, 10000k tbn, 10000k tbc
Successfully opened the file.
Parsing a group of options: output url -.
Applying option f (force format) with argument sdl2.
Successfully parsed a group of options.
Opening an output file: -.
Successfully opened the file.
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
[rawvideo @ 03e01660] PACKET SIZE: 1843200, STRIDE: 2560
detected 1 logical cores
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'video_size' to value '1280x720'
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'pix_fmt' to value '1'
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'time_base' to value '1/10000000'
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 03e06ae0] Setting 'frame_rate' to value '10000000/1000000'
[graph 0 input from stream 0:0 @ 03e06ae0] w:1280 h:720 pixfmt:yuyv422 tb:1/10000000 fr:10000000/1000000 sar:0/1 sws_param:flags=2
[AVFilterGraph @ 03de2780] query_formats: 3 queried, 2 merged, 0 already done, 0 delayed
dshow passing through packet of type video size 1843200 timestamp 664899770000 orig timestamp 664899643970 graph timestamp 664899770000 diff 126030 HD Webcam C525
dshow passing through packet of type video size 1843200 timestamp 664900890000 orig timestamp 664900643970 graph timestamp 664900890000 diff 246030 HD Webcam C525
dshow passing through packet of type video size 1843200 timestamp 664902040000 orig timestamp 664901643970 graph timestamp 664902040000 diff 396030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664902650000 orig timestamp 664902643970 graph timestamp 664902650000 diff 6030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664903610000 orig timestamp 664903643970 graph timestamp 664903610000 diff -33970 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664904570000 orig timestamp 664904643970 graph timestamp 664904570000 diff -73970 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664905520000 orig timestamp 664905643970 graph timestamp 664905520000 diff -123970 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929720000 orig timestamp 664906643970 graph timestamp 664929720000 diff 23076030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929760000 orig timestamp 664907643970 graph timestamp 664929760000 diff 22116030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929790000 orig timestamp 664908643970 graph timestamp 664929790000 diff 21146030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929820000 orig timestamp 664909643970 graph timestamp 664929820000 diff 20176030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929870000 orig timestamp 664910643970 graph timestamp 664929870000 diff 19226030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929910000 orig timestamp 664911643970 graph timestamp 664929910000 diff 18266030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929940000 orig timestamp 664912643970 graph timestamp 664929940000 diff 17296030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664929980000 orig timestamp 664913643970 graph timestamp 664929980000 diff 16336030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664930030000 orig timestamp 664914643970 graph timestamp 664930030000 diff 15386030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped!
dshow passing through packet of type video size 1843200 timestamp 664930070000 orig timestamp 664915643970 graph timestamp 664930070000 diff 14426030 HD Webcam C525
[dshow @ 03dfca20] real-time buffer [HD Webcam C525] [video input] too full or near too full (121% of size: 3041280 [rtbufsize parameter])! frame dropped! -
"moov atom not found" when using av_interleaved_write_frame but not avio_write
9 octobre 2017, par icStaticI am attempting to put together a class that can take arbitrary frames and construct a video from it using the ffmpeg 3.3.3 API. I’ve been struggling to find a good example for this as the examples still seem to be using deprecated functions, so I’ve attempted to patch this using the documentation in the headers and by referring to a few github repos that seem to be using the new version.
If I use av_interleaved_write_frame to write the encoded packets to the output then ffprobe outputs the following :
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000002760120] moov atom not found0
X:\Diagnostics.mp4: Invalid data found when processing inputffplay is unable to play the file generated using this method.
If I instead swap it out for a call to avio_write, ffprobe instead outputs :
Input #0, h264, from 'X:\Diagnostics.mp4':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 672x380 [SAR 1:1 DAR 168:95], 25 fps, 25 tbr, 1200k tbn, 50 tbcffplay can mostly play this file until it gets towards the end, when it outputs :
Input #0, h264, from 'X:\Diagnostics.mp4': 0KB sq= 0B f=0/0
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 672x380 [SAR 1:1 DAR 168:95], 25 fps, 25 tbr, 1200k tbn, 50 tbc
[h264 @ 000000000254ef80] error while decoding MB 31 22, bytestream -65
[h264 @ 000000000254ef80] concealing 102 DC, 102 AC, 102 MV errors in I frame
nan M-V: nan fd= 1 aq= 0KB vq= 0KB sq= 0B f=0/0VLC cannot play files from either method. The second method’s file displays a single black frame then hides the video output. The first does not display anything. Neither of them give a video duration.
Does anyone have any ideas what’s happening here ? I assume my solution is close to working as I’m getting a good chunk of valid frames coming through.
Code :
void main()
{
OutputStream Stream( "Output.mp4", 672, 380, 25, true );
Stream.Initialize();
int i = 100;
while( i-- )
{
//... Generate a frame
Stream.WriteFrame( Frame );
}
Stream.CloseFile();
}
OutputStream::OutputStream( const std::string& Path, unsigned int Width, unsigned int Height, int Framerate, bool IsBGR )
: Stream()
, FrameIndex( 0 )
{
auto& ID = *m_InternalData;
ID.Path = Path;
ID.Width = Width;
ID.Height= Height;
ID.Framerate.num = Framerate;
ID.Framerate.den = 1;
ID.PixelFormat = IsBGR ? AV_PIX_FMT_BGR24 : AV_PIX_FMT_RGB24;
ID.CodecID = AV_CODEC_ID_H264;
ID.CodecTag = 0;
ID.AspectRatio.num = 1;
ID.AspectRatio.den = 1;
}
CameraStreamError OutputStream::Initialize()
{
av_log_set_callback( &InputStream::LogCallback );
av_register_all();
avformat_network_init();
auto& ID = *m_InternalData;
av_init_packet( &ID.Packet );
int Result = avformat_alloc_output_context2( &ID.FormatContext, nullptr, nullptr, ID.Path.c_str() );
if( Result < 0 || !ID.FormatContext )
{
STREAM_ERROR( UnknownError );
}
AVCodec* Encoder = avcodec_find_encoder( ID.CodecID );
if( !Encoder )
{
STREAM_ERROR( NoH264Support );
}
AVStream* OutStream = avformat_new_stream( ID.FormatContext, Encoder );
if( !OutStream )
{
STREAM_ERROR( UnknownError );
}
ID.CodecContext = avcodec_alloc_context3( Encoder );
if( !ID.CodecContext )
{
STREAM_ERROR( NoH264Support );
}
ID.CodecContext->time_base = av_inv_q(ID.Framerate);
{
AVCodecParameters* CodecParams = OutStream->codecpar;
CodecParams->width = ID.Width;
CodecParams->height = ID.Height;
CodecParams->format = AV_PIX_FMT_YUV420P;
CodecParams->codec_id = ID.CodecID;
CodecParams->codec_type = AVMEDIA_TYPE_VIDEO;
CodecParams->profile = FF_PROFILE_H264_MAIN;
CodecParams->level = 40;
Result = avcodec_parameters_to_context( ID.CodecContext, CodecParams );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
}
if( ID.IsVideo )
{
ID.CodecContext->width = ID.Width;
ID.CodecContext->height = ID.Height;
ID.CodecContext->sample_aspect_ratio = ID.AspectRatio;
ID.CodecContext->time_base = av_inv_q(ID.Framerate);
if( Encoder->pix_fmts )
{
ID.CodecContext->pix_fmt = Encoder->pix_fmts[0];
}
else
{
ID.CodecContext->pix_fmt = ID.PixelFormat;
}
}
//Snip
Result = avcodec_open2( ID.CodecContext, Encoder, nullptr );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
Result = avcodec_parameters_from_context( OutStream->codecpar, ID.CodecContext );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
if( ID.FormatContext->oformat->flags & AVFMT_GLOBALHEADER )
{
ID.CodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
OutStream->time_base = ID.CodecContext->time_base;
OutStream->avg_frame_rate= av_inv_q(OutStream->time_base);
if( !( ID.FormatContext->oformat->flags & AVFMT_NOFILE ) )
{
Result = avio_open( &ID.FormatContext->pb, ID.Path.c_str(), AVIO_FLAG_WRITE );
if( Result < 0 )
{
STREAM_ERROR( FileNotWriteable );
}
}
Result = avformat_write_header( ID.FormatContext, nullptr );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
ID.Output = std::make_unique( ID.CodecContext->width, ID.CodecContext->height, ID.CodecContext->pix_fmt );
ID.ConversionContext = sws_getCachedContext(
ID.ConversionContext,
ID.Width,
ID.Height,
ID.PixelFormat,
ID.CodecContext->width,
ID.CodecContext->height,
ID.CodecContext->pix_fmt,
SWS_BICUBIC,
NULL,
NULL,
NULL );
return CameraStreamError::Success;
}
CameraStreamError OutputStream::WriteFrame( FFMPEG::Frame* Frame )
{
auto& ID = *m_InternalData;
ID.Output->Prepare();
int OutputSliceSize = sws_scale( m_InternalData->ConversionContext, Frame->GetFrame()->data, Frame->GetFrame()->linesize, 0, Frame->GetHeight(), ID.Output->GetFrame()->data, ID.Output->GetFrame()->linesize );
ID.Output->GetFrame()->pts = ID.CodecContext->frame_number;
int Result = avcodec_send_frame( GetData().CodecContext, ID.Output->GetFrame() );
if( Result == AVERROR(EAGAIN) )
{
CameraStreamError ResultErr = SendAll();
if( ResultErr != CameraStreamError::Success )
{
return ResultErr;
}
Result = avcodec_send_frame( GetData().CodecContext, ID.Output->GetFrame() );
}
if( Result == 0 )
{
CameraStreamError ResultErr = SendAll();
if( ResultErr != CameraStreamError::Success )
{
return ResultErr;
}
}
FrameIndex++;
return CameraStreamError::Success;
}
CameraStreamError OutputStream::SendAll( void )
{
auto& ID = *m_InternalData;
int Result;
do
{
AVPacket TempPacket = {};
av_init_packet( &TempPacket );
Result = avcodec_receive_packet( GetData().CodecContext, &TempPacket );
if( Result == 0 )
{
av_packet_rescale_ts( &TempPacket, ID.CodecContext->time_base, ID.FormatContext->streams[0]->time_base );
TempPacket.stream_index = ID.FormatContext->streams[0]->index;
//avio_write( ID.FormatContext->pb, TempPacket.data, TempPacket.size );
Result = av_interleaved_write_frame( ID.FormatContext, &TempPacket );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
av_packet_unref( &TempPacket );
}
else if( Result != AVERROR(EAGAIN) )
{
continue;
}
else if( Result != AVERROR_EOF )
{
break;
}
else if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
} while ( Result == 0);
return CameraStreamError::Success;
}
CameraStreamError OutputStream::CloseFile()
{
auto& ID = *m_InternalData;
while( true )
{
//Flush
int Result = avcodec_send_frame( ID.CodecContext, nullptr );
if( Result == 0 )
{
CameraStreamError StrError = SendAll();
if( StrError != CameraStreamError::Success )
{
return StrError;
}
}
else if( Result == AVERROR_EOF )
{
break;
}
else
{
STREAM_ERROR( WriteFailed );
}
}
int Result = av_write_trailer( ID.FormatContext );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
if( !(ID.FormatContext->oformat->flags& AVFMT_NOFILE) )
{
Result = avio_close( ID.FormatContext->pb );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
}
return CameraStreamError::Success;
}Note I’ve simplified a few things and inlined a few bits that were elsewhere. I’ve also removed all the shutdown code as anything that happens after the file is closed is irrelevant.
Full repo here : https://github.com/IanNorris/Witness If you clone this the issue is with the ’Diagnostics’ output, the Output file is fine. There are two hardcoded paths to X :.
-
"moov atom not found" when using av_interleaved_write_frame but not avio_write
9 octobre 2017, par icStaticI am attempting to put together a class that can take arbitrary frames and construct a video from it using the ffmpeg 3.3.3 API. I’ve been struggling to find a good example for this as the examples still seem to be using deprecated functions, so I’ve attempted to patch this using the documentation in the headers and by referring to a few github repos that seem to be using the new version.
If I use av_interleaved_write_frame to write the encoded packets to the output then ffprobe outputs the following :
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000002760120] moov atom not found0
X:\Diagnostics.mp4: Invalid data found when processing inputffplay is unable to play the file generated using this method.
If I instead swap it out for a call to avio_write, ffprobe instead outputs :
Input #0, h264, from 'X:\Diagnostics.mp4':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 672x380 [SAR 1:1 DAR 168:95], 25 fps, 25 tbr, 1200k tbn, 50 tbcffplay can mostly play this file until it gets towards the end, when it outputs :
Input #0, h264, from 'X:\Diagnostics.mp4': 0KB sq= 0B f=0/0
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 672x380 [SAR 1:1 DAR 168:95], 25 fps, 25 tbr, 1200k tbn, 50 tbc
[h264 @ 000000000254ef80] error while decoding MB 31 22, bytestream -65
[h264 @ 000000000254ef80] concealing 102 DC, 102 AC, 102 MV errors in I frame
nan M-V: nan fd= 1 aq= 0KB vq= 0KB sq= 0B f=0/0VLC cannot play files from either method. The second method’s file displays a single black frame then hides the video output. The first does not display anything. Neither of them give a video duration.
Does anyone have any ideas what’s happening here ? I assume my solution is close to working as I’m getting a good chunk of valid frames coming through.
Code :
void main()
{
OutputStream Stream( "Output.mp4", 672, 380, 25, true );
Stream.Initialize();
int i = 100;
while( i-- )
{
//... Generate a frame
Stream.WriteFrame( Frame );
}
Stream.CloseFile();
}
OutputStream::OutputStream( const std::string& Path, unsigned int Width, unsigned int Height, int Framerate, bool IsBGR )
: Stream()
, FrameIndex( 0 )
{
auto& ID = *m_InternalData;
ID.Path = Path;
ID.Width = Width;
ID.Height= Height;
ID.Framerate.num = Framerate;
ID.Framerate.den = 1;
ID.PixelFormat = IsBGR ? AV_PIX_FMT_BGR24 : AV_PIX_FMT_RGB24;
ID.CodecID = AV_CODEC_ID_H264;
ID.CodecTag = 0;
ID.AspectRatio.num = 1;
ID.AspectRatio.den = 1;
}
CameraStreamError OutputStream::Initialize()
{
av_log_set_callback( &InputStream::LogCallback );
av_register_all();
avformat_network_init();
auto& ID = *m_InternalData;
av_init_packet( &ID.Packet );
int Result = avformat_alloc_output_context2( &ID.FormatContext, nullptr, nullptr, ID.Path.c_str() );
if( Result < 0 || !ID.FormatContext )
{
STREAM_ERROR( UnknownError );
}
AVCodec* Encoder = avcodec_find_encoder( ID.CodecID );
if( !Encoder )
{
STREAM_ERROR( NoH264Support );
}
AVStream* OutStream = avformat_new_stream( ID.FormatContext, Encoder );
if( !OutStream )
{
STREAM_ERROR( UnknownError );
}
ID.CodecContext = avcodec_alloc_context3( Encoder );
if( !ID.CodecContext )
{
STREAM_ERROR( NoH264Support );
}
ID.CodecContext->time_base = av_inv_q(ID.Framerate);
{
AVCodecParameters* CodecParams = OutStream->codecpar;
CodecParams->width = ID.Width;
CodecParams->height = ID.Height;
CodecParams->format = AV_PIX_FMT_YUV420P;
CodecParams->codec_id = ID.CodecID;
CodecParams->codec_type = AVMEDIA_TYPE_VIDEO;
CodecParams->profile = FF_PROFILE_H264_MAIN;
CodecParams->level = 40;
Result = avcodec_parameters_to_context( ID.CodecContext, CodecParams );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
}
if( ID.IsVideo )
{
ID.CodecContext->width = ID.Width;
ID.CodecContext->height = ID.Height;
ID.CodecContext->sample_aspect_ratio = ID.AspectRatio;
ID.CodecContext->time_base = av_inv_q(ID.Framerate);
if( Encoder->pix_fmts )
{
ID.CodecContext->pix_fmt = Encoder->pix_fmts[0];
}
else
{
ID.CodecContext->pix_fmt = ID.PixelFormat;
}
}
//Snip
Result = avcodec_open2( ID.CodecContext, Encoder, nullptr );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
Result = avcodec_parameters_from_context( OutStream->codecpar, ID.CodecContext );
if( Result < 0 )
{
STREAM_ERROR( EncoderCreationError );
}
if( ID.FormatContext->oformat->flags & AVFMT_GLOBALHEADER )
{
ID.CodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
OutStream->time_base = ID.CodecContext->time_base;
OutStream->avg_frame_rate= av_inv_q(OutStream->time_base);
if( !( ID.FormatContext->oformat->flags & AVFMT_NOFILE ) )
{
Result = avio_open( &ID.FormatContext->pb, ID.Path.c_str(), AVIO_FLAG_WRITE );
if( Result < 0 )
{
STREAM_ERROR( FileNotWriteable );
}
}
Result = avformat_write_header( ID.FormatContext, nullptr );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
ID.Output = std::make_unique( ID.CodecContext->width, ID.CodecContext->height, ID.CodecContext->pix_fmt );
ID.ConversionContext = sws_getCachedContext(
ID.ConversionContext,
ID.Width,
ID.Height,
ID.PixelFormat,
ID.CodecContext->width,
ID.CodecContext->height,
ID.CodecContext->pix_fmt,
SWS_BICUBIC,
NULL,
NULL,
NULL );
return CameraStreamError::Success;
}
CameraStreamError OutputStream::WriteFrame( FFMPEG::Frame* Frame )
{
auto& ID = *m_InternalData;
ID.Output->Prepare();
int OutputSliceSize = sws_scale( m_InternalData->ConversionContext, Frame->GetFrame()->data, Frame->GetFrame()->linesize, 0, Frame->GetHeight(), ID.Output->GetFrame()->data, ID.Output->GetFrame()->linesize );
ID.Output->GetFrame()->pts = ID.CodecContext->frame_number;
int Result = avcodec_send_frame( GetData().CodecContext, ID.Output->GetFrame() );
if( Result == AVERROR(EAGAIN) )
{
CameraStreamError ResultErr = SendAll();
if( ResultErr != CameraStreamError::Success )
{
return ResultErr;
}
Result = avcodec_send_frame( GetData().CodecContext, ID.Output->GetFrame() );
}
if( Result == 0 )
{
CameraStreamError ResultErr = SendAll();
if( ResultErr != CameraStreamError::Success )
{
return ResultErr;
}
}
FrameIndex++;
return CameraStreamError::Success;
}
CameraStreamError OutputStream::SendAll( void )
{
auto& ID = *m_InternalData;
int Result;
do
{
AVPacket TempPacket = {};
av_init_packet( &TempPacket );
Result = avcodec_receive_packet( GetData().CodecContext, &TempPacket );
if( Result == 0 )
{
av_packet_rescale_ts( &TempPacket, ID.CodecContext->time_base, ID.FormatContext->streams[0]->time_base );
TempPacket.stream_index = ID.FormatContext->streams[0]->index;
//avio_write( ID.FormatContext->pb, TempPacket.data, TempPacket.size );
Result = av_interleaved_write_frame( ID.FormatContext, &TempPacket );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
av_packet_unref( &TempPacket );
}
else if( Result != AVERROR(EAGAIN) )
{
continue;
}
else if( Result != AVERROR_EOF )
{
break;
}
else if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
} while ( Result == 0);
return CameraStreamError::Success;
}
CameraStreamError OutputStream::CloseFile()
{
auto& ID = *m_InternalData;
while( true )
{
//Flush
int Result = avcodec_send_frame( ID.CodecContext, nullptr );
if( Result == 0 )
{
CameraStreamError StrError = SendAll();
if( StrError != CameraStreamError::Success )
{
return StrError;
}
}
else if( Result == AVERROR_EOF )
{
break;
}
else
{
STREAM_ERROR( WriteFailed );
}
}
int Result = av_write_trailer( ID.FormatContext );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
if( !(ID.FormatContext->oformat->flags& AVFMT_NOFILE) )
{
Result = avio_close( ID.FormatContext->pb );
if( Result < 0 )
{
STREAM_ERROR( WriteFailed );
}
}
return CameraStreamError::Success;
}Note I’ve simplified a few things and inlined a few bits that were elsewhere. I’ve also removed all the shutdown code as anything that happens after the file is closed is irrelevant.
Full repo here : https://github.com/IanNorris/Witness If you clone this the issue is with the ’Diagnostics’ output, the Output file is fine. There are two hardcoded paths to X :.