Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created August 29, 2011 19:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxlapshin/1179229 to your computer and use it in GitHub Desktop.
Save maxlapshin/1179229 to your computer and use it in GitHub Desktop.
Nitrogen example for ffmpeg frontend
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("video.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "FFmpeg frontend".
body() ->
#container_12 { body=[
#grid_8 { alpha=true, prefix=2, suffix=2, omega=true, body=inner_body() }
]}.
inner_body() ->
[
#h1 { text=title() },
#flash {},
#p{},
"
Upload video and it will be converted here to mp4
",
#p{},
#upload { tag=myUpload1, button_text="Upload File" },
#p{},
"
Run <b>./bin/dev help</b> to see some useful developer commands.
",
#panel{id= videoPanel, body = ["Here will be video"]}
].
start_upload_event(myUpload1) ->
wf:flash("Upload started.").
finish_upload_event(myUpload1, FileName, LocalFileData, Node) ->
FileSize = filelib:file_size(LocalFileData),
wf:flash(wf:f("Uploaded file: ~s (~p bytes) on node ~s, file: ~p.", [FileName, FileSize, Node, LocalFileData])),
wf:continue({ffmpeg, FileName}, fun() -> transcode(FileName, LocalFileData) end, infinity),
ok.
continue({ffmpeg, FileName}, {ok, NewPath}) ->
Message = wf:f("Converted file '~s' (~p)", [FileName, NewPath]),
wf:flash(Message),
% HTML = wf:f("<video src='~s'/>", [NewPath]),
wf:update(videoPanel, #video{src = NewPath}).
event(click) ->
wf:replace(button, #panel {
body="You clicked the button!",
actions=#effect { effect=highlight }
}).
transcode(FileName, Path) ->
NewPath = filename:basename(FileName, filename:extension(FileName)) ++ ".mp4",
Cmd = wf:f("ffmpeg -y -i '~s' -vcodec libx264 -preset fast -acodec libfaac 'site/static/~s'", [Path, NewPath]),
os:cmd(Cmd),
{ok, NewPath}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment