diff mbox

[FFmpeg-devel,1/4] ffmpeg: re-copy codec parameters after encoding

Message ID 1475087343-29745-3-git-send-email-jtoohill@google.com
State Changes Requested
Headers show

Commit Message

Jon Toohill Sept. 28, 2016, 6:29 p.m. UTC
This preserves changes to fields of AVCodecParameters that
get updated during encoding, such as trailing_padding
(which may not be known until encoding is complete).
---
 ffmpeg.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Michael Niedermayer Sept. 28, 2016, 11:42 p.m. UTC | #1
On Wed, Sep 28, 2016 at 11:29:00AM -0700, Jon Toohill wrote:
> This preserves changes to fields of AVCodecParameters that
> get updated during encoding, such as trailing_padding
> (which may not be known until encoding is complete).
> ---
>  ffmpeg.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

this breaks 165 fate tests

[...]
diff mbox

Patch

diff --git a/ffmpeg.c b/ffmpeg.c
index d0f247e..0cdc762 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4255,6 +4255,21 @@  static int transcode(void)
 
     term_exit();
 
+    /* update output codec parameters after encoding */
+    for (i = 0; i < nb_output_streams; i++) {
+        ost = output_streams[i];
+        if (ost->encoding_needed) {
+            ret = avcodec_parameters_from_context(
+                output_files[ost->file_index]->ctx->streams[ost->index]->codecpar,
+                ost->enc_ctx);
+            if (ret < 0) {
+                av_log(ost, AV_LOG_ERROR, "Error copying final codec context: %s\n", av_err2str(ret));
+                if (exit_on_error)
+                    exit_program(1);
+            }
+        }
+    }
+
     /* write the trailer if needed and close file */
     for (i = 0; i < nb_output_files; i++) {
         os = output_files[i]->ctx;