Commits

Mark Sundstrom committed a99c33b

finally have some ffmpeg settings that generate a movie the iPad can play

Comments (0)

Files changed (4)

     or higher.
 
     We use TIMELAPSE_DAILY to find where to put these movies
-
-    TODO:
-        More info on using ffmpeg:
-        <http://depooh.com/2009/09/25/ffmpeg-for-time-lapse-sets-of-images-and-even-archiving/>
 """
 from __future__ import print_function
 import sys
 location = Location.objects.get(pk=os.environ['TIMELAPSE_LOCATION_ID'])
 tzinfo = get_default_timezone()
 observer = sky.observer_from_location(location)
-
+overwrite = False  # always write the output files?
 
 def generate_date():
     "All the dates for which we have pictures"
     print("Checking", date)
     outpath = os.path.join(os.environ['TIMELAPSE_DAILY'],
         'camera-%d' % camera.id, 'location-%d' % location.id,
-        '{:%Y-%m-%d}.avi'.format(date))
-    if os.path.exists(outpath):
+        '{:%Y-%m-%d}.mp4'.format(date))
+    if os.path.exists(outpath) and (not overwrite):
         continue
     dirpath = os.path.dirname(outpath)
     if not os.path.exists(dirpath):
         os.makedirs(dirpath)
-    suntimes = sky.suntimes_for_date(observer, date)
+    suntimes = sky.suntimes_for_date(observer, date, '-8')
     print("Choose images from", suntimes.dawn, "to", suntimes.dusk)
 #     start = make_aware(datetime.datetime.combine(date,
 #         datetime.time(0, 0, 0)), tzinfo)
+More info on using ffmpeg:
+<http://depooh.com/2009/09/25/ffmpeg-for-time-lapse-sets-of-images-and-even-archiving/>
+
+<http://depooh.com/about/dumb-bunny-productions/>
+Makes note being able to go back and forth between the jpegs and the avi without
+losing any information.
+
+<https://develop.participatoryculture.org/index.php/ConversionMatrix>
+
+from <http://www.ioncannon.net/meta/1040/how-to-create-ipad-formatted-videos-using-handbrake-or-ffmpeg/>
+ffmpeg -y -i input.avi -acodec aac -ar 48000 -ab 128k -ac 2 -s 1024×768 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 output.mp4
+
+Options we might care about (never about audio):
+
+-s 640x480  # frame size
+-vcodec libx264 # video codec
+-b 1200k # output bitrate in bits/s
+-flags  # ???
+-coder 0 # ???
+-r 12  # frame rate
+-an # disable audio recording
+
+
+I'm using the following, which does work, but does not create videos
+that work on the iPad:
+        imagedir = '{}/%*.jpg'.format(tempdir)
+        args = ['/usr/local/bin/ffmpeg',
+            '-r', '12',
+            '-i', imagedir,
+            '-an',
+            '-vcodec', 'copy',
+            name]
+        print(' '.join(args))
+        subprocess.call(args)
+
 # -*- coding: utf8
 """
     use ffmpeg for creating timelapse movies from a sequence of images
-
-    Now based on some ideas seen at “dumb bunny productions”:
-        <http://depooh.com/about/dumb-bunny-productions/>
-
-    I like that you can go back and forth from the jpegs to the avi without
-    losing anything.
-
-    TODO - optionally add a timestamp to each image before we make the movie?
 """
 from __future__ import print_function
 import os
             '-r', '12',
             '-i', imagedir,
             '-an',
-            '-vcodec', 'copy',
+            '-vcodec', 'libx264',
+            '-b:v', '1200k',
+            '-s', '640x480',
             name]
         print(' '.join(args))
         subprocess.call(args)
     print("Sun times for today")
     location = Location.objects.get(pk=os.environ['TIMELAPSE_LOCATION_ID'])
     observer = observer_from_location(location)
-    times = suntimes_for_date(observer, datetime.date.today())
+    times = suntimes_for_date(observer, datetime.date.today(), '-8')
     for field in times._fields:
         value = getattr(times, field)
         print('{:7} {} UTC or {:%H:%M:%S} local'.format(