
Recherche avancée
Médias (1)
-
The Great Big Beautiful Tomorrow
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
Autres articles (47)
-
Les statuts des instances de mutualisation
13 mars 2010, parPour des raisons de compatibilité générale du plugin de gestion de mutualisations avec les fonctions originales de SPIP, les statuts des instances sont les mêmes que pour tout autre objets (articles...), seuls leurs noms dans l’interface change quelque peu.
Les différents statuts possibles sont : prepa (demandé) qui correspond à une instance demandée par un utilisateur. Si le site a déjà été créé par le passé, il est passé en mode désactivé. publie (validé) qui correspond à une instance validée par un (...) -
Support audio et vidéo HTML5
10 avril 2011MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...) -
HTML5 audio and video support
13 avril 2011, parMediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
For older browsers the Flowplayer flash fallback is used.
MediaSPIP allows for media playback on major mobile platforms with the above (...)
Sur d’autres sites (9202)
-
Video encoding and keyframes
24 février 2013, par TishuI am transcoding a video frame by frame and using x264+ffmpeg to encode. The original video plays fine, but the first few frames of my transcoded vide show grey artefacts. I understand this is because of time compression and these artefacts disappear after a few frames.
See these two pictures which are the first and second frames. The third frame is normal (i.e. no grey artefact and not blurry like the second one)
How can I force the first frame to be a key frame (ie fully encoded in my output video) so that these artefacts do not show ?
Edit - more details
Here is what I am doing more in details. I used bit form differents tutorials to read a video frame by frame and reencode each frame to a new video. My encoding parameters are the following :
avcodec_get_context_defaults3(c, *codec);
c->codec_id = codec_id;
c->bit_rate = output_bitrate;
/* Resolution must be a multiple of two. */
c->width = output_width;
c->height = output_height;
/* timebase: This is the fundamental unit of time (in seconds) in terms
* of which frame timestamps are represented. For fixed-fps content,
* timebase should be 1/framerate and timestamp increments should be
* identical to 1. */
st->r_frame_rate.num = output_framerate_num;
st->r_frame_rate.den = output_framerate_den;
c->time_base.den = output_timebase_den;
c->time_base.num = output_timebase_num;
c->gop_size = 3; /* emit one intra frame every twelve frames at most */
c->pix_fmt = STREAM_PIX_FMT;
if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
/* just for testing, we also add B frames */
c->max_b_frames = 2;
}
if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
/* Needed to avoid using macroblocks in which some coeffs overflow.
* This does not happen with normal video, it just happens here as
* the motion of the chroma plane does not match the luma plane. */
c->mb_decision = 2;
}
c->max_b_frames = 2;
c->scenechange_threshold = 0;
c->rc_buffer_size = 0;
c->me_method = ME_ZERO;Then I process each frame, probably doing something wrong there. The decoding bit :
while(av_read_frame(gFormatCtx, &packet)>=0) {
// Is this a packet from the video stream?
if(packet.stream_index==gVideoStreamIndex) {
// Decode video frame
avcodec_decode_video2(gVideoCodecCtx, pCurrentFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
[...]
if(firstPts == -999) /*Initial value*/
firstPts = packet.pts;
deltaPts = packet.pts - firstPts;
double seconds = deltaPts*av_q2d(gFormatCtx->streams[gVideoStreamIndex]->time_base);
[...]
muxing_writeVideoFrame(pCurrentFrame, packet.pts);
}
}
}The actual writing :
int muxing_writeVideoFrame(AVFrame *frame, int64_t pts)
{
frameCount = frameCount +1;
if(frameCount > 0)
{
if (video_st)
video_pts = (double)video_st->pts.val * video_st->time_base.num /
video_st->time_base.den;
else
video_pts = 0.0;
if (video_st && !(video_st && audio_st && audio_pts < video_pts))
{
frame->pts = pts;//av_rescale_q(frame_count, video_st->codec->time_base, video_st->time_base);
write_video_frame(oc, video_st, frame);
}
}
return 0;
}
static int write_video_frame(AVFormatContext *oc, AVStream *st, AVFrame *frame)
{
int ret;
static struct SwsContext *sws_ctx;
//LOGI(10, frame_count);
AVCodecContext *c = st->codec;
/* encode the image */
AVPacket pkt;
int got_output;
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
if (ret < 0) {
fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
exit(1);
}
/* If size is zero, it means the image was buffered. */
if (got_output) {
if (c->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index = st->index;
/* Write the compressed frame to the media file. */
ret = av_interleaved_write_frame(oc, &pkt);
} else {
ret = 0;
}
if (ret != 0) {
LOGI(10, av_err2str(ret));
exit(1);
}
frame_count++;
return got_output;
} -
Why does the frame count change when scaling with FFmpeg ?
22 octobre 2016, par ajmicekI use this to scale 1920x1080 H.264 videos :
ffmpeg -i IMG_1438.MOV -threads 2 -vf scale=-2:600 IMG_1438_scaledTo600.MOV
And it works great ! But here is my question : most of the time, the frame rate stays exactly the same between the original file and the scaled file. For example :
$ mediainfo -F IMG_1426.MOV | grep Frame\ rate
Frame rate : 29.970
Frame rate : 29.970 FPS
Frame rate mode : VFR
Frame rate mode : Variable
Frame rate : 29.970
Frame rate : 29.970 (29970/1000) FPS
$ mediainfo -F IMG_1426_scaledTo600.MOV | grep Frame\ rate
Frame rate : 29.970
Frame rate : 29.970 FPS
Frame rate mode : CFR
Frame rate mode : Constant
Frame rate : 29.970
Frame rate : 29.970 (30000/1001) FPSBut sometimes, the frame rate increases dramatically :
$ mediainfo -F IMG_1438.MOV | grep Frame\ rate
Frame rate : 25.044
Frame rate : 25.044 FPS
Frame rate mode : VFR
Frame rate mode : Variable
Frame rate : 25.044
Frame rate : 25.044 FPS
$ mediainfo -F IMG_1438_scaledTo600.MOV | grep Frame\ rate
Frame rate : 120.000
Frame rate : 120.000 FPS
Frame rate mode : CFR
Frame rate mode : Constant
Frame rate : 120.000
Frame rate : 120.000 FPSWhat should I know about FFmpeg or libx264 or libswscale that will help me understand why this happens ? (Hoping to hear from LordNeckbeard, in particular).
mediainfo IMG_1438.MOV --Full
outputs :General
Count : 327
Count of stream of this kind : 1
Kind of stream : General
Kind of stream : General
Stream identifier : 0
Count of video streams : 1
Count of audio streams : 1
OtherCount : 2
Video_Format_List : AVC
Video_Format_WithHint_List : AVC
Codecs Video : AVC
Audio_Format_List : AAC
Audio_Format_WithHint_List : AAC
Audio codecs : AAC LC
Complete name : IMG_1438.MOV
File name : IMG_1438
File extension : MOV
Format : MPEG-4
Format : MPEG-4
Format/Extensions usually used : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
Commercial name : MPEG-4
Format profile : QuickTime
Internet media type : video/mp4
Codec ID : qt
Codec ID : qt 0000.00 (qt )
Codec ID/Url : http://www.apple.com/quicktime/download/standalone.html
CodecID_Version : 0000.00
CodecID_Compatible : qt
Codec : MPEG-4
Codec : MPEG-4
Codec/Extensions usually used : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
File size : 113990140
File size : 109 MiB
File size : 109 MiB
File size : 109 MiB
File size : 109 MiB
File size : 108.7 MiB
Duration : 52268
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 00:00:52.268
Duration : 00:00:52:09
Duration : 00:00:52.268 (00:00:52:09)
Overall bit rate : 17447026
Overall bit rate : 17.4 Mb/s
Frame rate : 25.044
Frame rate : 25.044 FPS
Frame count : 1309
Stream size : 56670
Stream size : 55.3 KiB (0%)
Stream size : 55 KiB
Stream size : 55 KiB
Stream size : 55.3 KiB
Stream size : 55.34 KiB
Stream size : 55.3 KiB (0%)
Proportion of this stream : 0.00050
HeaderSize : 28
DataSize : 113966271
FooterSize : 23841
IsStreamable : No
Encoded date : UTC 2016-10-08 22:51:19
Tagged date : UTC 2016-10-08 22:52:12
File last modification date : UTC 2016-10-08 22:51:19
File last modification date (local) : 2016-10-08 17:51:19
Writing library : Apple QuickTime
Writing library : Apple QuickTime
Encoded_Library_Name : Apple QuickTime
com.apple.quicktime.make : Apple
com.apple.quicktime.model : iPhone 5
com.apple.quicktime.software : 10.0.2
com.apple.quicktime.creationdate : 2016-10-08T17:51:19-0500
Video
Count : 334
Count of stream of this kind : 1
Kind of stream : Video
Kind of stream : Video
Stream identifier : 0
StreamOrder : 0
ID : 1
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format/Url : http://developers.videolan.org/x264.html
Commercial name : AVC
Format profile : High@L4.1
Format settings : CABAC / 1 Ref Frames
Format settings, CABAC : Yes
Format settings, CABAC : Yes
Format settings, ReFrames : 1
Format settings, ReFrames : 1 frame
Internet media type : video/H264
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Codec ID/Url : http://www.apple.com/quicktime/download/standalone.html
Codec : AVC
Codec : AVC
Codec/Family : AVC
Codec/Info : Advanced Video Codec
Codec/Url : http://developers.videolan.org/x264.html
Codec/CC : avc1
Codec profile : High@L4.1
Codec settings : CABAC / 1 Ref Frames
Codec settings, CABAC : Yes
Codec_Settings_RefFrames : 1
Duration : 52268
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 00:00:52.268
Duration : 00:00:52:09
Duration : 00:00:52.268 (00:00:52:09)
Bit rate : 17375530
Bit rate : 17.4 Mb/s
Width : 1920
Width : 1 920 pixels
Height : 1080
Height : 1 080 pixels
Stored_Height : 1088
Sampled_Width : 1920
Sampled_Height : 1080
Pixel aspect ratio : 1.000
Display aspect ratio : 1.778
Display aspect ratio : 16:9
Rotation : 90.000
Rotation : 90°
Frame rate mode : VFR
Frame rate mode : Variable
Frame rate : 25.044
Frame rate : 25.044 FPS
Minimum frame rate : 23.077
Minimum frame rate : 23.077 FPS
Maximum frame rate : 30.000
Maximum frame rate : 30.000 FPS
Frame count : 1309
Resolution : 8
Resolution : 8 bits
Colorimetry : 4:2:0
Color space : YUV
Chroma subsampling : 4:2:0
Chroma subsampling : 4:2:0
Bit depth : 8
Bit depth : 8 bits
Scan type : Progressive
Scan type : Progressive
Interlacement : PPF
Interlacement : Progressive
Bits/(Pixel*Frame) : 0.335
Stream size : 113523046
Stream size : 108 MiB (100%)
Stream size : 108 MiB
Stream size : 108 MiB
Stream size : 108 MiB
Stream size : 108.3 MiB
Stream size : 108 MiB (100%)
Proportion of this stream : 0.99590
Title : Core Media Video
Encoded date : UTC 2016-10-08 22:51:19
Tagged date : UTC 2016-10-08 22:52:12
Color range : Limited
colour_description_present : Yes
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Audio
Count : 272
Count of stream of this kind : 1
Kind of stream : Audio
Kind of stream : Audio
Stream identifier : 0
StreamOrder : 1
ID : 2
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Commercial name : AAC
Format profile : LC
Codec ID : 40
Codec : AAC LC
Codec : AAC LC
Codec/Family : AAC
Codec/CC : 40
Duration : 52268
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 00:00:52.268
Duration : 00:00:52:15
Duration : 00:00:52.268 (00:00:52:15)
Source duration : 52338
Source duration : 52 s 338 ms
Source duration : 52 s 338 ms
Source duration : 52 s 338 ms
Source duration : 00:00:52.338
Bit rate mode : CBR
Bit rate mode : Constant
Bit rate : 64000
Bit rate : 64.0 kb/s
Channel(s) : 1
Channel(s) : 1 channel
Channel positions : Front: C
Channel positions : 1/0/0
ChannelLayout : C
Samples per frame : 1024
Sampling rate : 44100
Sampling rate : 44.1 kHz
Samples count : 2305019
Frame rate : 43.066
Frame rate : 43.066 FPS (1024 spf)
Frame count : 2251
Source frame count : 2254
Compression mode : Lossy
Compression mode : Lossy
Stream size : 410424
Stream size : 401 KiB (0%)
Stream size : 401 KiB
Stream size : 401 KiB
Stream size : 401 KiB
Stream size : 400.8 KiB
Stream size : 401 KiB (0%)
Proportion of this stream : 0.00360
Source stream size : 410894
Source stream size : 401 KiB (0%)
Source stream size : 401 KiB
Source stream size : 401 KiB
Source stream size : 401 KiB
Source stream size : 401.3 KiB
Source stream size : 401 KiB (0%)
Source_StreamSize_Proportion : 0.00360
Title : Core Media Audio
Encoded date : UTC 2016-10-08 22:51:19
Tagged date : UTC 2016-10-08 22:52:12
Other #1
Count : 112
Count of stream of this kind : 2
Kind of stream : Other
Kind of stream : Other
Stream identifier : 0
Stream identifier : 1
Type : meta
Duration : 52268
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 00:00:52.268
Duration : 00:00:52.268
Frame count : 6
Bit rate mode : VBR
Other #2
Count : 112
Count of stream of this kind : 2
Kind of stream : Other
Kind of stream : Other
Stream identifier : 1
Stream identifier : 2
Type : meta
Duration : 52268
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 52 s 268 ms
Duration : 00:00:52.268
Duration : 00:00:52.268
Frame count : 1
Bit rate mode : CBRand
ffprobe IMG_1438.MOV
outputs :ffprobe version 3.1.3 Copyright (c) 2007-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.1.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --disable-lzma --enable-vda
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_1438.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2016-10-08 22:51:19
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 5
com.apple.quicktime.software: 10.0.2
com.apple.quicktime.creationdate: 2016-10-08T17:51:19-0500
Duration: 00:00:52.27, start: 0.000000, bitrate: 17446 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 17375 kb/s, 25.04 fps, 120 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 90
creation_time : 2016-10-08 22:51:19
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 62 kb/s (default)
Metadata:
creation_time : 2016-10-08 22:51:19
handler_name : Core Media Data Handler
Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-10-08 22:51:19
handler_name : Core Media Data Handler
Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-10-08 22:51:19
handler_name : Core Media Data Handler
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3UPDATE
To clarify : my video above, the one with the high framerate (120 FPS) output after scaling, plays perfectly before and after scaling with FFmpeg (no sync issues, and 120 FPS is only about 14% larger in file size), I am simply trying to understand why this increase in framerate happens (just a little beyond Mulvya’s note that the framerate stored in the container is wrong).From a programming perspective, the initial issue I ran into was that I was using
frame=
from FFmpeg’s sterr console output to determine progress, which reports erroneous results when the frame count increases dramatically on output ("I’m 372% done encoding ?!") ; I have since read another stackoverflow answer and changed my code to usetime=
, which appears to be a more robust way for me to display FFmpeg progress. (Also, there is FFmpeg’s-progress
option, of course).Improving on the original command
My new command to scale, preserve a useful framerate, and optimize threads :
ffmpeg -i IMG_1438.MOV -vf scale=-2:600 -r 30 -vsync 0 IMG_1438_scaledTo600.MOV
Where
30
is the "Maximum frame rate" frommediainfo
.Thanks to help in the comments, I now know I do not fully understand FFmpeg’s use of three different time bases for timestamps :
tbn
,tbc
, andtbr
.
They were explained by Robert Swain in 2009 and his explanation was also used to answer a Stackoverflow question about tbn, tbc, tbr.It sounds to me, as I’m pulling together comments from Mulvya below and Michael Rampe at another forum, that
tbr
is guessed ; it is frequently but not always the best value to use when changing from a variable to a constant frame rate video.Which leaves these 2 questions...
(1)
tbr
is incorrect when "field rate and frame rate" differ ? Does this happen a lot ?
(2) Is-r 30
where30
is the maximum frame rate reported bymediainfo
the best way to do it for most codec/container combinations ? (Or should I only use this method when I am scaling a H.264/MPEG-4 AVC video ?) -
ffmpeg universal audio decoder failing on certain wma files
6 septembre 2016, par Steve MI’m trying to build a small universal audio decoding library that decodes the file a frame at a time. I’ve built a command line static ffmpeg that I can exec that works on every file format I have tested. Now I am trying to build a shared library version, so I can directly decode frame by frame. I seem to have success, except it is failing on certain WMA files. FFprobe of a file that is failing (file plays on every music player, and command line ffmpeg with same build configuration shows no problems) :
Input #0, asf, from 'a.wma':
Metadata:
WM/Track : 0
track : 1
WM/MediaPrimaryClassID: {D1607DBC-E323-4BE2-86A1-48A42A28441E}
WM/EncodingTime : 2139839136
WMFSDKVersion : 11.0.5721.5145
WMFSDKNeeded : 0.0.0.0000
AverageLevel : 10107
PeakValue : 32673
IsVBR : 0
DeviceConformanceTemplate: M0
WM/WMADRCPeakReference: 32766
WM/WMADRCPeakTarget: 32766
WM/WMADRCAverageReference: 12733
WM/WMADRCAverageTarget: 12733
Duration: 00:00:29.94, start: 0.000000, bitrate: 50 kb/s
Stream #0:0: Audio: wmapro (b[1][0][0] / 0x0162), 44100 Hz, stereo, fltp, 48 kb/sHere’s my code for initializing and opening file and the decode function :
FFMpegAudioDecoder::FFMpegAudioDecoder(int samplerate) : len(0), index(0), samplerate(samplerate)
{
av_register_all();
avformat_network_init();
pFormatCtx = avformat_alloc_context();
}
const char* FFMpegAudioDecoder::open(const char *path, bool metaOnly, int offset, int length)
{
const char* error = "File could not be opened";
//this->path = path;
if(avformat_open_input(&pFormatCtx,path,NULL,NULL)!=0){
return error;
}
if(avformat_find_stream_info(pFormatCtx,NULL)<0){
return error;
}
// Dump valid information onto standard error
//av_dump_format(pFormatCtx, 0, path, false);
// Find the best audio stream
audioStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);
if(audioStream < 0){
return error;
}
pCodecCtx=pFormatCtx->streams[audioStream]->codec;
// Find the decoder for the audio stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL){
return error;
}
// Open codec
if(avcodec_open2(pCodecCtx, pCodec,NULL)<0){
return error;
}
packet=(AVPacket *)av_malloc(sizeof(AVPacket));
av_init_packet(packet);
//Out Audio Param
out_channel_layout=AV_CH_LAYOUT_STEREO;
//nb_samples: AAC-1024 MP3-1152
out_nb_samples=pCodecCtx->frame_size;
out_sample_fmt=AV_SAMPLE_FMT_S16;
out_sample_rate=samplerate;
out_channels=av_get_channel_layout_nb_channels(out_channel_layout);
//Out Buffer Size
out_buffer_size=av_samples_get_buffer_size(NULL,out_channels ,out_nb_samples,out_sample_fmt, 1);
out_buffer=(uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE*3);
pFrame=av_frame_alloc();
//FIX:Some Codec's Context Information is missing
in_sample_fmt = pCodecCtx->sample_fmt;
in_channel_layout=av_get_default_channel_layout(pCodecCtx->channels);
//Swr
initConverter();
timeBase = (int64_t(pCodecCtx->time_base.num) * AV_TIME_BASE) / int64_t(pCodecCtx->time_base.den);
LOGI("Opened file");
return nullptr;
}
void FFMpegAudioDecoder::initConverter()
{
au_convert_ctx = swr_alloc();
au_convert_ctx=swr_alloc_set_opts(au_convert_ctx,out_channel_layout, out_sample_fmt, out_sample_rate,
in_channel_layout,in_sample_fmt, pCodecCtx->sample_rate,0, NULL);
swr_init(au_convert_ctx);
}
unsigned char FFMpegAudioDecoder::decode(short int *pcmOutput, unsigned int *samples)
{
unsigned int samplesWritten = 0;
//LOGI("BEFORE FRAME");
int read = av_read_frame(pFormatCtx, packet);
//LOGI("AFTER FRAME");
if (read < 0)
{
char msg[101];
av_strerror(read, msg, 100);
LOGI("EOF, %s", msg);
return AUDIODECODER_EOF;
}
if(packet->stream_index==audioStream)
{
//LOGI("BEFORE DECODE");
ret = avcodec_decode_audio4( pCodecCtx, pFrame, &got_picture, packet);
const char* msg1 = av_get_sample_fmt_name((AVSampleFormat)pFrame->format);
const char* msg2 = av_get_sample_fmt_name(in_sample_fmt);
LOGI("samples formats, pFrame->format: %s, in_sample_fmt: %s", msg1, msg2);
if (pFrame->format != in_sample_fmt)
{
LOGI("FORMAT CHANGED!@!!!!!, decode return value: %d", ret);
in_sample_fmt = (AVSampleFormat) pFrame->format;
swr_free(&au_convert_ctx);
initConverter();
}
LOGI("Decode return value: %d, packet->size: %d", ret, packet->size);
//LOGI("AFTER DECODE");
if ( ret < 0 ) {
char msg[101];
av_strerror(ret, msg, 100);
LOGI("decoder return value error, %s", msg);
//return AUDIODECODER_ERROR;
}
else if ( got_picture > 0 ){
//LOGI("BEFORE CONVERT");
int converted = swr_convert(au_convert_ctx,&out_buffer, MAX_AUDIO_FRAME_SIZE,(const uint8_t **)&pFrame->data , pFrame->nb_samples);
// LOGI("AFTER CONVERT");
if ( converted < 0 ) {
LOGI("CONVERT ERROR");
return AUDIODECODER_ERROR;
}
for (int i = 0; i < converted * 4; i += 2)
{
pcmOutput[i / 2] = (short int)(out_buffer[i+1]<<8 | (out_buffer[i] & 0xFF));
}
samplesWritten = (unsigned int) converted;
//LOGI("after write");
//LOGI("index:%5d\t pts:%lld\t packet size:%d\t samples written:%d",index,packet->pts,packet->size,samplesWritten);
index++;
}
}
av_packet_unref(packet);
//LOGI("after free, writte:%u", samplesWritten);
*samples = samplesWritten;
return AUDIODECODER_OK;
}The file reaches EOF after only 1-2 seconds and there is no audio. On a sample run with the WMA file the
packet->format
is set to null and there are strange return values from the decode4 function, here is the log with some redundancy cut :09-05 16:21:51.839 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: fltp
09-05 16:21:51.839 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: FORMAT CHANGED!@!!!!!, decode return value: 2
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 2, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 682, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 206, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 194, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 26, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 100, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.880 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 68, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 2230, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 49, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 65, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 216, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 123, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 146, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.881 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 24, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 162, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 90, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 15, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 290, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 220, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 118, packet->size: 2230
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.882 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 135, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 171, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 267, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 56, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: 90, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: Decode return value: -1094995529, packet->size: 2230
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: decoder return value error, Invalid data found when processing input
09-05 16:21:51.883 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: samples formats, pFrame->format: (null), in_sample_fmt: (null)
09-05 16:21:51.885 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: EOF, End of file
09-05 16:21:51.885 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: DECODELOOP EOF 2
09-05 16:21:51.886 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: EOF, End of file
09-05 16:21:51.887 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: DECODELOOP EOF 2
09-05 16:21:51.888 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: EOF, End of file
09-05 16:21:51.888 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: DECODELOOP EOF 2
09-05 16:21:51.916 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: EOF, End of file
09-05 16:21:51.916 5116-5332/com.smp.musicspeed I/SOUNDPROCESS: DECODELOOP EOF 2