Skip to content

Instantly share code, notes, and snippets.

@jsaowji
Created September 20, 2023 11:22
Show Gist options
  • Save jsaowji/ead18b4f1b90381d558eddaf0336164b to your computer and use it in GitHub Desktop.
Save jsaowji/ead18b4f1b90381d558eddaf0336164b to your computer and use it in GitHub Desktop.
D2vwitch vobid patch v1 for apply cleanly with Mikewando/D2VWitch/ffmpeg-6 but should work with normal aswell with manual applying
diff --git a/src/D2V.cpp b/src/D2V.cpp
index b6129ed..a38e91a 100644
--- a/src/D2V.cpp
+++ b/src/D2V.cpp
@@ -264,6 +264,8 @@ bool D2V::handleVideoPacket(AVPacket *packet) {
clearDataLine();
}
+ line.cell = current_cell;
+ line.vob = current_vob;
line.info = INFO_BIT11 | INFO_STARTS_NEW_GOP;
// More evil shit for passing through "closed_gop". MPEG2 only.
@@ -492,7 +494,7 @@ D2V::D2V() {
}
-D2V::D2V(const std::string &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, ProgressFunction _progress_report, void *_progress_data, LoggingFunction _log_message, void *_log_data)
+D2V::D2V(const std::string &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, ProgressFunction _progress_report, void *_progress_data, LoggingFunction _log_message, void *_log_data,int _dsi_stream_index)
: d2v_file_name(_d2v_file_name)
, d2v_file(_d2v_file)
, audio_files(_audio_files)
@@ -508,6 +510,7 @@ D2V::D2V(const std::string &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap
, previous_pts(AV_NOPTS_VALUE)
, guessed_frame_rate({ 0, 0 })
, first_video_keyframe_pos(_first_video_keyframe_pos)
+ , dsi_stream_index(_dsi_stream_index)
{ }
@@ -544,17 +547,24 @@ void D2V::index() {
// Apparently we might receive packets from streams with AVDISCARD_ALL set,
// and also from streams discovered late, probably.
- if (packet.stream_index != video_stream->index &&
+ if (packet.stream_index != video_stream->index && packet.stream_index != dsi_stream_index &&
!audio_files.count(packet.stream_index)) {
av_packet_unref(&packet);
continue;
}
bool okay = true;
-
if (packet.stream_index == video_stream->index)
okay = handleVideoPacket(&packet);
- else
+ else if(packet.stream_index == dsi_stream_index) {
+ #define PCI_SIZE 980
+ #define DSI_SIZE 1018
+ #define DSI_BASE PCI_SIZE + 1
+ uint8_t cellid = packet.data[DSI_BASE + 0x1B];
+ uint16_t vobid = (packet.data[DSI_BASE + 0x18] << 8) + (packet.data[DSI_BASE + 0x18 + 1]);
+ current_vob = vobid;
+ current_cell = cellid;
+ } else
okay = handleAudioPacket(&packet);
if (!okay) {
diff --git a/src/D2V.h b/src/D2V.h
index acd8e2e..906434c 100644
--- a/src/D2V.h
+++ b/src/D2V.h
@@ -80,7 +80,7 @@ public:
D2V();
- D2V(const std::string &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, ColourRange _input_range, bool _use_relative_paths, ProgressFunction _progress_report, void *_progress_data, LoggingFunction _log_message, void *_log_data);
+ D2V(const std::string &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, ColourRange _input_range, bool _use_relative_paths, ProgressFunction _progress_report, void *_progress_data, LoggingFunction _log_message, void *_log_data,int dsi_stream_index);
const std::string &getD2VFileName() const;
@@ -168,6 +168,7 @@ private:
FakeFile* fake_file;
FFMPEG *f;
AVStream *video_stream;
+ int dsi_stream_index;
ColourRange input_range;
bool use_relative_paths;
ProgressFunction progress_report;
@@ -177,6 +178,10 @@ private:
DataLine line;
+ uint8_t current_cell;
+ uint16_t current_vob;
+
+
int64_t previous_pts; // For frame rate guessing.
AVRational guessed_frame_rate;
diff --git a/src/D2VWitch.cpp b/src/D2VWitch.cpp
index e5273f6..3e80687 100644
--- a/src/D2VWitch.cpp
+++ b/src/D2VWitch.cpp
@@ -702,6 +702,13 @@ int main(int argc, char **_argv) {
// stream selection
f.deselectAllStreams();
+ int dsi_stream_index = 0;
+
+ for (unsigned i = 0; i < f.fctx->nb_streams; i++)
+ if(f.fctx->streams[i]->id == 0x1Bf) {
+ f.fctx->streams[i]->discard = AVDISCARD_DEFAULT;
+ dsi_stream_index = i;
+ }
AVStream *video_stream;
if (cmd.have_video_id) {
video_stream = f.selectVideoStreamById(cmd.video_id);
@@ -879,7 +886,7 @@ int main(int argc, char **_argv) {
logging_func = nullptr;
}
- D2V d2v(cmd.d2v_path, d2v_file, audio_files, &fake_file, &f, video_stream, first_video_keyframe_pos, cmd.input_range, cmd.relative_paths, progress_func, nullptr, logging_func, nullptr);
+ D2V d2v(cmd.d2v_path, d2v_file, audio_files, &fake_file, &f, video_stream, first_video_keyframe_pos, cmd.input_range, cmd.relative_paths, progress_func, nullptr, logging_func, nullptr, dsi_stream_index);
d2v.index();
diff --git a/src/GUIWindow.cpp b/src/GUIWindow.cpp
index 9b563ad..37af2df 100644
--- a/src/GUIWindow.cpp
+++ b/src/GUIWindow.cpp
@@ -354,7 +354,7 @@ void GUIWindow::startIndexing() {
QThread *worker_thread = new QThread;
- IndexingWorker *worker = new IndexingWorker(d2v_edit->text(), d2v_file, audio_files, &fake_file, &f, video_stream, first_video_keyframe_pos, (D2V::ColourRange)range_group->checkedId(), use_relative_paths_check->isChecked(), this);
+ IndexingWorker *worker = new IndexingWorker(d2v_edit->text(), d2v_file, audio_files, &fake_file, &f, video_stream, first_video_keyframe_pos, (D2V::ColourRange)range_group->checkedId(), use_relative_paths_check->isChecked(), this,-1);
worker->moveToThread(worker_thread);
connect(worker_thread, &QThread::started, worker, &IndexingWorker::process);
@@ -1011,7 +1011,7 @@ void GUIWindow::demuxingFinished(D2V new_d2v) {
QThread *worker_thread = new QThread;
- IndexingWorker *worker = new IndexingWorker(new_d2v_name, new_d2v_file, AudioFilesMap(), &demuxed_fake_file, &demuxed_f, video_stream, first_video_keyframe_pos, (D2V::ColourRange)range_group->checkedId(), use_relative_paths_check->isChecked(), this);
+ IndexingWorker *worker = new IndexingWorker(new_d2v_name, new_d2v_file, AudioFilesMap(), &demuxed_fake_file, &demuxed_f, video_stream, first_video_keyframe_pos, (D2V::ColourRange)range_group->checkedId(), use_relative_paths_check->isChecked(), this,-1);
worker->moveToThread(worker_thread);
connect(worker_thread, &QThread::started, worker, &IndexingWorker::process);
@@ -1340,8 +1340,8 @@ void GUIWindow::closeEvent(QCloseEvent *event) {
}
-IndexingWorker::IndexingWorker(const QString &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, GUIWindow *_window)
- : d2v(_d2v_file_name.toStdString(), _d2v_file, _audio_files, _fake_file, _f, _video_stream, _first_video_keyframe_pos, _input_range, _use_relative_paths, ::updateProgress, _window, ::logMessage, _window)
+IndexingWorker::IndexingWorker(const QString &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, GUIWindow *_window,int _dsi)
+ : d2v(_d2v_file_name.toStdString(), _d2v_file, _audio_files, _fake_file, _f, _video_stream, _first_video_keyframe_pos, _input_range, _use_relative_paths, ::updateProgress, _window, ::logMessage, _window,_dsi)
{
}
diff --git a/src/GUIWindow.h b/src/GUIWindow.h
index 36464b6..30ee8cf 100644
--- a/src/GUIWindow.h
+++ b/src/GUIWindow.h
@@ -147,7 +147,7 @@ class IndexingWorker : public QObject {
Q_OBJECT
public:
- IndexingWorker(const QString &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, GUIWindow *_window);
+ IndexingWorker(const QString &_d2v_file_name, FILE *_d2v_file, const AudioFilesMap &_audio_files, FakeFile *_fake_file, FFMPEG *_f, AVStream *_video_stream, int64_t _first_video_keyframe_pos, D2V::ColourRange _input_range, bool _use_relative_paths, GUIWindow *_window, int _dsi);
public slots:
void process();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment