Mutex FFMPEG::fflock("FFMPEG::fflock");
-static void ff_err(int ret, const char *msg)
+static void ff_err(int ret, const char *fmt, ...)
{
- char errmsg[BCSTRLEN]; av_strerror(ret, errmsg, sizeof(errmsg));
- fprintf(stderr,"%s: %s\n",msg, errmsg);
+ char msg[BCTEXTLEN];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(msg, sizeof(msg), fmt, ap);
+ va_end(ap);
+ char errmsg[BCSTRLEN];
+ av_strerror(ret, errmsg, sizeof(errmsg));
+ fprintf(stderr,_("%s err: %s\n"),msg, errmsg);
}
FFPacket::FFPacket()
if( ret >= 0 ) return 1;
st_eof(1);
if( ret == AVERROR_EOF ) return 0;
- fprintf(stderr, "FFStream::read_packet: av_read_frame failed\n");
+ ff_err(ret, "FFStream::read_packet: av_read_frame failed\n");
flushed = 1;
return -1;
}
if( ret < 0 ) {
if( ret == AVERROR(EAGAIN) ) return 0;
if( ret == AVERROR_EOF ) { st_eof(1); return -1; }
- fprintf(stderr, "FFStream::read_filter: av_buffersink_get_frame failed\n");
+ ff_err(ret, "FFStream::read_filter: av_buffersink_get_frame failed\n");
return ret;
}
return 1;
int ret = swr_convert(resample_context,
(uint8_t**)&aud_bfr, aud_bfr_sz, (const uint8_t**)data, len);
if( ret < 0 ) {
- fprintf(stderr, "FFAudioStream::load_history: swr_convert failed\n");
+ ff_err(ret, "FFAudioStream::load_history: swr_convert failed\n");
return -1;
}
samples = aud_bfr;
{
int ret = avcodec_decode_audio4(st->codec, frame, &got_frame, ipkt);
if( ret < 0 ) {
- fprintf(stderr, "FFAudioStream::decode_frame: Could not read audio frame\n");
+ ff_err(ret, "FFAudioStream::decode_frame: Could not read audio frame\n");
return -1;
}
return ret;
frame->sample_rate = ctx->sample_rate;
int ret = av_frame_get_buffer(frame, 0);
if (ret < 0)
- fprintf(stderr, "FFAudioStream::init_frame: av_frame_get_buffer failed\n");
+ ff_err(ret, "FFAudioStream::init_frame: av_frame_get_buffer failed\n");
return ret;
}
curr_pos += frame->nb_samples;
}
}
- if( flushed && end_pos > curr_pos ) {
+ if( end_pos > curr_pos ) {
zero(end_pos - curr_pos);
curr_pos = end_pos;
}
return 0;
}
if( pos == curr_pos ) return 0;
+ if( !st->codec || !st->codec->codec ) return -1;
avcodec_flush_buffers(st->codec);
double secs = (double)pos / sample_rate;
int64_t tstmp = secs * st->time_base.den / st->time_base.num;
(uint8_t **)frame->extended_data, frame_sz,
(const uint8_t **)&bfrp, frame_sz);
if( ret < 0 ) {
- fprintf(stderr, "FFAudioStream::encode: swr_convert failed\n");
+ ff_err(ret, "FFAudioStream::encode: swr_convert failed\n");
break;
}
frm->queue(curr_pos);
{
int ret = avcodec_decode_video2(st->codec, frame, &got_frame, ipkt);
if( ret < 0 ) {
- fprintf(stderr, "FFVideoStream::decode_frame: Could not read video frame\n");
+ ff_err(ret, "FFVideoStream::decode_frame: Could not read video frame\n");
return -1;
}
if( got_frame )
if( gop < 4 ) gop = 4;
if( gop > 64 ) gop = 64;
if( pos >= curr_pos && pos <= curr_pos + gop ) return 0;
+ if( pos == curr_pos-1 && curr_pos > seek_pos ) return 0;
+ if( !st->codec || !st->codec->codec ) return -1;
avcodec_flush_buffers(st->codec);
// back up a few frames to read up to current to help repair damages
if( (pos-=gop) < 0 ) pos = 0;
" sws_getCachedContext() failed\n");
return 1;
}
- if( sws_scale(convert_ctx, ip->data, ip->linesize, 0, ih,
- opic.data, opic.linesize) < 0 ) {
- fprintf(stderr, "FFVideoStream::convert_picture_frame: sws_scale() failed\n");
+ int ret = sws_scale(convert_ctx, ip->data, ip->linesize, 0, ih,
+ opic.data, opic.linesize);
+ if( ret < 0 ) {
+ ff_err(ret, "FFVideoStream::convert_picture_frame: sws_scale() failed\n");
return 1;
}
return 0;
" sws_getCachedContext() failed\n");
return 1;
}
- if( sws_scale(convert_ctx, opic.data, opic.linesize, 0, frame->get_h(),
- op->data, op->linesize) < 0 ) {
- fprintf(stderr, "FFVideoStream::convert_frame_picture: sws_scale() failed\n");
+ int ret = sws_scale(convert_ctx, opic.data, opic.linesize, 0, frame->get_h(),
+ op->data, op->linesize);
+ if( ret < 0 ) {
+ ff_err(ret, "FFVideoStream::convert_frame_picture: sws_scale() failed\n");
return 1;
}
return 0;
AVRational FFMPEG::to_sample_aspect_ratio(double aspect_ratio)
{
+#if 1
int height = 1000000, width = height * aspect_ratio;
float w, h;
MWindow::create_aspect_ratio(w, h, width, height);
return (AVRational){(int)w, (int)h};
+#else
+// square pixels
+ return (AVRational){1, 1};
+#endif
}
AVRational FFMPEG::to_time_base(int sample_rate)
return 1;
}
if( get_encoder(fp, format, codec, bsfilter, bsargs) )
- eprintf("FFMPEG::get_encoder:"
- " err: format/codec not found %s\n", options);
+ eprintf(_("FFMPEG::get_encoder:"
+ " err: format/codec not found %s\n"), options);
fclose(fp);
return 0;
}
if( line[0] == '\n' ) continue;
char key[BCSTRLEN], val[BCTEXTLEN];
if( scan_option_line(line, key, val) ) {
- eprintf("FFMPEG::read_options:"
- " err reading %s: line %d\n", options, no);
+ eprintf(_("FFMPEG::read_options:"
+ " err reading %s: line %d\n"), options, no);
ret = 1;
}
if( !ret ) {
for( int i=0; i<(int)fmt_ctx->nb_streams; ++i ) {
AVStream *st = fmt_ctx->streams[i];
AVCodecContext *avctx = st->codec;
- report("stream %d, id 0x%06x:\n", i, avctx->codec_id);
+ report(_("stream %d, id 0x%06x:\n"), i, avctx->codec_id);
const AVCodecDescriptor *desc = avcodec_descriptor_get(avctx->codec_id);
if( avctx->codec_type == AVMEDIA_TYPE_VIDEO ) {
AVRational framerate = av_guess_frame_rate(fmt_ctx, st, 0);
report(" %d:%02d:%05.2f\n", hrs, mins, secs);
}
else
- report(" codec_type unknown\n");
+ report(_(" codec_type unknown\n"));
}
report("\n");
for( int i=0; i<(int)fmt_ctx->nb_programs; ++i ) {
break;
}
if( asset->ff_audio_bitrate > 0 ) {
+ ctx->bit_rate = asset->ff_audio_bitrate;
char arg[BCSTRLEN];
sprintf(arg, "%d", asset->ff_audio_bitrate);
av_dict_set(&sopts, "b", arg, 0);
break;
}
if( asset->ff_video_bitrate > 0 ) {
+ ctx->bit_rate = asset->ff_video_bitrate;
char arg[BCSTRLEN];
sprintf(arg, "%d", asset->ff_video_bitrate);
av_dict_set(&sopts, "b", arg, 0);
int FFMPEG::encode_activate()
{
+ int ret = 0;
if( encoding < 0 ) {
encoding = 0;
if( !(fmt_ctx->flags & AVFMT_NOFILE) &&
- avio_open(&fmt_ctx->pb, fmt_ctx->filename, AVIO_FLAG_WRITE) < 0 ) {
- fprintf(stderr, "FFMPEG::encode_activate: err opening : %s\n",
+ (ret=avio_open(&fmt_ctx->pb, fmt_ctx->filename, AVIO_FLAG_WRITE)) < 0 ) {
+ ff_err(ret, "FFMPEG::encode_activate: err opening : %s\n",
fmt_ctx->filename);
return 1;
}
char option_path[BCTEXTLEN];
set_option_path(option_path, "format/%s", file_format);
read_options(option_path, fopts);
- int ret = avformat_write_header(fmt_ctx, &fopts);
+ ret = avformat_write_header(fmt_ctx, &fopts);
av_dict_free(&fopts);
if( ret < 0 ) {
- fprintf(stderr, "FFMPEG::encode_activate: write header failed %s\n",
+ ff_err(ret, "FFMPEG::encode_activate: write header failed %s\n",
fmt_ctx->filename);
return 1;
}