From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Cc: Marton Balint <cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 4/5] avformat/segafilmenc: use ff_format_shift_data for shifting Date: Mon, 27 Dec 2021 01:26:12 +0100 Message-ID: <20211227002613.25069-4-cus@passwd.hu> (raw) In-Reply-To: <20211227002613.25069-1-cus@passwd.hu> Signed-off-by: Marton Balint <cus@passwd.hu> --- libavformat/segafilmenc.c | 51 ++++----------------------------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c index ff8cb66aca..737805faa6 100644 --- a/libavformat/segafilmenc.c +++ b/libavformat/segafilmenc.c @@ -170,54 +170,13 @@ static int film_init(AVFormatContext *format_context) static int write_header(AVFormatContext *format_context, uint8_t *header, unsigned header_size) { - int ret = 0; - int64_t pos, pos_end; - uint8_t *buf, *read_buf[2]; - int read_buf_id = 0; - int read_size[2]; - AVIOContext *read_pb; - - buf = av_malloc(header_size); - if (!buf) - return AVERROR(ENOMEM); - read_buf[0] = buf; - read_buf[1] = header; - read_size[1] = header_size; - - /* Write the header at the beginning of the file, shifting all content as necessary; - * based on the approach used by MOV faststart. */ - avio_flush(format_context->pb); - ret = format_context->io_open(format_context, &read_pb, format_context->url, AVIO_FLAG_READ, NULL); - if (ret < 0) { - av_log(format_context, AV_LOG_ERROR, "Unable to re-open %s output file to " - "write the header\n", format_context->url); - av_free(buf); + int ret = ff_format_shift_data(format_context, 0, header_size); + if (ret < 0) return ret; - } - /* Mark the end of the shift to up to the last data we are going to write, - * and get ready for writing */ - pos_end = avio_tell(format_context->pb) + header_size; - pos = avio_seek(format_context->pb, 0, SEEK_SET); - - /* start reading at where the new header will be placed */ - avio_seek(read_pb, 0, SEEK_SET); - - /* shift data by chunk of at most header_size */ - do { - int n; - read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], - header_size); - read_buf_id ^= 1; - n = read_size[read_buf_id]; - if (n <= 0) - break; - avio_write(format_context->pb, read_buf[read_buf_id], n); - pos += n; - } while (pos < pos_end); - ff_format_io_close(format_context, &read_pb); - - av_free(buf); + avio_seek(format_context->pb, 0, SEEK_SET); + avio_write(format_context->pb, header, header_size); + return 0; } -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2021-12-27 0:26 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-27 0:26 [FFmpeg-devel] [PATCH 1/5] avformat/aviobuf: set AVIOContext->error on bprint buffer ENOMEM Marton Balint 2021-12-27 0:26 ` [FFmpeg-devel] [PATCH 2/5] avformat/movenc: factorize data shifting Marton Balint 2021-12-31 12:36 ` Andreas Rheinhardt 2021-12-27 0:26 ` [FFmpeg-devel] [PATCH 3/5] avformat/flvenc: use ff_format_shift_data for " Marton Balint 2021-12-27 0:26 ` Marton Balint [this message] 2021-12-31 12:30 ` [FFmpeg-devel] [PATCH 4/5] avformat/segafilmenc: use ff_format_shift_data for shifting Andreas Rheinhardt 2021-12-27 0:26 ` [FFmpeg-devel] [PATCH 5/5] avformat/utils: propagate return value of ff_format_io_close in ff_format_shift_data Marton Balint 2021-12-31 10:40 ` [FFmpeg-devel] [PATCH 1/5] avformat/aviobuf: set AVIOContext->error on bprint buffer ENOMEM Andreas Rheinhardt 2021-12-31 16:53 ` Marton Balint 2022-01-02 20:46 ` Marton Balint 2022-01-03 8:31 ` Andreas Rheinhardt 2022-01-03 19:18 ` Marton Balint
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211227002613.25069-4-cus@passwd.hu \ --to=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git