1 // Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // ============================================================================= 15 16 #ifndef TENSORFLOW_CONTRIB_FFMPEG_FFMPEG_LIB_H_ 17 #define TENSORFLOW_CONTRIB_FFMPEG_FFMPEG_LIB_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/core/lib/core/status.h" 23 24 namespace tensorflow { 25 namespace ffmpeg { 26 27 // Cleans up a file on destruction. 28 class FileDeleter { 29 public: 30 explicit FileDeleter(const string& filename) : filename_(filename) {} 31 ~FileDeleter(); 32 33 private: 34 const string filename_; 35 }; 36 37 // Writes binary data to a file. 38 Status WriteFile(const string& filename, tensorflow::StringPiece contents); 39 40 // Reads an audio file using ffmpeg and converts it into an array of samples in 41 // [-1.0, 1.0]. If there are multiple channels in the audio then each frame will 42 // contain a separate sample for each channel. Frames are ordered by time. 43 Status ReadAudioFile(const string& filename, const string& audio_format_id, 44 int32 samples_per_second, int32 channel_count, 45 const string& stream, std::vector<float>* output_samples); 46 47 // Creates an audio file using ffmpeg in a specific format. The samples are in 48 // [-1.0, 1.0]. If there are multiple channels in the audio then each frame will 49 // contain a separate sample for each channel. Frames are ordered by time. 50 // Currently, the implementation only supports wav files, and ffmpeg is not used 51 // to create them. 52 Status CreateAudioFile(const string& audio_format_id, int32 bits_per_second, 53 int32 samples_per_second, int32 channel_count, 54 const std::vector<float>& samples, string* output_data); 55 56 // Reads an video file using ffmpeg adn converts it into a RGB24 in uint8 57 // [frames, height, width, 3]. The w, h, and frames are obtained from ffmpeg. 58 Status ReadVideoFile(const string& filename, std::vector<uint8>* output_data, 59 uint32* width, uint32* height, uint32* frames); 60 61 } // namespace ffmpeg 62 } // namespace tensorflow 63 64 #endif // TENSORFLOW_CONTRIB_FFMPEG_DEFAULT_FFMPEG_LIB_H_ 65