| 303 | int GetAviDemux(QString list, QString chanid, QString starttime, const QString &outputfilename) |
| 304 | { |
| 305 | QMap<long long, int> cutlist; |
| 306 | QMap<long long, int>::Iterator it; |
| 307 | QString result; |
| 308 | int startValue = 0; |
| 309 | long long myTotalFrames; |
| 310 | long long myFrameRate; |
| 311 | |
| 312 | ProgramInfo *pginfo = |
| 313 | ProgramInfo::GetProgramFromRecorded(chanid, starttime); |
| 314 | |
| 315 | NuppelVideoPlayer* nvp = new NuppelVideoPlayer("avidemux_export", pginfo); |
| 316 | |
| 317 | myFrameRate = (long long)(nvp->GetFrameRate() * 1000); |
| 318 | myTotalFrames = 1000000; //nvp->GetTotalFrameCount(); |
| 319 | |
| 320 | if (!pginfo) |
| 321 | { |
| 322 | VERBOSE(VB_IMPORTANT, |
| 323 | QString("No program data exists for channel %1 at %2") |
| 324 | .arg(chanid).arg(starttime)); |
| 325 | return COMMFLAG_BUGGY_EXIT_NO_CHAN_DATA; |
| 326 | } |
| 327 | |
| 328 | QString filename = pginfo->GetPlaybackURL(TRUE); |
| 329 | |
| 330 | if (list == "cutlist") |
| 331 | pginfo->GetCutList(cutlist); |
| 332 | else |
| 333 | pginfo->GetCommBreakList(cutlist); |
| 334 | |
| 335 | // Formatting of output data |
| 336 | |
| 337 | for (it = cutlist.begin(); it != cutlist.end(); ++it) |
| 338 | { |
| 339 | if ((it.key() == 0) && (startValue == 0)) // Cutlist starts on first frame, |
| 340 | { |
| 341 | ++it; |
| 342 | startValue = it.key(); |
| 343 | } |
| 344 | |
| 345 | if ((it.key() != 0) && (startValue == 0)) // Cutlist starts on non-first frame |
| 346 | { |
| 347 | result += QString("app.addSegment(0,0,%1);").arg(it.key()); |
| 348 | startValue = it.key(); |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | if ((*it == MARK_COMM_END) && (startValue != 0) || |
| 353 | (*it == MARK_CUT_END) && (startValue != 0)) |
| 354 | { |
| 355 | if (result != "") |
| 356 | result += "\n"; |
| 357 | startValue = it.key(); |
| 358 | result += QString("app.addSegment(0,%1,").arg(it.key()); // Value is a start value |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | result += QString("%1);").arg(it.key() - startValue); // Value is an end value |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (it.key() != myTotalFrames) |
| 368 | { |
| 369 | result += QString("%1);").arg(myTotalFrames); |
| 370 | } |
| 371 | |
| 372 | // Governs the file output: |
| 373 | |
| 374 | QString tmp = ""; |
| 375 | ostream *out = &cout; |
| 376 | |
| 377 | if (outputfilename != "-"){ |
| 378 | QByteArray tmp = outputfilename.toLocal8Bit(); |
| 379 | out = new fstream(tmp.constData(), ios::app | ios::out ); |
| 380 | } |
| 381 | |
| 382 | if (outputfilename == ""){ |
| 383 | VERBOSE(VB_IMPORTANT, |
| 384 | QString("Error: AVIDemux output requires the use of the --outputfile option.")); |
| 385 | return COMMFLAG_EXIT_INVALID_CMDLINE; |
| 386 | } |
| 387 | |
| 388 | tmp = QString("//AD <- Needed to identify//\n" |
| 389 | "//--automatically built--\n" |
| 390 | "//--Project:\n\n" |
| 391 | "var app = new Avidemux();\n\n" |
| 392 | "//** Video **\n" |
| 393 | "// 01 videos source\n" |
| 394 | "app.load(\"%1\");\n\n" |
| 395 | "app.clearSegments();\n\n" |
| 396 | "%2\n" |
| 397 | "app.markerA=0;\n" |
| 398 | "app.markerB=%3;\n" |
| 399 | "app.rebuildIndex();\n\n" |
| 400 | "//** Postproc **\n" |
| 401 | "app.video.setPostProc(3,3,0);\n\n" |
| 402 | "app.video.setFps1000(%4);\n\n" |
| 403 | "//** Filters **\n\n" |
| 404 | "//** Video Codec conf **\n" |
| 405 | "app.video.codec(\"Copy\",\"CQ=4\",\"0 \");\n\n" |
| 406 | "//** Audio **\n" |
| 407 | "app.audio.reset();\n" |
| 408 | "app.audio.codec(\"copy\",128,0,\"\");\n" |
| 409 | "app.audio.normalizeMode=0;\n" |
| 410 | "app.audio.normalizeValue=0;\n" |
| 411 | "app.audio.delay=0;\n" |
| 412 | "app.audio.mixer(\"NONE\");\n" |
| 413 | "app.setContainer(\"MATROSKA\");\n" |
| 414 | "setSuccess(1);\n" |
| 415 | "//app.Exit();\n\n" |
| 416 | "//End of script\n").arg(filename).arg(result).arg(myTotalFrames).arg(myFrameRate).toLocal8Bit().constData(); |
| 417 | |
| 418 | const QByteArray tmp2 = tmp.toLocal8Bit(); |
| 419 | *out << tmp2.constData() << endl; |
| 420 | |
| 421 | VERBOSE(VB_IMPORTANT, |
| 422 | QString("AVIDemux Project generated for %1 at %2 with filename %3.") |
| 423 | .arg(chanid).arg(starttime).arg(outputfilename)); |
| 424 | |
| 425 | return COMMFLAG_EXIT_NO_ERROR_WITH_NO_BREAKS; |
| 426 | } |
| 427 | |
| 428 | |