Hi,

I am encountering frequent crashes with current libav when encoding
live MPEG2 streams. This seems to be caused by the recent
multithreading changes in error_resilience.c.

The problem is, that after the ff_thread_await_progress, picture's
motion_val and ref_index can still sometimes be NULL, which causes the
segfault. I tried to add a simple sanity check (attached) which solves
the problem here, but I don't know if it's a proper solution.

Sample mpeg-ts stream: http://geraldine.fjfi.cvut.cz/~makovicka/stream.dump

To reproduce: ./ffmpeg -y -i stream.dump out.mpg

Regards,
-- 
Jindrich Makovicka
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index aea0e15..c939733 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -534,9 +534,19 @@ skip_mean_and_median:
                             ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
                                                      mb_y, 0);
                         }
-                        prev_x = s->last_picture.motion_val[0][mot_index][0];
-                        prev_y = s->last_picture.motion_val[0][mot_index][1];
-                        prev_ref = s->last_picture.ref_index[0][4*mb_xy];
+
+                        if (s->last_picture.motion_val[0]) {
+                            prev_x = s->last_picture.motion_val[0][mot_index][0];
+                            prev_y = s->last_picture.motion_val[0][mot_index][1];
+                        } else {
+                            prev_x = s->current_picture.motion_val[0][mot_index][0];
+                            prev_y = s->current_picture.motion_val[0][mot_index][1];
+                        }
+                        if (s->last_picture.ref_index[0]) {
+                            prev_ref = s->last_picture.ref_index[0][4*mb_xy];
+                        } else {
+                            prev_ref = s->current_picture.ref_index[0][4*mb_xy];
+                        }
                     } else {
                         prev_x = s->current_picture.motion_val[0][mot_index][0];
                         prev_y = s->current_picture.motion_val[0][mot_index][1];
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to