This fixes an issue where video-only scripts and audio-only
scripts would work correctly, but video+audio scripts wouldn't
output any audio.

Seeking was also broken as a result of this issue with scripts
serving both not outputting audio.  Moving to av_packet_from_data
also makes seeking work as expected again.
---
 libavformat/avisynth.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 10a0740..5811ba6 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -443,7 +443,7 @@ static int avisynth_read_packet_video(AVFormatContext *s, 
AVPacket *pkt,
     AVS_VideoFrame *frame;
     unsigned char *dst_p;
     const unsigned char *src_p;
-    int n, i, plane, rowsize, planeheight, pitch, bits;
+    int n, i, plane, rowsize, planeheight, pitch, bits, ret;
     const char *error;
 
     if (avs->curr_frame >= avs->vi->num_frames)
@@ -482,9 +482,15 @@ static int avisynth_read_packet_video(AVFormatContext *s, 
AVPacket *pkt,
     if (!pkt->size)
         return AVERROR_UNKNOWN;
 
-    if (av_new_packet(pkt, pkt->size) < 0)
+    pkt->data = av_malloc(pkt->size);
+    if (!pkt->data)
         return AVERROR(ENOMEM);
 
+    if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) {
+        av_packet_unref(pkt);
+        return ret;
+    }
+
     frame = avs_library.avs_get_frame(avs->clip, n);
     error = avs_library.avs_clip_get_error(avs->clip);
     if (error) {
@@ -523,7 +529,7 @@ static int avisynth_read_packet_audio(AVFormatContext *s, 
AVPacket *pkt,
 {
     AviSynthContext *avs = s->priv_data;
     AVRational fps, samplerate;
-    int samples;
+    int samples, ret;
     int64_t n;
     const char *error;
 
@@ -570,9 +576,15 @@ static int avisynth_read_packet_audio(AVFormatContext *s, 
AVPacket *pkt,
     if (!pkt->size)
         return AVERROR_UNKNOWN;
 
-    if (av_new_packet(pkt, pkt->size) < 0)
+    pkt->data = av_malloc(pkt->size);
+    if (!pkt->data)
         return AVERROR(ENOMEM);
 
+    if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) {
+        av_packet_unref(pkt);
+        return ret;
+    }
+
     avs_library.avs_get_audio(avs->clip, pkt->data, n, samples);
     error = avs_library.avs_clip_get_error(avs->clip);
     if (error) {
-- 
1.8.3.2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to