Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Update #115, correct some bugs. Watchfolder should process anyfiles, …
Browse files Browse the repository at this point in the history
…audio/video or not, like images.
  • Loading branch information
hdsdi3g committed Sep 18, 2015
1 parent 641d06c commit 174c7a4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
13 changes: 11 additions & 2 deletions app/hd3gtv/mydmam/transcode/JobContextTranscoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public JsonObject contextToJson() {
JsonObject jo = new JsonObject();
jo.addProperty("source_pathindex_key", source_pathindex_key);
jo.addProperty("dest_storage_name", dest_storage_name);
jo.addProperty("duration", duration.toString());
if (duration != null) {
jo.addProperty("duration", duration.toString());
jo.addProperty("source_fps", duration.getFps());
}
if (frame > -1) {
JsonObject jo_progress = new JsonObject();
jo_progress.addProperty("performance_fps", performance_fps);
Expand All @@ -54,7 +57,13 @@ public void contextFromJson(JsonObject json_object) {
source_pathindex_key = json_object.get("source_pathindex_key").getAsString();
dest_storage_name = json_object.get("dest_storage_name").getAsString();

duration = new Timecode(json_object.get("duration").getAsString(), 25);
if (json_object.has("duration")) {
if (json_object.has("source_fps")) {
duration = new Timecode(json_object.get("duration").getAsString(), json_object.get("source_fps").getAsFloat());
} else {
duration = new Timecode(json_object.get("duration").getAsString(), 25);
}
}
if (json_object.has("progress")) {
JsonObject jo_progress = json_object.get("progress").getAsJsonObject();
performance_fps = jo_progress.get("performance_fps").getAsFloat();
Expand Down
3 changes: 3 additions & 0 deletions app/hd3gtv/mydmam/transcode/TranscodeProgressFFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ protected void processAnalystProgressFile(File progressfile, JobProgression prog
if (context instanceof ProgressForJobContextFFmpegBased) {
progress_context = (ProgressForJobContextFFmpegBased) context;
Timecode tc_source = progress_context.getSourceDuration();
if (tc_source == null) {
throw new NullPointerException("No source duration extracted from profile");
}
source_duration = tc_source.getValue();
fps = tc_source.getFps();
}
Expand Down
46 changes: 35 additions & 11 deletions app/hd3gtv/mydmam/transcode/TranscoderWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public String getWorkerVendorName() {

protected synchronized void forceStopProcess() throws Exception {
stop_process = true;
if (process != null) {
process.kill();
}
}

protected boolean isActivated() {
Expand All @@ -120,7 +123,7 @@ public List<WorkerCapablities> getWorkerCapablities() {
return capabilities;
}

private TranscodeProgress tprogress;
private Execprocess process;

protected void workerProcessJob(JobProgression progression, JobContext context) throws Exception {
JobContextTranscoder transcode_context = (JobContextTranscoder) context;
Expand Down Expand Up @@ -160,12 +163,13 @@ protected void workerProcessJob(JobProgression progression, JobContext context)

TranscodeProfile transcode_profile;
ProcessConfiguration process_configuration;
Execprocess process;
TranscodeProgress tprogress;
File temp_output_file;
File progress_file = null;

for (int pos = 0; pos < profiles_to_transcode.size(); pos++) {
if (stop_process) {
process = null;
return;
}
transcode_profile = TranscodeProfile.getTranscodeProfile(profiles_to_transcode.get(pos));
Expand All @@ -174,12 +178,6 @@ protected void workerProcessJob(JobProgression progression, JobContext context)

process_configuration = transcode_profile.createProcessConfiguration(physical_source, temp_output_file);

/**
* @see FFmpegLowresRenderer
* process_conf.getParamTags().put("FILTERS", sb_filters.toString());
*/
process = process_configuration.setProgressFile(progress_file).prepareExecprocess(progression.getJobKey());

if (process_configuration.wantAProgressFile()) {
progress_file = new File(temp_directory.getAbsolutePath() + File.separator + transcode_context.source_pathindex_key + "_" + (pos + 1) + "progress.txt");

Expand All @@ -188,32 +186,58 @@ protected void workerProcessJob(JobProgression progression, JobContext context)
tprogress.startWatching();
} else {
progress_file = null;
tprogress = null;
}

progression.updateStep(pos + 1, profiles_to_transcode.size());

/**
* @see FFmpegLowresRenderer, if it's a video file
* process_conf.getParamTags().put("FILTERS", sb_filters.toString());
*/
process = process_configuration.setProgressFile(progress_file).prepareExecprocess(progression.getJobKey());

progression.update("Transcode source file with " + transcode_profile.getName() + " (" + transcode_profile.getExecutable().getName() + ")");

process.run();

if (progress_file != null) {
if (tprogress != null) {
tprogress.stopWatching();
}
if (progress_file != null) {
if (progress_file.exists()) {
FileUtils.forceDelete(progress_file);
}
}

if (process.getExitvalue() != 0) {
if (process_configuration.getEvent() != null) {
throw new IOException("Bad ffmpeg execution: " + process_configuration.getEvent().getLast_message());
throw new IOException("Bad transcoder execution: " + process_configuration.getEvent().getLast_message());
}
throw new IOException("Bad ffmpeg execution");
throw new IOException("Bad transcoder execution");
}

process = null;

if (stop_process) {
return;
}

if (transcode_profile.getOutputformat().isFaststarted()) {
progression.update("Faststart transcoded file");
File fast_started_file = new File(temp_output_file.getAbsolutePath() + "-faststart" + transcode_profile.getExtension(""));
Publish.faststartFile(temp_output_file, fast_started_file);
FileUtils.forceDelete(temp_output_file);
temp_output_file = fast_started_file;
}

if (stop_process) {
return;
}

// TODO add prefix/suffix for output file + recreate sub dir

progression.update("Move transcoded file to destination");
if (local_dest_dir != null) {
FileUtils.moveFile(temp_output_file, new File(local_dest_dir.getAbsolutePath() + File.separator + physical_source.getName() + transcode_profile.getExtension("")));
} else if (stop_process == false) {
Expand Down
13 changes: 10 additions & 3 deletions app/hd3gtv/mydmam/transcode/watchfolder/WatchFolderEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Target init(LinkedHashMap<String, ?> conf) throws Exception {
return this;
}

/**
* @param duration can be null
*/
JobNG prepareTranscodeJob(String path_index_key, String simple_file_name, Timecode duration, MutationBatch mutator) throws ConnectionException {
JobContextTranscoder job_transcode = new JobContextTranscoder();
job_transcode.source_pathindex_key = path_index_key;
Expand All @@ -111,7 +114,6 @@ JobNG prepareTranscodeJob(String path_index_key, String simple_file_name, Timeco
// TODO add prefix/suffix for output file + recreate sub dir
return AppManager.createJob(job_transcode).setCreator(getClass()).setName("Transcode from watchfolder " + simple_file_name).publish(mutator);
}

}

WatchFolderEntry(AppManager manager, String name, HashMap<String, ConfigurationItem> all_wf_confs) throws Exception {
Expand Down Expand Up @@ -473,20 +475,25 @@ void performFoundAndValidatedFile(AbstractFoundedFile validated_file) throws Con
/**
* Process active files: transcoding jobs
*/
Timecode duration = null;

// TODO check video and/or audio presence.

FFprobe ffprobe = indexing_result.getByClass(FFprobe.class);
if (ffprobe == null) {
Log2.log.error("No ffprobe indexing informations for item", null, validated_file);
AdminMailAlert.create("No ffprobe indexing informations for item", false).addDump(validated_file).send();
validated_file.status = Status.ERROR;
return;
} else {
duration = ffprobe.getDuration();
}
// TODO check video and/or audio presence.

MutationBatch mutator = CassandraDb.prepareMutationBatch();
ArrayList<JobNG> jobs_to_watch = new ArrayList<JobNG>(targets.size());

for (int pos = 0; pos < targets.size(); pos++) {
jobs_to_watch.add(targets.get(pos).prepareTranscodeJob(pi_item.prepare_key(), validated_file.getName(), ffprobe.getDuration(), mutator));
jobs_to_watch.add(targets.get(pos).prepareTranscodeJob(pi_item.prepare_key(), validated_file.getName(), duration, mutator));
}

JobContextWFDeleteSourceFile delete_source = new JobContextWFDeleteSourceFile();
Expand Down

0 comments on commit 174c7a4

Please sign in to comment.