rework ffmpeg seek, bld_script updates
authorGood Guy <good1.2guy@gmail.com>
Sat, 30 Jan 2016 15:19:49 +0000 (08:19 -0700)
committerGood Guy <good1.2guy@gmail.com>
Sat, 30 Jan 2016 15:19:49 +0000 (08:19 -0700)
cinelerra-5.0/bld_scripts/bld_incremental.sh
cinelerra-5.0/bld_scripts/bld_package.sh
cinelerra-5.0/bld_scripts/bld_prepare.sh
cinelerra-5.0/cinelerra/ffmpeg.C
cinelerra-5.0/cinelerra/fileffmpeg.C
cinelerra-5.0/cinelerra/fileffmpeg.h

index ad62cd84c2aadcd1f0efb383799762f427d84a48..e38308d86596fb39764bdef7397239e7f87f9d75 100755 (executable)
@@ -3,7 +3,7 @@
 dir="$1"
 path="/home"
 bld="git-repo"
-proj="cinelerra"
+proj="cinelerra5"
 base="cinelerra-5.0"
 
 if [ ! -d "$path/$dir/$bld/$proj" ]; then
index 81f027bd2213272260633227a911dc9178e49551..08f21a4ebb6d0acef4b48ae1f83e80dc6782b164 100755 (executable)
@@ -10,7 +10,7 @@ fi
 dir="$1"
 path="/home"
 bld="git-repo"
-proj="cinelerra"
+proj="cinelerra5"
 base="cinelerra-5.0"
 
 centos="centos-7.0-1406"
index 9eb54334619371332b9ce5eecdc35823d45ff18a..a99de900e943f605198ef193468dd3f2418e5bea 100755 (executable)
@@ -23,7 +23,7 @@ case "$dir" in
     libpng-devel bzip2-devel zlib-devel kernel-headers \
     libavc1394 festival-devel libiec61883-devel flac-devel \
     libsndfile-devel libtheora-devel linux-firmware ivtv-firmware \
-    libvorbis-devel texinfo xz-devel lzma-devel cmake udftools
+    libvorbis-devel texinfo xz-devel lzma-devel cmake udftools git
     yasm=yasm-1.2.0-7.fc21.x86_64.rpm
     release=http://archives.fedoraproject.org/pub/fedora/linux/releases/21
     url=$release/Everything/x86_64/os/Packages/y/$yasm
@@ -39,7 +39,7 @@ case "$dir" in
     openexr-devel libavc1394-devel festival-devel libjpeg8-devel libdv-devel \
     libdvdnav-devel libdvdread-devel libiec61883-devel libuuid-devel \
     ilmbase-devel fftw3-devel libsndfile-devel libtheora-devel flac-devel \
-    cmake patch libnuma-devel lzma-devel udftools
+    cmake patch libnuma-devel lzma-devel udftools git
     if [ ! -f /usr/lib64/libtermcap.so ]; then
       ln -s libtermcap.so.2 /usr/lib64/libtermcap.so
     fi
index 120a75d61368ba62d63a6111879078e05e999be1..aa7a9f1f396827759404a688d94bf815c1e23d7d 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef INT64_MAX
 #define INT64_MAX 9223372036854775807LL
 #endif
+#define MAX_RETRY 1000
 
 #include "asset.h"
 #include "bccmodels.h"
@@ -350,7 +351,7 @@ int FFStream::read_packet()
 int FFStream::decode(AVFrame *frame)
 {
        int ret = 0;
-       int retries = 1000;
+       int retries = MAX_RETRY;
        int got_frame = 0;
 
        while( ret >= 0 && !flushed && --retries >= 0 && !got_frame ) {
@@ -365,7 +366,7 @@ int FFStream::decode(AVFrame *frame)
                                ipkt->data += ret;
                                ipkt->size -= ret;
                        }
-                       retries = 1000;
+                       retries = MAX_RETRY;
                }
                if( !got_frame ) {
                        need_packet = 1;
@@ -460,33 +461,39 @@ int FFStream::seek(int64_t no, double rate)
                        if( n < 0 ) n = 0;
                        pos = n;
                        plmt = marks[i].pos;
-                       npkts = 1000;
+                       npkts = MAX_RETRY;
                }
        }
        double secs = pos / rate;
-       int64_t tstmp = secs * st->time_base.den / st->time_base.num;
+       int64_t pkt_ts, tstmp = secs * st->time_base.den / st->time_base.num;
        if( nudge != AV_NOPTS_VALUE ) tstmp += nudge;
-       if( avformat_seek_file(fmt_ctx, st->index,
-               -INT64_MAX, tstmp, INT64_MAX, AVSEEK_FLAG_ANY) < 0 ) return -1;
-       avcodec_flush_buffers(st->codec);
-       need_packet = 0;  flushed = 0;
-       seeked = 1;  st_eof(0);
-       int64_t pkt_ts = AV_NOPTS_VALUE;
-       int ret = 1, retry = 1000;
-
+       int ret = avformat_seek_file(fmt_ctx, st->index,
+               -INT64_MAX, tstmp, INT64_MAX, AVSEEK_FLAG_ANY);
+       if( ret >= 0 ) {
+               avcodec_flush_buffers(st->codec);
+               need_packet = 0;  flushed = 0;
+               seeked = 1;  st_eof(0);
 // read up to retry packets, limited to npkts in stream, and not past pkt.pos plmt
-       while( ret > 0 && npkts > 0 && --retry >= 0 ) {
-               if( (ret=read_packet()) <= 0 ) break;
-               if( ipkt->stream_index != st->index ) continue;
-               if( (pkt_ts=ipkt->dts) == AV_NOPTS_VALUE ) pkt_ts = ipkt->pts;
-               if( pkt_ts != AV_NOPTS_VALUE && pkt_ts >= tstmp ) break;
-               if( plmt >= 0 && ipkt->pos >= plmt ) break;
-               --npkts;
+               for( int retry=MAX_RETRY; ret>=0 && --retry>=0; ) {
+                       if( read_packet() <= 0 || ( plmt >= 0 && ipkt->pos > plmt ) ) {
+                               ret = -1;  break;
+                       }
+                       if( ipkt->stream_index != st->index ) continue;
+                       if( --npkts <= 0 ) break;
+                       if( (pkt_ts=ipkt->dts) == AV_NOPTS_VALUE &&
+                           (pkt_ts=ipkt->pts) == AV_NOPTS_VALUE ) continue;
+                       if( pkt_ts >= tstmp ) break;
+               }
        }
-
-       if( ret <= 0 || retry < 0 ) return -1;
+       if( ret < 0 ) {
+//printf("** seek fail %ld, %ld\n", pos, tstmp);
+               seeked = need_packet = 0;
+               st_eof(flushed=1);
+               return -1;
+       }
+//printf("seeked pos = %ld, %ld\n", pos, tstmp);
        seek_pos = curr_pos = pos;
-       return npkts > 0 ? 1 : 0;
+       return 0;
 }
 
 FFAudioStream::FFAudioStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx)
@@ -628,7 +635,7 @@ int FFAudioStream::load(int64_t pos, int len)
        if( mbsz < len ) mbsz = len;
        int64_t end_pos = pos + len;
        int ret = 0;
-       for( int i=0; ret>=0 && !flushed && curr_pos<end_pos && i<1000; ++i ) {
+       for( int i=0; ret>=0 && !flushed && curr_pos<end_pos && i<MAX_RETRY; ++i ) {
                ret = read_frame(frame);
                if( ret > 0 ) {
                        load_history(&frame->extended_data[0], frame->nb_samples);
@@ -742,7 +749,7 @@ int FFVideoStream::load(VFrame *vframe, int64_t pos)
                fprintf(stderr, "FFVideoStream::load: av_frame_alloc failed\n");
                return -1;
        }
-       for( int i=0; ret>=0 && !flushed && curr_pos<=pos && i<1000; ++i ) {
+       for( int i=0; ret>=0 && !flushed && curr_pos<=pos && i<MAX_RETRY; ++i ) {
                ret = read_frame(frame);
                if( ret > 0 ) ++curr_pos;
        }
@@ -1254,9 +1261,9 @@ int FFMPEG::read_options(FILE *fp, const char *options, AVDictionary *&opts)
                if( !ret ) {
                        if( !strcmp(key, "duration") )
                                opt_duration = strtod(val, 0);
-                       if( !strcmp(key, "video_filter") )
+                       else if( !strcmp(key, "video_filter") )
                                opt_video_filter = cstrdup(val);
-                       if( !strcmp(key, "audio_filter") )
+                       else if( !strcmp(key, "audio_filter") )
                                opt_audio_filter = cstrdup(val);
                        else if( !strcmp(key, "loglevel") )
                                set_loglevel(val);
index b5b459ef4faaca750407bdc743cbd755a0554a6e..1972a9eca9634824856e1427aecf285b0860e038 100644 (file)
@@ -247,22 +247,6 @@ int FileFFMPEG::close_file()
 }
 
 
-int FileFFMPEG::set_video_position(int64_t pos)
-{
-        if( !ff || pos < 0 || pos >= asset->video_length )
-               return 1;
-       return 0;
-}
-
-
-int FileFFMPEG::set_audio_position(int64_t pos)
-{
-        if( !ff || pos < 0 || pos >= asset->audio_length )
-               return 1;
-       return 0;
-}
-
-
 int FileFFMPEG::write_samples(double **buffer, int64_t len)
 {
         if( !ff || len < 0 ) return -1;
index ed95ee9460740e2b12c98f6d6999ab9b38ca6bcc..fe068d25e67a9473943d7c3921dee60a3064f024 100644 (file)
@@ -52,8 +52,6 @@ public:
        int open_file(int rd,int wr);
        int get_index(char *index_filename);
        int close_file(void);
-       int set_video_position(int64_t pos);
-       int set_audio_position(int64_t pos);
        int write_samples(double **buffer,int64_t len);
        int write_frames(VFrame ***frames,int len);
        int read_samples(double *buffer,int64_t len);