Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/ffmpeg.c b/ffmpeg.c
- index 5ccbf10..631ddfd 100644
- --- a/ffmpeg.c
- +++ b/ffmpeg.c
- @@ -547,7 +547,7 @@ static void update_benchmark(const char *fmt, ...)
- }
- }
- -static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- +static int write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- {
- AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
- AVCodecContext *avctx = ost->st->codec;
- @@ -567,7 +567,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- if (!(avctx->codec_type == AVMEDIA_TYPE_VIDEO && avctx->codec)) {
- if (ost->frame_number >= ost->max_frames) {
- av_free_packet(pkt);
- - return;
- + return 0;
- }
- ost->frame_number++;
- }
- @@ -647,8 +647,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- ret = av_interleaved_write_frame(s, pkt);
- if (ret < 0) {
- print_error("av_interleaved_write_frame()", ret);
- - exit_program(1);
- }
- +
- + return ret;
- }
- static void close_output_stream(OutputStream *ost)
- @@ -675,19 +676,20 @@ static int check_recording_time(OutputStream *ost)
- return 1;
- }
- -static void do_audio_out(AVFormatContext *s, OutputStream *ost,
- +static int do_audio_out(AVFormatContext *s, OutputStream *ost,
- AVFrame *frame)
- {
- AVCodecContext *enc = ost->st->codec;
- AVPacket pkt;
- int got_packet = 0;
- + int ret = 0;
- av_init_packet(&pkt);
- pkt.data = NULL;
- pkt.size = 0;
- if (!check_recording_time(ost))
- - return;
- + return 0;
- if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
- frame->pts = ost->sync_opts;
- @@ -717,13 +719,15 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
- }
- audio_size += pkt.size;
- - write_frame(s, &pkt, ost);
- + ret = write_frame(s, &pkt, ost);
- av_free_packet(&pkt);
- }
- +
- + return ret;
- }
- -static void do_subtitle_out(AVFormatContext *s,
- +static int do_subtitle_out(AVFormatContext *s,
- OutputStream *ost,
- InputStream *ist,
- AVSubtitle *sub)
- @@ -733,12 +737,13 @@ static void do_subtitle_out(AVFormatContext *s,
- AVCodecContext *enc;
- AVPacket pkt;
- int64_t pts;
- + int ret = 0;
- if (sub->pts == AV_NOPTS_VALUE) {
- av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n");
- if (exit_on_error)
- exit_program(1);
- - return;
- + return 0;
- }
- enc = ost->st->codec;
- @@ -762,7 +767,7 @@ static void do_subtitle_out(AVFormatContext *s,
- for (i = 0; i < nb; i++) {
- ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
- if (!check_recording_time(ost))
- - return;
- + return 0;
- sub->pts = pts;
- // start_display_time is required to be 0
- @@ -792,15 +797,19 @@ static void do_subtitle_out(AVFormatContext *s,
- pkt.pts += 90 * sub->end_display_time;
- }
- subtitle_size += pkt.size;
- - write_frame(s, &pkt, ost);
- + ret = write_frame(s, &pkt, ost);
- + if (ret < 0)
- + break;
- }
- +
- + return ret;
- }
- -static void do_video_out(AVFormatContext *s,
- +static int do_video_out(AVFormatContext *s,
- OutputStream *ost,
- AVFrame *in_picture)
- {
- - int ret, format_video_sync;
- + int ret = 0, format_video_sync;
- AVPacket pkt;
- AVCodecContext *enc = ost->st->codec;
- int nb_frames, i;
- @@ -870,12 +879,12 @@ static void do_video_out(AVFormatContext *s,
- if (nb_frames == 0) {
- nb_frames_drop++;
- av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
- - return;
- + return 0;
- } else if (nb_frames > 1) {
- if (nb_frames > dts_error_threshold * 30) {
- av_log(NULL, AV_LOG_ERROR, "%d frame duplication too large, skipping\n", nb_frames - 1);
- nb_frames_drop++;
- - return;
- + return 0;
- }
- nb_frames_dup += nb_frames - 1;
- av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1);
- @@ -894,7 +903,7 @@ static void do_video_out(AVFormatContext *s,
- #else
- if (ost->frame_number >= ost->max_frames)
- #endif
- - return;
- + return 0;
- if (s->oformat->flags & AVFMT_RAWPICTURE &&
- enc->codec->id == AV_CODEC_ID_RAWVIDEO) {
- @@ -913,7 +922,7 @@ static void do_video_out(AVFormatContext *s,
- pkt.flags |= AV_PKT_FLAG_KEY;
- video_size += pkt.size;
- - write_frame(s, &pkt, ost);
- + ret = write_frame(s, &pkt, ost);
- } else {
- int got_packet, forced_keyframe = 0;
- double pts_time;
- @@ -994,7 +1003,7 @@ static void do_video_out(AVFormatContext *s,
- frame_size = pkt.size;
- video_size += pkt.size;
- - write_frame(s, &pkt, ost);
- + ret = write_frame(s, &pkt, ost);
- av_free_packet(&pkt);
- /* if two pass, output log */
- @@ -1013,7 +1022,12 @@ static void do_video_out(AVFormatContext *s,
- if (vstats_filename && frame_size)
- do_video_stats(ost, frame_size);
- +
- + if (ret < 0)
- + break;
- }
- +
- + return ret;
- }
- static double psnr(double d)
- @@ -1075,6 +1089,9 @@ static int reap_filters(void)
- OutputFile *of = output_files[ost->file_index];
- int ret = 0;
- + if (ost->finished)
- + continue;
- +
- if (!ost->filter)
- continue;
- @@ -1113,7 +1130,7 @@ static int reap_filters(void)
- if (!ost->frame_aspect_ratio.num)
- ost->st->codec->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
- - do_video_out(of->ctx, ost, filtered_frame);
- + ret = do_video_out(of->ctx, ost, filtered_frame);
- break;
- case AVMEDIA_TYPE_AUDIO:
- filtered_frame->pts = frame_pts;
- @@ -1123,7 +1140,7 @@ static int reap_filters(void)
- "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
- break;
- }
- - do_audio_out(of->ctx, ost, filtered_frame);
- + ret = do_audio_out(of->ctx, ost, filtered_frame);
- break;
- default:
- // TODO support subtitle filters
- @@ -1131,6 +1148,11 @@ static int reap_filters(void)
- }
- av_frame_unref(filtered_frame);
- +
- + if (ret < 0) {
- + close_output_stream(ost);
- + break;
- + }
- }
- }
- @@ -1324,6 +1346,9 @@ static void flush_encoders(void)
- AVFormatContext *os = output_files[ost->file_index]->ctx;
- int stop_encoding = 0;
- + if (ost->finished)
- + continue;
- +
- if (!ost->encoding_needed)
- continue;
- @@ -1380,7 +1405,11 @@ static void flush_encoders(void)
- pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
- if (pkt.duration > 0)
- pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);
- - write_frame(os, &pkt, ost);
- + ret = write_frame(os, &pkt, ost);
- + if (ret < 0) {
- + stop_encoding = 1;
- + break;
- + }
- if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) {
- do_video_stats(ost, pkt.size);
- }
- @@ -1409,7 +1438,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
- return 1;
- }
- -static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
- +static int do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
- {
- OutputFile *of = output_files[ost->file_index];
- InputFile *f = input_files [ist->file_index];
- @@ -1418,27 +1447,28 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
- int64_t ist_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base);
- AVPicture pict;
- AVPacket opkt;
- + int ret = 0;
- av_init_packet(&opkt);
- if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) &&
- !ost->copy_initial_nonkeyframes)
- - return;
- + return 0;
- if (pkt->pts == AV_NOPTS_VALUE) {
- if (!ost->frame_number && ist->pts < start_time &&
- !ost->copy_prior_start)
- - return;
- + return 0;
- } else {
- if (!ost->frame_number && pkt->pts < ist_tb_start_time &&
- !ost->copy_prior_start)
- - return;
- + return 0;
- }
- if (of->recording_time != INT64_MAX &&
- ist->pts >= of->recording_time + start_time) {
- close_output_stream(ost);
- - return;
- + return 0;
- }
- if (f->recording_time != INT64_MAX) {
- @@ -1447,7 +1477,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
- start_time += f->start_time;
- if (ist->pts >= f->recording_time + start_time) {
- close_output_stream(ost);
- - return;
- + return 0;
- }
- }
- @@ -1512,8 +1542,10 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
- opkt.flags |= AV_PKT_FLAG_KEY;
- }
- - write_frame(of->ctx, &opkt, ost);
- + ret = write_frame(of->ctx, &opkt, ost);
- ost->st->codec->frame_number++;
- +
- + return ret;
- }
- int guess_input_channel_layout(InputStream *ist)
- @@ -1836,10 +1868,15 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
- for (i = 0; i < nb_output_streams; i++) {
- OutputStream *ost = output_streams[i];
- + if (ost->finished)
- + continue;
- +
- if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
- continue;
- - do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle);
- + ret = do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle);
- + if (ret < 0)
- + close_output_stream(ost);
- }
- out:
- @@ -1981,7 +2018,10 @@ static int output_packet(InputStream *ist, const AVPacket *pkt)
- if (!check_output_constraints(ist, ost) || ost->encoding_needed)
- continue;
- - do_streamcopy(ist, ost, pkt);
- + ret = do_streamcopy(ist, ost, pkt);
- + if (ret < 0) {
- + close_output_stream(ost);
- + }
- }
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement