Skip to content

Commit

Permalink
rate control tweaks. add tools for generating and comparing videos
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Dec 6, 2023
1 parent de2d345 commit 3e64156
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion builders/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get -y update \
libglx-mesa0 libglvnd-dev libxkbcommon-dev libxkbcommon-x11-0 libpulse-dev libxcb1 libx11-xcb1 libxcb-glx0 libxcb-cursor0 \
libxcb-icccm4 libxcb-image0 libxcb-render-util0 libxcb-keysyms1 libicu70 \
python3 python3-pip \
curl xz-utils xvfb pkg-config \
curl xz-utils xvfb pkg-config ffmpeg \
fontconfig fonts-liberation

ARG QT_VER=6.6.0
Expand Down
2 changes: 1 addition & 1 deletion src/mediafx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main(int argc, char* argv[])
command = parser.value(qSL("command"));
if (command == "ffplay") {
// XXX need to handle audio eventually
command = qSL("ffplay -autoexit -f rawvideo -video_size ${MEDIAFX_FRAMESIZE} -pixel_format rgb0 -framerate ${MEDIAFX_FRAMERATE} -i pipe:${MEDIAFX_VIDEOFD}");
command = qSL("ffplay -autoexit -infbuf -f rawvideo -video_size ${MEDIAFX_FRAMESIZE} -pixel_format rgb0 -framerate ${MEDIAFX_FRAMERATE} -i pipe:${MEDIAFX_VIDEOFD}");
} else if (command == "ffmpeg") {
if (!parser.isSet(qSL("output"))) {
parser.showHelp(1);
Expand Down
6 changes: 3 additions & 3 deletions src/mediafx/rate_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void RateControl::onVideoFrameRequired()
void RateControl::enqueue(const QVideoFrame& videoFrame)
{
if (videoFrame.startTime() != -1 && videoFrame.endTime() != -1) {
microseconds sourceFrameDuration(videoFrame.endTime() - videoFrame.startTime());
rateScalar = targetFrameDuration / duration<double, microseconds::period>(sourceFrameDuration);
sourceFrameDuration = sourceFrameDuration;
microseconds frameDuration(videoFrame.endTime() - videoFrame.startTime());
rateScalar = targetFrameDuration / duration<double, microseconds::period>(frameDuration);
sourceFrameDuration = frameDuration;
}
bufferedFrames.enqueue(videoFrame);
}
Expand Down
2 changes: 2 additions & 0 deletions src/mediafx/video_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QDebug>
#include <QMediaPlayer>
#include <QMessageLogContext>
#include <QMetaObject>
#include <QMutexLocker>
#include <QUrl>
#include <QVideoSink>
Expand Down Expand Up @@ -68,6 +69,7 @@ void VideoClip::onVideoFrameChanged(const QVideoFrame& frame)
}
if (microseconds(frame.startTime()) >= frameTimeStart) {
rateControl.enqueue(frame);
QMetaObject::invokeMethod(this, &VideoClip::onRateControl, Qt::QueuedConnection);
}
}

Expand Down
Binary file added tools/JetBrainsMono-Regular.ttf
Binary file not shown.
19 changes: 19 additions & 0 deletions tools/create-video.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Copyright (C) 2023 Andrew Wason
#
# This file is part of mediaFX.
#
# mediaFX is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# mediaFX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with mediaFX.
# If not, see <https://www.gnu.org/licenses/>.

ROOT=$(dirname "${BASH_SOURCE[0]}")

ffmpeg -f lavfi -i testsrc=duration=${DURATION:-12}:size=${SIZE:-640x360}:rate=${FRAMERATE:-30}:decimals=2,drawbox=color=${COLOR:-red}:t=ih/16,drawtext=text=f%{frame_num}:x=w/10:y=x/dar:shadowx=3:shadowy=3:fontsize=h/3.75:[email protected]:fontfile=${ROOT}/JetBrainsMono-Regular.ttf -f nut -vcodec ffv1 -g 1 -level 3 -pix_fmt rgb32 -framerate ${FRAMERATE:-30} -y ${1:?specify output nut filename}
3 changes: 0 additions & 3 deletions tools/create_mov.sh

This file was deleted.

19 changes: 19 additions & 0 deletions tools/diff-video.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Copyright (C) 2023 Andrew Wason
#
# This file is part of mediaFX.
#
# mediaFX is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# mediaFX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with mediaFX.
# If not, see <https://www.gnu.org/licenses/>.
usage="$0 <original-video> <new-video>"

# https://superuser.com/questions/854543/how-to-compare-the-difference-between-2-videos-color-in-ffmpeg
ffplay -autoexit -f lavfi "movie='${1:?$usage}',split[org1][org2]; movie='${2:?$usage}',split[new1][new2]; [org1][new1]blend=all_mode=grainextract[blend];[org2][new2][blend]vstack=inputs=3"
17 changes: 17 additions & 0 deletions tools/framehash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Copyright (C) 2023 Andrew Wason
#
# This file is part of mediaFX.
#
# mediaFX is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# mediaFX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with mediaFX.
# If not, see <https://www.gnu.org/licenses/>.

ffmpeg -loglevel error -i ${1:?specify input video} -f framehash -hash md5 -fflags bitexact -
17 changes: 17 additions & 0 deletions tools/hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Copyright (C) 2023 Andrew Wason
#
# This file is part of mediaFX.
#
# mediaFX is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# mediaFX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with mediaFX.
# If not, see <https://www.gnu.org/licenses/>.

ffmpeg -loglevel error -i ${1:?video file required} -f hash -hash md5 -

0 comments on commit 3e64156

Please sign in to comment.