[FFmpeg-devel] [PATCH 2/3] lavf/srtenc: do not print more line breaks than necessary.

Clément Bœsch ubitux at gmail.com
Sun Oct 21 03:29:07 CEST 2012


---
 libavformat/srtenc.c         | 12 ++++++++++--
 tests/ref/fate/sub-subripenc |  2 +-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavformat/srtenc.c b/libavformat/srtenc.c
index 42a264e..d92f559 100644
--- a/libavformat/srtenc.c
+++ b/libavformat/srtenc.c
@@ -78,8 +78,16 @@ static int srt_write_packet(AVFormatContext *avf, AVPacket *pkt)
                        (int)(e /    1000) % 60, (int)(e %  1000));
     }
     avio_write(avf->pb, pkt->data, pkt->size);
-    if (write_ts)
-        avio_write(avf->pb, "\n\n", 2);
+    if (write_ts) {
+        int i, linebreaks = 2;
+        for (i = sizeof("\r\n\r\n") - 1; i > 0; i--) {
+            char c = pkt->data[pkt->size - i];
+            if (pkt->size >= i && c == '\r' || c == '\n')
+                linebreaks -= c == '\n';
+        }
+        for (i = 0; i < linebreaks; i++)
+            avio_write(avf->pb, "\n", 1);
+    }
     avio_flush(avf->pb);
     return 0;
 }
diff --git a/tests/ref/fate/sub-subripenc b/tests/ref/fate/sub-subripenc
index 7daa4f5..4e459a5 100644
--- a/tests/ref/fate/sub-subripenc
+++ b/tests/ref/fate/sub-subripenc
@@ -1 +1 @@
-bd520f85238abf9df292374aed54681a
+c376f926f375df897898d147eb0ace0c
-- 
1.7.12.4



More information about the ffmpeg-devel mailing list