Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
media-video/motion no longer able to record timelapse videos
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Mon Jul 08, 2013 6:52 am    Post subject: media-video/motion no longer able to record timelapse videos Reply with quote

Hello,

The timelapse feature of media-video/motion appears to be broken, and I believe that ffmpeg is the actual cause. Recording video on motion events (in MPEG 4) works as it did in the past, but I am no longer able to record timelapse movies (in MPEG 1). Indeed, setting ffmpeg_timelapse to anything but zero causes the following repeat error:

Code:
[2] ffmpeg_open FPS 24
[2] ffmpeg_avcodec_log: intra_quant_bias = 96 inter_quant_bias = 0
 - flag 48
[2] Error opening file /home/motion/side/daily/20130708.mpg: Operation now in progress
[1] ffmpeg_open FPS 24
[2] ffopen_open error creating (timelapse) file [/home/motion/side/daily/20130708.mpg]: Operation now in progress
[1] ffmpeg_avcodec_log: intra_quant_bias = 96 inter_quant_bias = 0
 - flag 48
[1] Error opening file /home/motion/front/daily/20130708.mpg: Operation now in progress
[1] ffopen_open error creating (timelapse) file [/home/motion/front/daily/20130708.mpg]: Operation now in progress


The offending file does not exist but the ownership for the respective directory (/home/motion/front/daily) is correct (motion:video); this directory has been created by motion itself some time earlier. I suspect that the EINPROGRESS error code is thrown by ffmpeg and is a red herring.

The working version of motion has been emerged Sat Aug 18 22:11:02 2012. The ffmpeg version at the time was 0.10.3. The recent rebuild of motion happened because of the change in ffmpeg library versions and broke things as described above. I tried this with ffmepg 1.0.7 (current stable) as well as 0.10.7 (same result). I believe that the appropriate USE flags are set; they are as follows:

Code:
< post:media-video/ffmpeg > emerge -pv ffmpeg motion

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] media-video/ffmpeg-1.0.7  USE="3dnow 3dnowext X aac alsa bzip2 encode hardcoded-tables jack mmx mmxext mp3 oss pulseaudio sdl theora truetype v4l vorbis x264 xvid zlib -aacplus (-altivec) -amr -avx -bindist -bluray -cdio (-celt) -cpudetection -debug -doc -examples -faac -fdk -flite -fontconfig -frei0r -gnutls -gsm -iec61883 -ieee1394 -jpeg2k -libass -libcaca -libv4l -modplug (-neon) -network -openal -openssl -opus -pic -rtmp -schroedinger -speex -ssse3 -static-libs {-test} -threads -twolame -vaapi -vdpau (-vis) -vpx" FFTOOLS="aviocat cws2fws ffeval fourcc2pixfmt graph2dot ismindex pktdumper qt-faststart trasher" 0 kB
[ebuild   R    ] media-video/motion-3.2.12-r2  USE="ffmpeg v4l -mysql -postgres" 0 kB


I do not even know how to start debugging this so help on the matter is much appreciated. Many thanks!
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
imbiea
Tux's lil' helper
Tux's lil' helper


Joined: 23 Nov 2004
Posts: 95
Location: Colorado Rockies

PostPosted: Thu Jul 11, 2013 6:51 pm    Post subject: ffopen_open anyone? Reply with quote

I have a similar problem, though the error is slightly different, and I suspect as you do, that ffmpeg is at fault... maybe... the function and/or binary for ffopen is no longer available?


I get the following:

Code:


[1] 2 length=1843200
[1] 3 length=1843200
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[1] Started stream webcam server in port 8081
[1] Error opening file /var/tmp/motion/20130711-timelapse.mpg: Invalid argument
[1] ffopen_open error creating (timelapse) file [/var/tmp/motion/20130711-timelapse.mpg]: Invalid argument
[1] Thread exiting
[1] Calling vid_close() from motion_cleanup
[1] Closing video device /dev/video0
[0] Motion thread 1 restart



My problem is "slightly" different in that I get the "Invalid argument" at the end of my ffopen_open line.
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Sat Jul 13, 2013 9:11 am    Post subject: Re: ffopen_open anyone? Reply with quote

imbiea wrote:
I have a similar problem, though the error is slightly different, and I suspect as you do, that ffmpeg is at fault... maybe... the function and/or binary for ffopen is no longer available?

Yours has actually been popping up all over the place (with no fix). It would appear that both our errors are thrown by ffmpeg_open. Both our errors appear to come from the blacklisting of the mpeg1 format in ffmpeg. At least this is what I concluded following my very brief investigation on the matter. Indeed, I found an interesting comment in ffmpeg.h (from the motion sources):
Code:
/* Open an mpeg file. This is a generic interface for opening either an mpeg1 or
 * an mpeg4 video. If non-standard mpeg1 isn't supported (FFmpeg build > 4680),
 * calling this function with "mpeg1" as codec results in an error. To create a
 * timelapse video, use TIMELAPSE_CODEC as codec name.
 */

This file also contains the definition of this codec name as follows:
Code:
/* Define a codec name/identifier for timelapse videos, so that we can
 * differentiate between normal mpeg1 videos and timelapse videos.
 */
#define TIMELAPSE_CODEC "mpeg1_tl"

The piece of code that throws our errors seems to be the following (from ffmpeg.c):
Code:
/* open the output file, if needed */
    if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) {
        char file_proto[256];

        /* Use append file protocol for mpeg1, to get the append behavior from
         * url_fopen, but no protocol (=> default) for other codecs.
         */
        if (is_mpeg1)
            snprintf(file_proto, sizeof(file_proto), APPEND_PROTO ":%s", filename);
        else
            snprintf(file_proto, sizeof(file_proto), "%s", filename);
       

        if (avio_open(&ffmpeg->oc->pb, file_proto, AVIO_FLAG_WRITE) < 0) {
            /* path did not exist? */
            if (errno == ENOENT) {
                /* create path for file (don't use file_proto)... */
                if (create_path(filename) == -1) {
                    ffmpeg_cleanups(ffmpeg);
                    return NULL;
                }

                /* and retry opening the file (use file_proto) */
                if (avio_open(&ffmpeg->oc->pb, file_proto, AVIO_FLAG_WRITE) < 0) {
                    motion_log(LOG_ERR, 1, "url_fopen - error opening file %s",filename);
                    ffmpeg_cleanups(ffmpeg);
                    return NULL;
                }
                /* Permission denied */
            } else if (errno ==  EACCES) {
                motion_log(LOG_ERR, 1,
                           "url_fopen - error opening file %s"
                           " ... check access rights to target directory", filename);
                ffmpeg_cleanups(ffmpeg);
                return NULL;
            } else {
                motion_log(LOG_ERR, 1, "Error opening file %s", filename);
                ffmpeg_cleanups(ffmpeg);
                return NULL;
            }
        }
    }

By this time the file format checks are done (and presumably succeed), yet avio_fopen() fails (sorry by the way for the previous version, I was looking at the file before applying the Gentoo patches). I am ovbiously not familiar with either motion or ffmpeg so I am not sure what to make out of all of this. I will try to dig further but this will not happen for another couple of week at least (maybe more).

Should anybody be able to shed light on the matter it would be much appreciated.
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
imbiea
Tux's lil' helper
Tux's lil' helper


Joined: 23 Nov 2004
Posts: 95
Location: Colorado Rockies

PostPosted: Sat Jul 13, 2013 1:33 pm    Post subject: Bug report opened upstream Reply with quote

I just about to open a bug upstream... somebody already has..

http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2013x07x09x180501


ahhh.. opened by you...
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Sun Aug 18, 2013 7:51 pm    Post subject: Reply with quote

Hi,

Sorry for the long silence. I have filed a bug report upstream and it went unanswered for more than a month. The project appears dead to me, which is a pity really. I could really use a working motion as to the best of my knowledge there is no other Gentoo package doing anything similar. Should anybody have any suggestion on the matter I would be more than happy to hear it.
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Sat Oct 12, 2013 4:44 pm    Post subject: Reply with quote

Hi,

I sort of solved my problem, in the sense that I have a working "motion" once more. The bad news is that what I ended up with is a horrible workaround: I built a minimal ffmpeg-0.5.13 (I can confirm that 0.8.15 has the same problem as the current version as far as motion is concernet; I did not try any other version of ffmpeg) in a non-standard location and then I built motion against it! All of this is outside the Portage system.

By "minimal ffmpeg" and "non-standard location" I mean the following ffmpeg configuration:
Code:
./configure --prefix=/usr/local/ffmpeg \
  --enable-shared  --enable-gpl  --enable-nonfree  --disable-ffmpeg  \
  --disable-ffplay  --disable-ffserver  --enable-runtime-cpudetect


By "building motion against the old ffmpeg" I mean that I took the motion source (3.2.12), applied motion-3.2.12-workaround-v4l1_deprecation.patch from the Portage tree (ffmpeg-*.patch are not necessary for ffmpeg-0.5.13), and then configured it as follows:
Code:
./configure --with-ffmpeg=/usr/local/ffmpeg --without-mysql  --without-pgsql

(whether mysql and psql are needed is of course a matter of local need and might or might not be necessary).

Obviously instead of just the executable "motion" now the thing must be launched as "LD_LIBRARY_PATH=/usr/local/ffmpeg/lib motion" but things are otherwise running as before.

This is obviously the lazy way out (and ugly as hell), but I did not have the time for anything nicer. By the look of their bug report pages the upstream seems to be dead. I might look into a correct fix in the future but I am not sure when will I find the time for this.
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
mapmot
n00b
n00b


Joined: 11 May 2008
Posts: 4

PostPosted: Sun Oct 13, 2013 5:04 pm    Post subject: Reply with quote

If anybody still cares, I have fixed the timelapse problem in my overlay at https://github.com/mapmot/moverlay

Big thanks to bruda for all the groundwork narrowing down the problem!
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Sun Oct 13, 2013 9:43 pm    Post subject: Reply with quote

mapmot wrote:
If anybody still cares, I have fixed the timelapse problem in my overlay at https://github.com/mapmot/moverlay


Way cool, many thanks! I cannot believe that appending was the issue.

This indeed seems to make motion work well, with one obvious, minor issue: the timelapse video is now truncated every time motion is restarted. I understand that the APPEND_PROTO trick no longer works but I am wondering whether there is any other way of specifying such a behaviour (to append to the file rather than overwrite it).

I know nothing about the ffmpeg API, otherwise I would not be asking. :wink: I will try to experiment myself but since you know your way around the thing already I was wondering whether you may have some pointers on the matter...

Quote:
Big thanks to bruda for all the groundwork narrowing down the problem!


No need for any thanks indeed, as you were the one actually fixing things.
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
mapmot
n00b
n00b


Joined: 11 May 2008
Posts: 4

PostPosted: Sun Oct 13, 2013 10:12 pm    Post subject: Reply with quote

I looks like the appending trick is no longer possible, since the relevant functions are no longer exported from ffmpeg. av_register_protocol() is now ffurl_register_protocol(), which is private. My head still hurts from sifting through the code!

The workaround is to specify in motion.conf the timelapse file name to include the time, as in the motion-triggered capture files. In that way, when motion restarts, it will create a new file. The nice side effect is that you will know immediately if and when motion was restarted :)
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Mon Oct 14, 2013 1:00 pm    Post subject: Reply with quote

mapmot wrote:
I looks like the appending trick is no longer possible, since the relevant functions are no longer exported from ffmpeg. av_register_protocol() is now ffurl_register_protocol(), which is private. My head still hurts from sifting through the code!


Hrm, OK, that's life I guess. Thank you for clarifying this so that I do not have to look into the API myself.

Quote:
The workaround is to specify in motion.conf the timelapse file name to include the time, as in the motion-triggered capture files. In that way, when motion restarts, it will create a new file. The nice side effect is that you will know immediately if and when motion was restarted :)


Good point, that seems to do nicely; overall I can say that I have now a fully working motion once more. The whole thing should go into the official tree since their version of motion is crippled.

In any event, your help has been much appreciated. Many thanks.
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
bruda
Guru
Guru


Joined: 06 May 2004
Posts: 376
Location: Sherbrooke, QC, Canada

PostPosted: Wed Apr 15, 2015 12:59 pm    Post subject: Reply with quote

I am hereby reviving this thread because the recent upgrade to ffmpeg-2.2.14 broke motion once more. This time the call to avformat_write_header() in the following piece of code segfaults:

Code:
    /* write the stream header, if any */
    if(avformat_write_header(ffmpeg->oc, NULL) < 0) {
      motion_log(LOG_ERR, 1, "Error while writing header for %s", filename);
      ffmpeg_cleanups(ffmpeg);
      return NULL;
    }


This happens at the end of ffmpeg_open() from ffmpeg.c in the motion source, with the full set of patches from https://github.com/mapmot/moverlay applied. I am clueless when it comes to the ffmpeg API so any help is much appreciated.

The reason I am putting all of this in this thread rather than a new one is because the effect of the issue is the same, namely that timelapse videos cannot be recorded anymore; the rest of the functionality is still fine.

Many thanks!
_________________
Quid latine dictum sit altum videtur
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum