The encoder has a separate concept of width and stride so is possible
to map directly the AVFrame to the input_frame.
---

While implementing the Libav wrapper I wondered if would be possible
avoid the framecopy. Looks like it is.

 cli/cli.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/cli/cli.c b/cli/cli.c
index 376062e..8bf6c3b 100644
--- a/cli/cli.c
+++ b/cli/cli.c
@@ -205,6 +205,9 @@ void video_data_clear(video_data *v)
     free(v->enc_buf); v->enc_buf = NULL;
     free(v->enc_output_frame.bs); v->enc_output_frame.bs = NULL;
     close_input_file(&v->ifd);
+    #ifndef F265_NO_LIBAV
+    if (v->ifd.yuv_flag)
+    #endif
     for (int i = 0; i < 3; i++) { free(v->planes[i]); v->planes[i] = NULL; }
     close_output_file(&v->ofd);
 }
@@ -414,17 +417,8 @@ int read_nonyuv_frame(video_data *v)
         /* Read each component. The YUV samples are ordered per line. */
         for (uint32_t i = 0; i < 3; i++)
         {
-            uint8_t *read_plane = ifd->frame->data[i];
-            uint8_t *write_plane = v->planes[i];
-            uint32_t read_pitch = ifd->frame->linesize[i];
-            uint32_t nb = v->width[i];
-
-            for (uint32_t line = 0; line < v->height[i]; line++)
-            {
-                memcpy(write_plane, read_plane, nb);
-                read_plane += read_pitch;
-                write_plane += nb;
-            }
+            v->enc_input_frame.planes[i] = ifd->frame->data[i];
+            v->enc_input_frame.stride[i] = ifd->frame->linesize[i];
         }
     }

@@ -627,6 +621,9 @@ void set_frame_dimensions(video_data *v)
         v->height[1+i] = v->height[0] / 2;
     }

+    if (!v->ifd.yuv_flag)
+        return;
+
     /* Allocate the planes. */
     for (uint32_t i = 0; i < 3; i++)
     {
--
1.9.0

--
To unsubscribe visit http://f265.org
or send a mail to [email protected].

Reply via email to