diff --git a/videos/api.py b/videos/api.py index 2f100bb147bf00b6feefc032cdd8c79c63a55749..96cea59b84a05923675d1b720638564985fd66dd 100755 --- a/videos/api.py +++ b/videos/api.py @@ -43,6 +43,7 @@ def task(request): task['type'] = 'master' task['course'] = video.course.id task['video'] = video.id + task['notranscode'] = video.notranscode task['path'] = str(video.original) return JsonResponse(task) diff --git a/videos/migrations/0002_video_notranscode.py b/videos/migrations/0002_video_notranscode.py new file mode 100644 index 0000000000000000000000000000000000000000..972d9cf653ed674d0b71ee4f0b3832eec14ab57b --- /dev/null +++ b/videos/migrations/0002_video_notranscode.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-04-29 21:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('videos', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='video', + name='notranscode', + field=models.BooleanField(default=False), + ), + ] diff --git a/videos/models.py b/videos/models.py index 368cd4c4dd3272cc30d9b4d469677f55c2153467..9f54adcb96e6274853d8b1d3b94720dc10f263a0 100755 --- a/videos/models.py +++ b/videos/models.py @@ -155,6 +155,7 @@ class Video(MetaVideo): course = models.ForeignKey('Course', Course, null=False, blank=False) key = models.CharField(blank=False, null=False, default=random_key_20, max_length=30, unique=True) views = models.IntegerField(default=0) + notranscode = models.BooleanField(default=False) name = models.CharField(max_length=1000, blank=True) description = models.TextField(blank=True) length = models.DecimalField(null=True, blank=True, decimal_places=3, max_digits=10) diff --git a/videos/templates/worker.py b/videos/templates/worker.py index 01038468ef61798e084f5b3d41979dab3ed86ac6..4a7890c25582aacace7e0e7ec5e425961ac3255b 100644 --- a/videos/templates/worker.py +++ b/videos/templates/worker.py @@ -77,21 +77,31 @@ def render_master(task, tmpfiles=[]): ffmpeg_command = ['ffmpeg', '-y', '-v', 'info', '-nostats'] ffmpeg_command += ['-analyzeduration', '20000000'] ffmpeg_command += ['-i', tmpfiles[0]] - filters = ['[0:v:0] hqdn3d,pad=ceil(iw/2)*2:ceil(ih/2)*2 [v]'] - - for i in range(len(audio_streams)): - filters += ["[0:a:{i}] dynaudnorm='p=0.35:r=1:f=300',loudnorm='i=-16.0:lra=12.0:tp=-3.0',anull [amix_{i}]".format(i=i)] - if len(video_streams) == 2: - filters += ['[0:v:1] pad=ceil(iw/2)*2:ceil(ih/2)*2 [s]'] - ffmpeg_command += ['-filter_complex', '; '.join(filters)] - for i in range(len(audio_streams)): - ffmpeg_command += ['-map', '[amix_{}]'.format(i)] - ffmpeg_command += ['-c:a:{}'.format(i), 'aac', '-b:a:{}'.format(i), '128k', '-ar:a:{}'.format(i), '48000'] - ffmpeg_command += ['-map', '[v]'] - ffmpeg_command += ['-c:v:0', 'libx264', '-threads', '4', '-pix_fmt', 'yuv420p', '-crf:v:0', '23', '-profile:v:0', 'high', '-level:v:0', '4.1', '-disposition:v:0', 'default', '-metadata:s:v:0', 'title="Video"'] - if len(video_streams) == 2: - ffmpeg_command += ['-map', '[s]'] - ffmpeg_command += ['-c:v:1', 'libx264', '-threads', '4', '-pix_fmt', 'yuv420p', '-crf:v:1', '23', '-profile:v:1', 'high', '-level:v:1', '4.1', '-tune:v:1', 'stillimage', '-disposition:v:1', 'descriptions', '-metadata:s:v:1', 'title="Slides"'] + + if task['notranscode']: + log(task, "notranscode flag is set, only remuxing video+audio") + ffmpeg_command += ['-c:v:0', 'copy', '-map', '0:v:0'] + if len(video_streams) == 2: + ffmpeg_command += ['-c:v:1', 'copy', '-map', '0:v:1'] + for i in range(len(audio_streams)): + ffmpeg_command += ['-c:a:%d' % i, 'copy', '-map', '0:a:%d' % i] + else: + log(task, "notranscode flag is not set, transcoding video+audio") + filters = ['[0:v:0] hqdn3d,pad=ceil(iw/2)*2:ceil(ih/2)*2 [v]'] + + for i in range(len(audio_streams)): + filters += ["[0:a:{i}] dynaudnorm='p=0.35:r=1:f=300',loudnorm='i=-16.0:lra=12.0:tp=-3.0',anull [amix_{i}]".format(i=i)] + if len(video_streams) == 2: + filters += ['[0:v:1] pad=ceil(iw/2)*2:ceil(ih/2)*2 [s]'] + ffmpeg_command += ['-filter_complex', '; '.join(filters)] + for i in range(len(audio_streams)): + ffmpeg_command += ['-map', '[amix_{}]'.format(i)] + ffmpeg_command += ['-c:a:{}'.format(i), 'aac', '-b:a:{}'.format(i), '128k', '-ar:a:{}'.format(i), '48000'] + ffmpeg_command += ['-map', '[v]'] + ffmpeg_command += ['-c:v:0', 'libx264', '-threads', '4', '-pix_fmt', 'yuv420p', '-crf:v:0', '23', '-profile:v:0', 'high', '-level:v:0', '4.1', '-disposition:v:0', 'default', '-metadata:s:v:0', 'title="Video"'] + if len(video_streams) == 2: + ffmpeg_command += ['-map', '[s]'] + ffmpeg_command += ['-c:v:1', 'libx264', '-threads', '4', '-pix_fmt', 'yuv420p', '-crf:v:1', '23', '-profile:v:1', 'high', '-level:v:1', '4.1', '-tune:v:1', 'stillimage', '-disposition:v:1', 'descriptions', '-metadata:s:v:1', 'title="Slides"'] # ffmpeg_command += ['-aspect', '16:9'] ffmpeg_command += ['-movflags', 'faststart', '-f', 'mp4', tmpfiles[1]] log(task, repr(ffmpeg_command)) diff --git a/videos/views.py b/videos/views.py index 1bd49fda5b5c3922c0f6534d0a518e8361655967..50602df8ff5094b248d5726c9569ced564ef38e2 100755 --- a/videos/views.py +++ b/videos/views.py @@ -215,6 +215,7 @@ def upload(request): v.name = request.POST.get("name").strip() v.description = request.POST.get("description").strip() v.original = request.FILES.get('videofile') + v.notranscode = (request.POST.get("notranscode") == "1") if not v.original: return HttpResponse("File missing") v.save()