Skip to content

Commit

Permalink
FFmpeg: Combine 2 constructors via a default arg, fix docs, const refs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Jun 8, 2020
1 parent 7a91ca1 commit c57f8ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
15 changes: 7 additions & 8 deletions include/FFmpegReader.h
Expand Up @@ -233,14 +233,13 @@ namespace openshot {
/// codecs have trouble seeking, and can introduce artifacts or blank images into the video.
bool enable_seek;

/// Constructor for FFmpegReader. This automatically opens the media file and loads
/// frame 1, or it throws one of the following exceptions.
FFmpegReader(std::string path);

/// Constructor for FFmpegReader. This only opens the media file to inspect its properties
/// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful
/// when you are inflating the object using JSON after instantiating it.
FFmpegReader(std::string path, bool inspect_reader);
/// @brief Constructor for FFmpegReader.
///
/// Sets (and possibly opens) the media file path,
/// or throws an exception.
/// @param path The filesystem location to load
/// @param inspect_reader if true (the default), automatically open the media file and loads frame 1.
FFmpegReader(const std::string& path, bool inspect_reader=true);

/// Destructor
virtual ~FFmpegReader();
Expand Down
6 changes: 4 additions & 2 deletions include/FFmpegWriter.h
Expand Up @@ -251,9 +251,11 @@ namespace openshot {

public:

/// @brief Constructor for FFmpegWriter. Throws one of the following exceptions.
/// @brief Constructor for FFmpegWriter.
/// Throws an exception on failure to open path.
///
/// @param path The file path of the video file you want to open and read
FFmpegWriter(std::string path);
FFmpegWriter(const std::string& path);

/// Close the writer
void Close();
Expand Down
23 changes: 1 addition & 22 deletions src/FFmpegReader.cpp
Expand Up @@ -83,35 +83,14 @@ int hw_de_on = 0;
AVHWDeviceType hw_de_av_device_type_global = AV_HWDEVICE_TYPE_NONE;
#endif

FFmpegReader::FFmpegReader(std::string path)
FFmpegReader::FFmpegReader(const std::string& path, bool inspect_reader)
: last_frame(0), is_seeking(0), seeking_pts(0), seeking_frame(0), seek_count(0),
audio_pts_offset(99999), video_pts_offset(99999), path(path), is_video_seek(true), check_interlace(false),
check_fps(false), enable_seek(true), is_open(false), seek_audio_frame_found(0), seek_video_frame_found(0),
prev_samples(0), prev_pts(0), pts_total(0), pts_counter(0), is_duration_known(false), largest_frame_processed(0),
current_video_frame(0), has_missing_frames(false), num_packets_since_video_frame(0), num_checks_since_final(0),
packet(NULL) {

// Initialize FFMpeg, and register all formats and codecs
AV_REGISTER_ALL
AVCODEC_REGISTER_ALL

// Init cache
working_cache.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * info.fps.ToDouble() * 2, info.width, info.height, info.sample_rate, info.channels);
missing_frames.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * 2, info.width, info.height, info.sample_rate, info.channels);
final_cache.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * 2, info.width, info.height, info.sample_rate, info.channels);

// Open and Close the reader, to populate its attributes (such as height, width, etc...)
Open();
Close();
}

FFmpegReader::FFmpegReader(std::string path, bool inspect_reader)
: last_frame(0), is_seeking(0), seeking_pts(0), seeking_frame(0), seek_count(0),
audio_pts_offset(99999), video_pts_offset(99999), path(path), is_video_seek(true), check_interlace(false),
check_fps(false), enable_seek(true), is_open(false), seek_audio_frame_found(0), seek_video_frame_found(0),
prev_samples(0), prev_pts(0), pts_total(0), pts_counter(0), is_duration_known(false), largest_frame_processed(0),
current_video_frame(0), has_missing_frames(false), num_packets_since_video_frame(0), num_checks_since_final(0),
packet(NULL) {

// Initialize FFMpeg, and register all formats and codecs
AV_REGISTER_ALL
Expand Down
2 changes: 1 addition & 1 deletion src/FFmpegWriter.cpp
Expand Up @@ -83,7 +83,7 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx, int6
}
#endif // HAVE_HW_ACCEL

FFmpegWriter::FFmpegWriter(std::string path) :
FFmpegWriter::FFmpegWriter(const std::string& path) :
path(path), fmt(NULL), oc(NULL), audio_st(NULL), video_st(NULL), samples(NULL),
audio_outbuf(NULL), audio_outbuf_size(0), audio_input_frame_size(0), audio_input_position(0),
initial_audio_input_frame_size(0), img_convert_ctx(NULL), cache_size(8), num_of_rescalers(32),
Expand Down

0 comments on commit c57f8ed

Please sign in to comment.