Commit 984b169e authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Remove debug code and associated arguments from ffmpeg code (#2168)

Summary:
Part of https://github.com/pytorch/audio/issues/2164.
Removes debug code and associated arguments/fields left in previous PRs.

Pull Request resolved: https://github.com/pytorch/audio/pull/2168

Reviewed By: hwangjeff

Differential Revision: D33712999

Pulled By: mthrok

fbshipit-source-id: 0729e9fbc146c48887379b6231e4d6e8cb520c44
parent db10bdfb
......@@ -216,8 +216,7 @@ void add_basic_audio_stream(
const c10::optional<int64_t>& sample_rate,
const c10::optional<c10::ScalarType>& dtype) {
std::string filter_desc = get_afilter_desc(sample_rate, dtype);
s->s.add_audio_stream(
i, frames_per_chunk, num_chunks, sample_rate.value_or(-1), filter_desc);
s->s.add_audio_stream(i, frames_per_chunk, num_chunks, filter_desc);
}
void add_basic_video_stream(
......@@ -230,8 +229,7 @@ void add_basic_video_stream(
const c10::optional<int64_t>& height,
const c10::optional<std::string>& format) {
std::string filter_desc = get_vfilter_desc(frame_rate, width, height, format);
s->s.add_video_stream(
i, frames_per_chunk, num_chunks, frame_rate.value_or(-1), filter_desc);
s->s.add_video_stream(i, frames_per_chunk, num_chunks, filter_desc);
}
void add_audio_stream(
......@@ -239,14 +237,9 @@ void add_audio_stream(
int64_t i,
int64_t frames_per_chunk,
int64_t num_chunks,
const c10::optional<double>& sample_rate,
const c10::optional<std::string>& filter_desc) {
s->s.add_audio_stream(
i,
frames_per_chunk,
num_chunks,
sample_rate.value_or(-1),
filter_desc.value_or(""));
i, frames_per_chunk, num_chunks, filter_desc.value_or(""));
}
void add_video_stream(
......@@ -254,14 +247,9 @@ void add_video_stream(
int64_t i,
int64_t frames_per_chunk,
int64_t num_chunks,
const c10::optional<double>& frame_rate,
const c10::optional<std::string>& filter_desc) {
s->s.add_video_stream(
i,
frames_per_chunk,
num_chunks,
frame_rate.value_or(-1),
filter_desc.value_or(""));
i, frames_per_chunk, num_chunks, filter_desc.value_or(""));
}
void remove_stream(S s, int64_t i) {
......@@ -289,7 +277,7 @@ std::tuple<c10::optional<torch::Tensor>, int64_t> load(const std::string& src) {
int i = s.find_best_audio_stream();
auto sinfo = s.get_src_stream_info(i);
int64_t sample_rate = static_cast<int64_t>(sinfo.sample_rate);
s.add_audio_stream(i, -1, -1, 1, "");
s.add_audio_stream(i, -1, -1, "");
s.process_all_packets();
auto tensors = s.pop_chunks();
return std::make_tuple<>(tensors[0], sample_rate);
......
......@@ -29,11 +29,9 @@ Sink::Sink(
AVCodecParameters* codecpar,
int frames_per_chunk,
int num_chunks,
double output_time_base,
std::string filter_description)
: filter(input_time_base, codecpar, filter_description),
buffer(get_buffer(codecpar->codec_type, frames_per_chunk, num_chunks)),
time_base(output_time_base) {}
buffer(get_buffer(codecpar->codec_type, frames_per_chunk, num_chunks)) {}
// 0: some kind of success
// <0: Some error happened
......
......@@ -13,13 +13,11 @@ class Sink {
public:
FilterGraph filter;
std::unique_ptr<Buffer> buffer;
double time_base;
Sink(
AVRational input_time_base,
AVCodecParameters* codecpar,
int frames_per_chunk,
int num_chunks,
double output_time_base,
std::string filter_description);
int process_frame(AVFrame* frame);
......
......@@ -7,7 +7,7 @@ namespace ffmpeg {
using KeyType = StreamProcessor::KeyType;
StreamProcessor::StreamProcessor(AVCodecParameters* codecpar)
: media_type(codecpar->codec_type), decoder(codecpar) {}
: decoder(codecpar) {}
////////////////////////////////////////////////////////////////////////////////
// Configurations
......@@ -17,7 +17,6 @@ KeyType StreamProcessor::add_stream(
AVCodecParameters* codecpar,
int frames_per_chunk,
int num_chunks,
double output_rate,
std::string filter_description) {
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
......@@ -35,7 +34,6 @@ KeyType StreamProcessor::add_stream(
codecpar,
frames_per_chunk,
num_chunks,
(output_rate > 0) ? 1 / output_rate : av_q2d(input_time_base),
std::move(filter_description)));
decoder_time_base = av_q2d(input_time_base);
return key;
......@@ -64,28 +62,6 @@ bool StreamProcessor::is_buffer_ready() const {
////////////////////////////////////////////////////////////////////////////////
// The streaming process
////////////////////////////////////////////////////////////////////////////////
namespace {
void debug_print_frame(AVFrame* pFrame, double time_rate) {
if (pFrame->sample_rate)
std::cerr << " ---- format: "
<< av_get_sample_fmt_name(
static_cast<AVSampleFormat>(pFrame->format))
<< ", num_frames: " << pFrame->nb_samples
<< ", num_channels: " << pFrame->channels
<< ", num_samples: " << pFrame->nb_samples * pFrame->channels
<< ", sample_rate: " << pFrame->sample_rate
<< ", pts: " << pFrame->pts << ", pts/sample_rate: "
<< pFrame->pts / (double)pFrame->sample_rate
<< ", time: " << pFrame->pts * time_rate << std::endl;
else
std::cerr << " -------- format: "
<< av_get_pix_fmt_name(static_cast<AVPixelFormat>(pFrame->format))
<< ", width: " << pFrame->width << ", height: " << pFrame->height
<< ", pts: " << pFrame->pts
<< ", time: " << pFrame->pts * time_rate << std::endl;
}
} // namespace
// 0: some kind of success
// <0: Some error happened
int StreamProcessor::process_packet(AVPacket* packet) {
......
......@@ -14,7 +14,6 @@ class StreamProcessor {
using KeyType = int;
private:
AVMediaType media_type = AVMEDIA_TYPE_UNKNOWN;
AVFramePtr pFrame1;
AVFramePtr pFrame2;
......@@ -49,7 +48,6 @@ class StreamProcessor {
AVCodecParameters* codecpar,
int frames_per_chunk,
int num_chunks,
double output_rate,
std::string filter_description);
// 1. Remove the stream
......
......@@ -152,14 +152,12 @@ void Streamer::add_audio_stream(
int i,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc) {
add_stream(
i,
AVMEDIA_TYPE_AUDIO,
frames_per_chunk,
num_chunks,
rate,
std::move(filter_desc));
}
......@@ -167,14 +165,12 @@ void Streamer::add_video_stream(
int i,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc) {
add_stream(
i,
AVMEDIA_TYPE_VIDEO,
frames_per_chunk,
num_chunks,
rate,
std::move(filter_desc));
}
......@@ -183,7 +179,6 @@ void Streamer::add_stream(
AVMediaType media_type,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc) {
validate_src_stream_type(i, media_type);
AVStream* stream = pFormatContext->streams[i];
......@@ -195,7 +190,6 @@ void Streamer::add_stream(
stream->codecpar,
frames_per_chunk,
num_chunks,
rate,
std::move(filter_desc));
stream_indices.push_back(std::make_pair<>(i, key));
}
......
......@@ -66,13 +66,11 @@ class Streamer {
int i,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc);
void add_video_stream(
int i,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc);
void remove_stream(int i);
......@@ -82,7 +80,6 @@ class Streamer {
AVMediaType media_type,
int frames_per_chunk,
int num_chunks,
double rate,
std::string filter_desc);
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment